Skip to content

Commit 17823cd

Browse files
authored
[Strings] Fix precomputing of StringEq (WebAssembly#6401)
We incorrectly overrode the string operations in the interpreter's subclasses. But string operations can be implemented in the topmost class there (as they depend on no module state), so just implement them there, once, in a proper way. This fixes StringEq by removing its override, and moves the others to the right place.
1 parent e62653d commit 17823cd

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

src/wasm-interpreter.h

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
19041904
}
19051905
Flow visitStringMeasure(StringMeasure* curr) {
19061906
// For now we only support JS-style strings.
1907-
assert(curr->op == StringMeasureWTF16View);
1907+
if (curr->op != StringMeasureWTF16View) {
1908+
return Flow(NONCONSTANT_FLOW);
1909+
}
19081910

19091911
Flow flow = visit(curr->ref);
19101912
if (flow.breaking()) {
@@ -1917,8 +1919,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
19171919
}
19181920
return Literal(int32_t(data->values.size()));
19191921
}
1920-
Flow visitStringEncode(StringEncode* curr) { WASM_UNREACHABLE("unimp"); }
1921-
Flow visitStringConcat(StringConcat* curr) { WASM_UNREACHABLE("unimp"); }
1922+
Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
1923+
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
19221924
Flow visitStringEq(StringEq* curr) {
19231925
NOTE_ENTER("StringEq");
19241926
Flow flow = visit(curr->left);
@@ -1987,7 +1989,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
19871989
}
19881990
Flow visitStringAs(StringAs* curr) {
19891991
// For now we only support JS-style strings.
1990-
assert(curr->op == StringAsWTF16);
1992+
if (curr->op != StringAsWTF16) {
1993+
return Flow(NONCONSTANT_FLOW);
1994+
}
19911995

19921996
Flow flow = visit(curr->ref);
19931997
if (flow.breaking()) {
@@ -2004,10 +2008,10 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
20042008
return Literal(data, curr->type.getHeapType());
20052009
}
20062010
Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
2007-
WASM_UNREACHABLE("unimp");
2011+
return Flow(NONCONSTANT_FLOW);
20082012
}
20092013
Flow visitStringWTF16Get(StringWTF16Get* curr) {
2010-
NOTE_ENTER("StringEq");
2014+
NOTE_ENTER("StringWTF16Get");
20112015
Flow ref = visit(curr->ref);
20122016
if (ref.breaking()) {
20132017
return ref;
@@ -2028,11 +2032,17 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
20282032
}
20292033
return Literal(values[i].geti32());
20302034
}
2031-
Flow visitStringIterNext(StringIterNext* curr) { WASM_UNREACHABLE("unimp"); }
2032-
Flow visitStringIterMove(StringIterMove* curr) { WASM_UNREACHABLE("unimp"); }
2033-
Flow visitStringSliceWTF(StringSliceWTF* curr) { WASM_UNREACHABLE("unimp"); }
2035+
Flow visitStringIterNext(StringIterNext* curr) {
2036+
return Flow(NONCONSTANT_FLOW);
2037+
}
2038+
Flow visitStringIterMove(StringIterMove* curr) {
2039+
return Flow(NONCONSTANT_FLOW);
2040+
}
2041+
Flow visitStringSliceWTF(StringSliceWTF* curr) {
2042+
return Flow(NONCONSTANT_FLOW);
2043+
}
20342044
Flow visitStringSliceIter(StringSliceIter* curr) {
2035-
WASM_UNREACHABLE("unimp");
2045+
return Flow(NONCONSTANT_FLOW);
20362046
}
20372047

20382048
virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
@@ -2369,31 +2379,6 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
23692379
NOTE_ENTER("Rethrow");
23702380
return Flow(NONCONSTANT_FLOW);
23712381
}
2372-
Flow visitStringMeasure(StringMeasure* curr) {
2373-
return Flow(NONCONSTANT_FLOW);
2374-
}
2375-
Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
2376-
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
2377-
Flow visitStringEq(StringEq* curr) { return Flow(NONCONSTANT_FLOW); }
2378-
Flow visitStringAs(StringAs* curr) { return Flow(NONCONSTANT_FLOW); }
2379-
Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
2380-
return Flow(NONCONSTANT_FLOW);
2381-
}
2382-
Flow visitStringWTF16Get(StringWTF16Get* curr) {
2383-
return Flow(NONCONSTANT_FLOW);
2384-
}
2385-
Flow visitStringIterNext(StringIterNext* curr) {
2386-
return Flow(NONCONSTANT_FLOW);
2387-
}
2388-
Flow visitStringIterMove(StringIterMove* curr) {
2389-
return Flow(NONCONSTANT_FLOW);
2390-
}
2391-
Flow visitStringSliceWTF(StringSliceWTF* curr) {
2392-
return Flow(NONCONSTANT_FLOW);
2393-
}
2394-
Flow visitStringSliceIter(StringSliceIter* curr) {
2395-
return Flow(NONCONSTANT_FLOW);
2396-
}
23972382
Flow visitRefAs(RefAs* curr) {
23982383
// TODO: Remove this once interpretation is implemented.
23992384
if (curr->op == ExternInternalize || curr->op == ExternExternalize) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; RUN: wasm-opt %s --precompute --fuzz-exec -all -S -o - | filecheck %s
4+
5+
(module
6+
;; CHECK: (func $eq-no (type $0) (result i32)
7+
;; CHECK-NEXT: (i32.const 0)
8+
;; CHECK-NEXT: )
9+
(func $eq-no (export "eq-no") (result i32)
10+
(string.eq
11+
(string.const "ab")
12+
(string.const "cdefg")
13+
)
14+
)
15+
16+
;; CHECK: (func $eq-yes (type $0) (result i32)
17+
;; CHECK-NEXT: (i32.const 1)
18+
;; CHECK-NEXT: )
19+
(func $eq-yes (export "eq-yes") (result i32)
20+
(string.eq
21+
(string.const "ab")
22+
(string.const "ab")
23+
)
24+
)
25+
)
26+

0 commit comments

Comments
 (0)