Commit c4113c47 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][refactor] Simplify/unify parts of the function decoder

Changes:
- Remove TypeCheckBranchResult. Change TypeCheckBranch() to return bool.
  Refactor call sites to reflect this (decouple current code
  reachability check from type check).
- Unify TypeCheckBranch(), TypeCheckFallthrough(), and the type-checking
  part of Return() into TypeCheckStackAgainstMerge().
- Make sure all TypeCheck* functions are only called within VALIDATE.
- In graph-builder-interface, rename end_env -> merge_env to reflect
  its function for loops.
- Change expected error messages in some tests.

Change-Id: I857edc18db9c2454ad12d539ffe7a10e96367710
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2839560Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74100}
parent 32281d62
This diff is collapsed.
......@@ -95,7 +95,7 @@ class WasmGraphBuildingInterface {
};
struct Control : public ControlBase<Value, validate> {
SsaEnv* end_env = nullptr; // end environment for the construct.
SsaEnv* merge_env = nullptr; // merge environment for the construct.
SsaEnv* false_env = nullptr; // false environment (only for if).
TryInfo* try_info = nullptr; // information about try statements.
int32_t previous_catch = -1; // previous Control with a catch.
......@@ -154,15 +154,15 @@ class WasmGraphBuildingInterface {
void Block(FullDecoder* decoder, Control* block) {
// The branch environment is the outer environment.
block->end_env = ssa_env_;
block->merge_env = ssa_env_;
SetEnv(Steal(decoder->zone(), ssa_env_));
}
void Loop(FullDecoder* decoder, Control* block) {
SsaEnv* finish_try_env = Steal(decoder->zone(), ssa_env_);
block->end_env = finish_try_env;
SetEnv(finish_try_env);
// The continue environment is the inner environment.
// This is the merge environment at the beginning of the loop.
SsaEnv* merge_env = Steal(decoder->zone(), ssa_env_);
block->merge_env = merge_env;
SetEnv(merge_env);
ssa_env_->state = SsaEnv::kMerged;
......@@ -214,15 +214,15 @@ class WasmGraphBuildingInterface {
control());
}
// Now we setup a new environment for the inside of the loop.
SetEnv(Split(decoder->zone(), ssa_env_));
builder_->StackCheck(decoder->position());
ssa_env_->SetNotMerged();
if (!decoder->ok()) return;
// Wrap input merge into phis.
for (uint32_t i = 0; i < block->start_merge.arity; ++i) {
Value& val = block->start_merge[i];
TFNode* inputs[] = {val.node, block->end_env->control};
TFNode* inputs[] = {val.node, block->merge_env->control};
val.node = builder_->Phi(val.type, 1, inputs);
}
}
......@@ -236,7 +236,7 @@ class WasmGraphBuildingInterface {
SsaEnv* try_env = Steal(decoder->zone(), outer_env);
SetEnv(try_env);
TryInfo* try_info = decoder->zone()->New<TryInfo>(catch_env);
block->end_env = outer_env;
block->merge_env = outer_env;
block->try_info = try_info;
}
......@@ -244,12 +244,12 @@ class WasmGraphBuildingInterface {
TFNode* if_true = nullptr;
TFNode* if_false = nullptr;
builder_->BranchNoHint(cond.node, &if_true, &if_false);
SsaEnv* end_env = ssa_env_;
SsaEnv* merge_env = ssa_env_;
SsaEnv* false_env = Split(decoder->zone(), ssa_env_);
false_env->control = if_false;
SsaEnv* true_env = Steal(decoder->zone(), ssa_env_);
true_env->control = if_true;
if_block->end_env = end_env;
if_block->merge_env = merge_env;
if_block->false_env = false_env;
SetEnv(true_env);
}
......@@ -290,7 +290,7 @@ class WasmGraphBuildingInterface {
MergeValuesInto(decoder, block, &block->end_merge, values);
}
// Now continue with the merged environment.
SetEnv(block->end_env);
SetEnv(block->merge_env);
}
void UnOp(FullDecoder* decoder, WasmOpcode opcode, const Value& value,
......@@ -1197,7 +1197,7 @@ class WasmGraphBuildingInterface {
Value* values) {
DCHECK(merge == &c->start_merge || merge == &c->end_merge);
SsaEnv* target = c->end_env;
SsaEnv* target = c->merge_env;
// This has to be computed before calling Goto().
const bool first = target->state == SsaEnv::kUnreachable;
......
*%(basename)s:9: CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
*%(basename)s:9: CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
let rethrow = e => setTimeout(_ => {throw e}, 0);
^
CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
CompileError: WebAssembly.compile(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
*%(basename)s:9: CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
*%(basename)s:9: CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
let rethrow = e => setTimeout(_ => {throw e}, 0);
^
CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
CompileError: WebAssembly.instantiate(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
*%(basename)s:11: CompileError: WebAssembly.compileStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
*%(basename)s:11: CompileError: WebAssembly.compileStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
let rethrow = e => setTimeout(_ => {throw e}, 0);
^
CompileError: WebAssembly.compileStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
CompileError: WebAssembly.compileStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
*%(basename)s:11: CompileError: WebAssembly.instantiateStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
*%(basename)s:11: CompileError: WebAssembly.instantiateStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
let rethrow = e => setTimeout(_ => {throw e}, 0);
^
CompileError: WebAssembly.instantiateStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
CompileError: WebAssembly.instantiateStreaming(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
*%(basename)s:9: CompileError: WebAssembly.Module(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
*%(basename)s:9: CompileError: WebAssembly.Module(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
new WebAssembly.Module(builder.toBuffer());
^
CompileError: WebAssembly.Module(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru to @1, found 0 @+24
CompileError: WebAssembly.Module(): Compiling function #0:"f" failed: expected 1 elements on the stack for fallthru, found 0 @+24
at *%(basename)s:9:1
......@@ -29,5 +29,5 @@ kExprEnd, // @21
assertThrows(
() => {builder.toModule()}, WebAssembly.CompileError,
'WebAssembly.Module(): Compiling function #0:\"main\" failed: ' +
'type error in merge[0] (expected f32, got i32) @+57');
'type error in branch[0] (expected f32, got i32) @+57');
})();
......@@ -67,7 +67,7 @@ assertPromiseResult(async function badFunctionInTheMiddle() {
await assertCompileError(
buffer,
'Compiling function #10:\"bad\" failed: ' +
'expected 1 elements on the stack for fallthru to @1, found 0 @+94');
'expected 1 elements on the stack for fallthru, found 0 @+94');
}());
assertPromiseResult(async function importWithoutCode() {
......
......@@ -35,7 +35,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertPromiseResult(WebAssembly.compile(bytes)
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): type error in " +
"merge[0] (expected i32, got i64) @+56", error.message)));
"fallthru[0] (expected i32, got i64) @+56", error.message)));
})();
(function testCompileEmptyModule() {
......
......@@ -33,7 +33,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertThrows(() => builder.toModule(),
WebAssembly.CompileError,
"WebAssembly.Module(): Compiling function #0:\"id\" failed: type error " +
"in merge[0] (expected i32, got i64) @+56");
"in fallthru[0] (expected i32, got i64) @+56");
})();
(function testCompileEmptyModule() {
......
......@@ -3841,7 +3841,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnNull) {
WASM_I32V(0), kExprSelectWithType, 1,
WASM_REF_TYPE(reps[0]))},
kAppendEnd,
"expected 1 elements on the stack for br to @1, found 0");
"expected 1 elements on the stack for branch, found 0");
}
TEST_F(FunctionBodyDecoderTest, GCStruct) {
......@@ -3880,8 +3880,7 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
&sig_r_v,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0), WASM_I32V(1),
WASM_RTT_CANON(struct_type_index))},
kAppendEnd,
"expected 1 elements on the stack for fallthru to @1, found 2");
kAppendEnd, "expected 1 elements on the stack for fallthru, found 2");
// Mistyped arguments.
ExpectFailure(&sig_v_r,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_LOCAL_GET(0),
......@@ -3927,7 +3926,7 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
ExpectFailure(
&sig_f_r,
{WASM_STRUCT_GET(struct_type_index, field_index, WASM_LOCAL_GET(0))},
kAppendEnd, "type error in merge[0] (expected f32, got i32)");
kAppendEnd, "type error in fallthru[0] (expected f32, got i32)");
/** struct.set **/
ExpectValidates(&sig_v_r, {WASM_STRUCT_SET(struct_type_index, field_index,
......@@ -3953,7 +3952,7 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
{WASM_STRUCT_SET(struct_type_index, field_index,
WASM_LOCAL_GET(0), WASM_I32V(0))},
kAppendEnd,
"expected 1 elements on the stack for fallthru to @1, found 0");
"expected 1 elements on the stack for fallthru, found 0");
// Setting immutable field.
ExpectFailure(
sigs.v_v(),
......@@ -4063,7 +4062,7 @@ TEST_F(FunctionBodyDecoderTest, GCArray) {
ExpectFailure(
&sig_f_r,
{WASM_ARRAY_GET(array_type_index, WASM_LOCAL_GET(0), WASM_I32V(5))},
kAppendEnd, "type error in merge[0] (expected f32, got funcref)");
kAppendEnd, "type error in fallthru[0] (expected f32, got funcref)");
// array.get_s/u fail.
ExpectFailure(
......@@ -4112,7 +4111,8 @@ TEST_F(FunctionBodyDecoderTest, GCArray) {
{WASM_ARRAY_LEN(array_type_index, WASM_LOCAL_GET(0))});
// Wrong return type.
ExpectFailure(&sig_f_r, {WASM_ARRAY_LEN(array_type_index, WASM_LOCAL_GET(0))},
kAppendEnd, "type error in merge[0] (expected f32, got i32)");
kAppendEnd,
"type error in fallthru[0] (expected f32, got i32)");
// Non-array type index.
ExpectFailure(&sig_i_r,
{WASM_ARRAY_LEN(struct_type_index, WASM_LOCAL_GET(0))},
......@@ -4234,7 +4234,7 @@ TEST_F(FunctionBodyDecoderTest, RttCanon) {
ValueType rtt2 = ValueType::Rtt(type_index, 1);
FunctionSig sig2(1, 0, &rtt2);
ExpectFailure(&sig2, {WASM_RTT_CANON(type_index)}, kAppendEnd,
"type error in merge[0]");
"type error in fallthru[0]");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment