Use a special 'auto' type in type inference

This commit is contained in:
dcode
2019-06-12 08:34:39 +02:00
parent 40dac8269d
commit acda2d05c8
11 changed files with 239 additions and 216 deletions

View File

@ -116,6 +116,12 @@
(func $assert-nonnull/testElem (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
call $~lib/array/Array<assert-nonnull/Foo | null>#__get
local.tee $0
i32.eqz
if
unreachable
end
local.get $0
)
(func $assert-nonnull/testAll (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0

View File

@ -179,7 +179,6 @@
)
(func $assert-nonnull/testElem (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
local.get $0
call $~lib/rt/stub/__retain
drop
@ -187,13 +186,16 @@
i32.const 0
call $~lib/array/Array<assert-nonnull/Foo | null>#__get
local.tee $1
if (result i32)
local.get $1
else
unreachable
end
call $~lib/rt/stub/__retain
local.set $2
local.get $1
call $~lib/rt/stub/__release
local.set $1
local.get $0
call $~lib/rt/stub/__release
local.get $2
local.get $1
)
(func $assert-nonnull/testAll (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)

View File

@ -6,6 +6,7 @@
(data (i32.const 8) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00r\00e\00t\00a\00i\00n\00-\00i\003\002\00.\00t\00s")
(global $retain-i32/si (mut i32) (i32.const 0))
(global $retain-i32/ui (mut i32) (i32.const 0))
(global $retain-i32/ri (mut i32) (i32.const 0))
(export "memory" (memory $0))
(start $start)
(func $start:retain-i32 (; 1 ;) (type $FUNCSIG$v)
@ -254,6 +255,12 @@
call $~lib/builtins/abort
unreachable
end
i32.const 0
i32.load8_s
global.set $retain-i32/ri
i32.const 0
i32.load8_s
drop
)
(func $start (; 2 ;) (type $FUNCSIG$v)
call $start:retain-i32

View File

@ -129,3 +129,14 @@ assert(ui == 1);
ui = 255 % 255;
assert(ui == 0);
// inferring global type from load should still retain T
var ri = load<i8>(0);
assert(ri instanceof i8);
// inferring local type from load should still retain T
function testLocalRetain(): void {
var ri = load<i8>(0);
assert(ri instanceof i8);
}
testLocalRetain();

View File

@ -18,6 +18,7 @@
(global $~lib/builtins/u32.MAX_VALUE i32 (i32.const -1))
(global $retain-i32/si (mut i32) (i32.const 0))
(global $retain-i32/ui (mut i32) (i32.const 0))
(global $retain-i32/ri (mut i32) (i32.const 0))
(export "memory" (memory $0))
(start $start)
(func $retain-i32/test (; 1 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
@ -330,7 +331,25 @@
unreachable
end
)
(func $start:retain-i32 (; 2 ;) (type $FUNCSIG$v)
(func $retain-i32/testLocalRetain (; 2 ;) (type $FUNCSIG$v)
(local $0 i32)
i32.const 0
i32.load8_s
local.set $0
local.get $0
drop
i32.const 1
i32.eqz
if
i32.const 0
i32.const 24
i32.const 140
i32.const 2
call $~lib/builtins/abort
unreachable
end
)
(func $start:retain-i32 (; 3 ;) (type $FUNCSIG$v)
(local $0 i32)
i32.const 0
global.get $~lib/builtins/i8.MAX_VALUE
@ -786,10 +805,26 @@
call $~lib/builtins/abort
unreachable
end
i32.const 0
i32.load8_s
global.set $retain-i32/ri
global.get $retain-i32/ri
drop
i32.const 1
i32.eqz
if
i32.const 0
i32.const 24
i32.const 135
i32.const 0
call $~lib/builtins/abort
unreachable
end
call $retain-i32/testLocalRetain
)
(func $start (; 3 ;) (type $FUNCSIG$v)
(func $start (; 4 ;) (type $FUNCSIG$v)
call $start:retain-i32
)
(func $null (; 4 ;) (type $FUNCSIG$v)
(func $null (; 5 ;) (type $FUNCSIG$v)
)
)

View File

@ -1475,6 +1475,7 @@
call $~lib/string/String.__concat
)
(func $start:std/symbol (; 27 ;) (type $FUNCSIG$v)
(local $0 i32)
i32.const 24
call $~lib/symbol/Symbol
global.set $std/symbol/sym1
@ -1537,9 +1538,21 @@
end
global.get $std/symbol/sym3
call $~lib/symbol/_Symbol.keyFor
local.tee $0
i32.eqz
if
unreachable
end
local.get $0
global.set $std/symbol/key3
global.get $std/symbol/sym4
call $~lib/symbol/_Symbol.keyFor
local.tee $0
i32.eqz
if
unreachable
end
local.get $0
global.set $std/symbol/key4
global.get $std/symbol/key3
i32.const 24

View File

@ -3342,8 +3342,6 @@
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
i32.const 24
call $~lib/symbol/Symbol
global.set $std/symbol/sym1
@ -3423,11 +3421,21 @@
global.get $std/symbol/sym3
call $~lib/symbol/_Symbol.keyFor
local.tee $0
if (result i32)
local.get $0
else
unreachable
end
call $~lib/rt/stub/__retain
global.set $std/symbol/key3
global.get $std/symbol/sym4
call $~lib/symbol/_Symbol.keyFor
local.tee $1
local.tee $0
if (result i32)
local.get $0
else
unreachable
end
call $~lib/rt/stub/__retain
global.set $std/symbol/key4
global.get $std/symbol/key3
@ -3457,7 +3465,7 @@
i32.const 0
call $~lib/symbol/Symbol
call $~lib/symbol/_Symbol#toString
local.tee $2
local.tee $0
i32.const 704
call $~lib/string/String.__eq
i32.eqz
@ -3471,7 +3479,7 @@
end
global.get $std/symbol/sym3
call $~lib/symbol/_Symbol#toString
local.tee $3
local.tee $1
i32.const 736
call $~lib/string/String.__eq
i32.eqz
@ -3489,7 +3497,7 @@
global.set $std/symbol/isConcatSpreadable
global.get $std/symbol/hasInstance
call $~lib/symbol/_Symbol#toString
local.tee $4
local.tee $2
i32.const 776
call $~lib/string/String.__eq
i32.eqz
@ -3503,7 +3511,7 @@
end
global.get $std/symbol/isConcatSpreadable
call $~lib/symbol/_Symbol#toString
local.tee $5
local.tee $3
i32.const 832
call $~lib/string/String.__eq
i32.eqz
@ -3527,10 +3535,6 @@
call $~lib/rt/stub/__release
local.get $3
call $~lib/rt/stub/__release
local.get $4
call $~lib/rt/stub/__release
local.get $5
call $~lib/rt/stub/__release
)
(func $start (; 34 ;) (type $FUNCSIG$v)
call $start:std/symbol