aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2023-03-18 09:42:16 -0700
committerRon Evans <[email protected]>2023-03-25 22:32:29 +0100
commit21527353f7c4e096d0646fff68e0aae5e2540559 (patch)
tree758be2df74edce44b120b6cb2132433000cd24a9 /compiler
parentbedd27b20e84d3db0941f829125d210c16e7fefc (diff)
downloadtinygo-21527353f7c4e096d0646fff68e0aae5e2540559.tar.gz
tinygo-21527353f7c4e096d0646fff68e0aae5e2540559.zip
compiler: for interface maps, use the original named type if available
Diffstat (limited to 'compiler')
-rw-r--r--compiler/map.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/map.go b/compiler/map.go
index 9c9a3b5c6..c3d428902 100644
--- a/compiler/map.go
+++ b/compiler/map.go
@@ -78,6 +78,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val
// Do the lookup. How it is done depends on the key type.
var commaOkValue llvm.Value
+ origKeyType := keyType
keyType = keyType.Underlying()
if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 {
// key is a string
@@ -99,7 +100,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val
itfKey := key
if _, ok := keyType.(*types.Interface); !ok {
// Not already an interface, so convert it to an interface now.
- itfKey = b.createMakeInterface(key, keyType, pos)
+ itfKey = b.createMakeInterface(key, origKeyType, pos)
}
params := []llvm.Value{m, itfKey, mapValuePtr, mapValueSize}
commaOkValue = b.createRuntimeCall("hashmapInterfaceGet", params, "")
@@ -125,6 +126,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val
func (b *builder) createMapUpdate(keyType types.Type, m, key, value llvm.Value, pos token.Pos) {
valueAlloca, valuePtr, valueSize := b.createTemporaryAlloca(value.Type(), "hashmap.value")
b.CreateStore(value, valueAlloca)
+ origKeyType := keyType
keyType = keyType.Underlying()
if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 {
// key is a string
@@ -143,7 +145,7 @@ func (b *builder) createMapUpdate(keyType types.Type, m, key, value llvm.Value,
itfKey := key
if _, ok := keyType.(*types.Interface); !ok {
// Not already an interface, so convert it to an interface first.
- itfKey = b.createMakeInterface(key, keyType, pos)
+ itfKey = b.createMakeInterface(key, origKeyType, pos)
}
params := []llvm.Value{m, itfKey, valuePtr}
b.createRuntimeCall("hashmapInterfaceSet", params, "")
@@ -154,6 +156,7 @@ func (b *builder) createMapUpdate(keyType types.Type, m, key, value llvm.Value,
// createMapDelete deletes a key from a map by calling the appropriate runtime
// function. It is the implementation of the Go delete() builtin.
func (b *builder) createMapDelete(keyType types.Type, m, key llvm.Value, pos token.Pos) error {
+ origKeyType := keyType
keyType = keyType.Underlying()
if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 {
// key is a string
@@ -174,7 +177,7 @@ func (b *builder) createMapDelete(keyType types.Type, m, key llvm.Value, pos tok
itfKey := key
if _, ok := keyType.(*types.Interface); !ok {
// Not already an interface, so convert it to an interface first.
- itfKey = b.createMakeInterface(key, keyType, pos)
+ itfKey = b.createMakeInterface(key, origKeyType, pos)
}
params := []llvm.Value{m, itfKey}
b.createRuntimeCall("hashmapInterfaceDelete", params, "")