Returns true if this key type does not contain strings, interfaces etc., so can be compared with runtime.memequal. Note that padding bytes are undef and can alter two "equal" structs being equal when compared with memequal.
(keyType types.Type)
| 248 | // can be compared with runtime.memequal. Note that padding bytes are undef |
| 249 | // and can alter two "equal" structs being equal when compared with memequal. |
| 250 | func hashmapIsBinaryKey(keyType types.Type) bool { |
| 251 | switch keyType := keyType.Underlying().(type) { |
| 252 | case *types.Basic: |
| 253 | // TODO: unsafe.Pointer is also a binary key, but to support that we |
| 254 | // need to fix an issue with interp first (see |
| 255 | // https://github.com/tinygo-org/tinygo/pull/4898). |
| 256 | return keyType.Info()&(types.IsBoolean|types.IsInteger) != 0 |
| 257 | case *types.Pointer: |
| 258 | return true |
| 259 | case *types.Struct: |
| 260 | for i := 0; i < keyType.NumFields(); i++ { |
| 261 | fieldType := keyType.Field(i).Type().Underlying() |
| 262 | if !hashmapIsBinaryKey(fieldType) { |
| 263 | return false |
| 264 | } |
| 265 | } |
| 266 | return true |
| 267 | case *types.Array: |
| 268 | return hashmapIsBinaryKey(keyType.Elem()) |
| 269 | default: |
| 270 | return false |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | func (b *builder) zeroUndefBytes(llvmType llvm.Type, ptr llvm.Value) error { |
| 275 | // We know that hashmapIsBinaryKey is true, so we only have to handle those types that can show up there. |
no test coverage detected