Skip to content
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
55 changes: 20 additions & 35 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
Flow visitStringMeasure(StringMeasure* curr) {
// For now we only support JS-style strings.
assert(curr->op == StringMeasureWTF16View);
if (curr->op != StringMeasureWTF16View) {
return Flow(NONCONSTANT_FLOW);
}

Flow flow = visit(curr->ref);
if (flow.breaking()) {
Expand All @@ -1917,8 +1919,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
return Literal(int32_t(data->values.size()));
}
Flow visitStringEncode(StringEncode* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitStringConcat(StringConcat* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) {
NOTE_ENTER("StringEq");
Flow flow = visit(curr->left);
Expand Down Expand Up @@ -1987,7 +1989,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
Flow visitStringAs(StringAs* curr) {
// For now we only support JS-style strings.
assert(curr->op == StringAsWTF16);
if (curr->op != StringAsWTF16) {
return Flow(NONCONSTANT_FLOW);
}

Flow flow = visit(curr->ref);
if (flow.breaking()) {
Expand All @@ -2004,10 +2008,10 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
return Literal(data, curr->type.getHeapType());
}
Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
WASM_UNREACHABLE("unimp");
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringWTF16Get(StringWTF16Get* curr) {
NOTE_ENTER("StringEq");
NOTE_ENTER("StringWTF16Get");
Flow ref = visit(curr->ref);
if (ref.breaking()) {
return ref;
Expand All @@ -2028,11 +2032,17 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
return Literal(values[i].geti32());
}
Flow visitStringIterNext(StringIterNext* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitStringIterMove(StringIterMove* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitStringSliceWTF(StringSliceWTF* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitStringIterNext(StringIterNext* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringIterMove(StringIterMove* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringSliceWTF(StringSliceWTF* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringSliceIter(StringSliceIter* curr) {
WASM_UNREACHABLE("unimp");
return Flow(NONCONSTANT_FLOW);
}

virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
Expand Down Expand Up @@ -2369,31 +2379,6 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
NOTE_ENTER("Rethrow");
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringMeasure(StringMeasure* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) { return Flow(NONCONSTANT_FLOW); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the critical line for string.eq - this line overrode the parent, so we always returned "give up"...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh got it.

Flow visitStringAs(StringAs* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringWTF16Get(StringWTF16Get* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringIterNext(StringIterNext* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringIterMove(StringIterMove* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringSliceWTF(StringSliceWTF* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitStringSliceIter(StringSliceIter* curr) {
return Flow(NONCONSTANT_FLOW);
}
Flow visitRefAs(RefAs* curr) {
// TODO: Remove this once interpretation is implemented.
if (curr->op == ExternInternalize || curr->op == ExternExternalize) {
Expand Down
26 changes: 26 additions & 0 deletions test/lit/passes/precompute-strings.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.

;; RUN: wasm-opt %s --precompute --fuzz-exec -all -S -o - | filecheck %s

(module
;; CHECK: (func $eq-no (type $0) (result i32)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
(func $eq-no (export "eq-no") (result i32)
(string.eq
(string.const "ab")
(string.const "cdefg")
)
)

;; CHECK: (func $eq-yes (type $0) (result i32)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
(func $eq-yes (export "eq-yes") (result i32)
(string.eq
(string.const "ab")
(string.const "ab")
)
)
)