From c7287751c9bb664e9287db1707aa3e9ce01669e0 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 6 May 2021 11:28:31 +0300 Subject: [PATCH 1/6] move assert inside second arm for fromCodePoint --- std/assembly/string.ts | 2 +- .../std/string-casemapping.optimized.wat | 22 ++++++++--------- .../std/string-casemapping.untouched.wat | 24 +++++++++---------- tests/compiler/std/string.optimized.wat | 22 ++++++++--------- tests/compiler/std/string.untouched.wat | 24 +++++++++---------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 3624f63d3e..e8c143b5ff 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -30,12 +30,12 @@ import { Array } from "./array"; } static fromCodePoint(code: i32): String { - assert(code <= 0x10FFFF); var hasSur = code > 0xFFFF; var out = changetype(__new(2 << i32(hasSur), idof())); if (!hasSur) { store(changetype(out), code); } else { + assert(code <= 0x10FFFF); code -= 0x10000; let hi = (code & 0x03FF) | 0xDC00; let lo = (code >>> 10) | 0xD800; diff --git a/tests/compiler/std/string-casemapping.optimized.wat b/tests/compiler/std/string-casemapping.optimized.wat index 607b5b49c5..45eedf69d3 100644 --- a/tests/compiler/std/string-casemapping.optimized.wat +++ b/tests/compiler/std/string-casemapping.optimized.wat @@ -5967,17 +5967,6 @@ 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 @@ -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 38 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $1 local.get $0 i32.const 65536 diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index 58d43bed23..c0c5957a8f 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -8589,18 +8589,6 @@ 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 local.set $1 @@ -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 38 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $0 i32.const 65536 i32.sub diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index a4342fca7c..012dba6b1d 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -20364,17 +20364,6 @@ 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 @@ -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 38 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $1 local.get $0 i32.const 65536 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 2b5ed767dd..025c9fb0fb 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -25393,18 +25393,6 @@ 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 local.set $1 @@ -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 38 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $0 i32.const 65536 i32.sub From ef9af6db9ad221ff905afcc59604fabaeb6073f9 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 6 May 2021 11:32:35 +0300 Subject: [PATCH 2/6] fix --- std/assembly/string.ts | 2 +- tests/compiler/std/string-casemapping.optimized.wat | 2 +- tests/compiler/std/string-casemapping.untouched.wat | 2 +- tests/compiler/std/string.optimized.wat | 2 +- tests/compiler/std/string.untouched.wat | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index e8c143b5ff..1b556c1677 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -30,7 +30,7 @@ import { Array } from "./array"; } static fromCodePoint(code: i32): String { - var hasSur = code > 0xFFFF; + var hasSur = code > 0xFFFF; var out = changetype(__new(2 << i32(hasSur), idof())); if (!hasSur) { store(changetype(out), code); diff --git a/tests/compiler/std/string-casemapping.optimized.wat b/tests/compiler/std/string-casemapping.optimized.wat index 45eedf69d3..f1d9702318 100644 --- a/tests/compiler/std/string-casemapping.optimized.wat +++ b/tests/compiler/std/string-casemapping.optimized.wat @@ -5971,7 +5971,7 @@ i32.const 2 local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.tee $2 i32.shl i32.const 1 diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index c0c5957a8f..f80bfc0c44 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -8590,7 +8590,7 @@ i32.store local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.set $1 global.get $~lib/memory/__stack_pointer i32.const 2 diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 012dba6b1d..b180ff7f6a 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -20368,7 +20368,7 @@ i32.const 2 local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.tee $2 i32.shl i32.const 1 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 025c9fb0fb..a9e18a78db 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -25394,7 +25394,7 @@ i32.store local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.set $1 global.get $~lib/memory/__stack_pointer i32.const 2 From 8fa96f7176800d64b63ff42f8bff7c6664ac7fb8 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 6 May 2021 13:19:28 +0300 Subject: [PATCH 3/6] remove unnecessary parenthesis --- std/assembly/string.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 1b556c1677..ef0cde7513 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -38,8 +38,8 @@ import { Array } from "./array"; assert(code <= 0x10FFFF); code -= 0x10000; let hi = (code & 0x03FF) | 0xDC00; - let lo = (code >>> 10) | 0xD800; - store(changetype(out), lo | (hi << 16)); + let lo = code >>> 10 | 0xD800; + store(changetype(out), lo | hi << 16); } return out; } From b9c4900e875f1f98c4ffd87796371b955c6aa48e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 12 May 2021 12:23:09 +0300 Subject: [PATCH 4/6] add comment --- std/assembly/string.ts | 1 + tests/compiler/std/string-casemapping.optimized.wat | 2 +- tests/compiler/std/string-casemapping.untouched.wat | 2 +- tests/compiler/std/string.optimized.wat | 6 +++--- tests/compiler/std/string.untouched.wat | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index ef0cde7513..77585d9b77 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -35,6 +35,7 @@ import { Array } from "./array"; if (!hasSur) { store(changetype(out), code); } else { + // Checks valid code point range assert(code <= 0x10FFFF); code -= 0x10000; let hi = (code & 0x03FF) | 0xDC00; diff --git a/tests/compiler/std/string-casemapping.optimized.wat b/tests/compiler/std/string-casemapping.optimized.wat index f1d9702318..8aa51a1d63 100644 --- a/tests/compiler/std/string-casemapping.optimized.wat +++ b/tests/compiler/std/string-casemapping.optimized.wat @@ -5986,7 +5986,7 @@ if i32.const 0 i32.const 15344 - i32.const 38 + i32.const 39 i32.const 7 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index f80bfc0c44..cfb7e7640d 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -8614,7 +8614,7 @@ if i32.const 0 i32.const 14576 - i32.const 38 + i32.const 39 i32.const 7 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index b180ff7f6a..22257a02ee 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -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 @@ -20383,7 +20383,7 @@ if i32.const 0 i32.const 1328 - i32.const 38 + i32.const 39 i32.const 7 call $~lib/builtins/abort unreachable @@ -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 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index a9e18a78db..5d8b16e859 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -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 @@ -25418,7 +25418,7 @@ if i32.const 0 i32.const 304 - i32.const 38 + i32.const 39 i32.const 7 call $~lib/builtins/abort unreachable @@ -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 From 29a66e079c342d84a4d20f873a3730989f1cf6ef Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 12 May 2021 12:27:30 +0300 Subject: [PATCH 5/6] upd fixtures --- tests/compiler/std-wasi/process.optimized.wat | 2 +- tests/compiler/std-wasi/process.untouched.wat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compiler/std-wasi/process.optimized.wat b/tests/compiler/std-wasi/process.optimized.wat index 97ea52e086..a2f6527925 100644 --- a/tests/compiler/std-wasi/process.optimized.wat +++ b/tests/compiler/std-wasi/process.optimized.wat @@ -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 diff --git a/tests/compiler/std-wasi/process.untouched.wat b/tests/compiler/std-wasi/process.untouched.wat index 061e79a721..decdaf0529 100644 --- a/tests/compiler/std-wasi/process.untouched.wat +++ b/tests/compiler/std-wasi/process.untouched.wat @@ -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 From 45ef79792992d2067dd57ef604ce033770a92de5 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 12 May 2021 12:43:13 +0300 Subject: [PATCH 6/6] more --- tests/compiler/std/string-encoding.optimized.wat | 2 +- tests/compiler/std/string-encoding.untouched.wat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index bc55b7e596..7c76a4beb0 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -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 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 947c9da3aa..65f2c9be39 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -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