Skip to content

Move assert inside branch for String.fromCodePoint #1847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions std/assembly/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ import { Array } from "./array";
}

static fromCodePoint(code: i32): String {
assert(<u32>code <= 0x10FFFF);
var hasSur = code > 0xFFFF;
var hasSur = <u32>code > 0xFFFF;
var out = changetype<String>(__new(2 << i32(hasSur), idof<String>()));
if (!hasSur) {
store<u16>(changetype<usize>(out), <u16>code);
} else {
// Checks valid code point range
assert(<u32>code <= 0x10FFFF);
code -= 0x10000;
let hi = (code & 0x03FF) | 0xDC00;
let lo = (code >>> 10) | 0xD800;
store<u32>(changetype<usize>(out), lo | (hi << 16));
let lo = code >>> 10 | 0xD800;
store<u32>(changetype<usize>(out), lo | hi << 16);
}
return out;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/std-wasi/process.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4792,7 +4792,7 @@
if
i32.const 0
i32.const 4816
i32.const 748
i32.const 749
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/std-wasi/process.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -7791,7 +7791,7 @@
if
i32.const 0
i32.const 3792
i32.const 748
i32.const 749
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand Down
24 changes: 12 additions & 12 deletions tests/compiler/std/string-casemapping.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -5967,22 +5967,11 @@
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
local.get $0
i32.const 1114111
i32.gt_u
if
i32.const 0
i32.const 15344
i32.const 33
i32.const 5
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 2
local.get $0
i32.const 65535
i32.gt_s
i32.gt_u
local.tee $2
i32.shl
i32.const 1
Expand All @@ -5991,6 +5980,17 @@
i32.store
local.get $2
if
local.get $0
i32.const 1114111
i32.gt_u
if
i32.const 0
i32.const 15344
i32.const 39
i32.const 7
call $~lib/builtins/abort
unreachable
end
local.get $1
local.get $0
i32.const 65536
Expand Down
26 changes: 13 additions & 13 deletions tests/compiler/std/string-casemapping.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8589,20 +8589,8 @@
i32.const 0
i32.store
local.get $0
i32.const 1114111
i32.le_u
i32.eqz
if
i32.const 0
i32.const 14576
i32.const 33
i32.const 5
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 65535
i32.gt_s
i32.gt_u
local.set $1
global.get $~lib/memory/__stack_pointer
i32.const 2
Expand All @@ -8619,6 +8607,18 @@
local.get $0
i32.store16
else
local.get $0
i32.const 1114111
i32.le_u
i32.eqz
if
i32.const 0
i32.const 14576
i32.const 39
i32.const 7
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 65536
i32.sub
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/std/string-encoding.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,7 @@
if
i32.const 0
i32.const 1712
i32.const 748
i32.const 749
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/std/string-encoding.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -5958,7 +5958,7 @@
if
i32.const 0
i32.const 688
i32.const 748
i32.const 749
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down
28 changes: 14 additions & 14 deletions tests/compiler/std/string.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,7 @@
if
i32.const 1264
i32.const 1328
i32.const 56
i32.const 57
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -20364,22 +20364,11 @@
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
local.get $0
i32.const 1114111
i32.gt_u
if
i32.const 0
i32.const 1328
i32.const 33
i32.const 5
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 2
local.get $0
i32.const 65535
i32.gt_s
i32.gt_u
local.tee $2
i32.shl
i32.const 1
Expand All @@ -20388,6 +20377,17 @@
i32.store
local.get $2
if
local.get $0
i32.const 1114111
i32.gt_u
if
i32.const 0
i32.const 1328
i32.const 39
i32.const 7
call $~lib/builtins/abort
unreachable
end
local.get $1
local.get $0
i32.const 65536
Expand Down Expand Up @@ -20988,7 +20988,7 @@
if
i32.const 13648
i32.const 1328
i32.const 332
i32.const 333
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down
30 changes: 15 additions & 15 deletions tests/compiler/std/string.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3089,7 +3089,7 @@
if
i32.const 240
i32.const 304
i32.const 56
i32.const 57
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -25393,20 +25393,8 @@
i32.const 0
i32.store
local.get $0
i32.const 1114111
i32.le_u
i32.eqz
if
i32.const 0
i32.const 304
i32.const 33
i32.const 5
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 65535
i32.gt_s
i32.gt_u
local.set $1
global.get $~lib/memory/__stack_pointer
i32.const 2
Expand All @@ -25423,6 +25411,18 @@
local.get $0
i32.store16
else
local.get $0
i32.const 1114111
i32.le_u
i32.eqz
if
i32.const 0
i32.const 304
i32.const 39
i32.const 7
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 65536
i32.sub
Expand Down Expand Up @@ -26084,7 +26084,7 @@
if
i32.const 12624
i32.const 304
i32.const 332
i32.const 333
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down