Commit fd8309e8 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm] Rename "initializer" expression to "constant"

Change-Id: I6f2e5fa04eba1b3c97212be945b776ebc2be5915
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3726210Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81399}
parent 2b3bff58
......@@ -1366,14 +1366,13 @@ class WasmDecoder : public Decoder {
if (decoding_mode == kConstantExpression) {
if (!VALIDATE(!imm.global->mutability)) {
this->DecodeError(pc,
"mutable globals cannot be used in initializer "
"mutable globals cannot be used in constant "
"expressions");
return false;
}
if (!VALIDATE(imm.global->imported || this->enabled_.has_gc())) {
this->DecodeError(
pc,
"non-imported globals cannot be used in initializer expressions");
pc, "non-imported globals cannot be used in constant expressions");
return false;
}
}
......@@ -3691,7 +3690,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
#undef DECODE
static int NonConstError(WasmFullDecoder* decoder, WasmOpcode opcode) {
decoder->DecodeError("opcode %s is not allowed in init. expressions",
decoder->DecodeError("opcode %s is not allowed in constant expressions",
WasmOpcodes::OpcodeName(opcode));
return 0;
}
......@@ -4094,9 +4093,9 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
uint32_t DecodeSimdOpcode(WasmOpcode opcode, uint32_t opcode_length) {
if (decoding_mode == kConstantExpression) {
// Currently, only s128.const is allowed in initializer expressions.
// Currently, only s128.const is allowed in constant expressions.
if (opcode != kExprS128Const) {
this->DecodeError("opcode %s is not allowed in init. expressions",
this->DecodeError("opcode %s is not allowed in constant expressions",
this->SafeOpcodeNameAt(this->pc()));
return 0;
}
......@@ -4246,11 +4245,11 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
this->module_);
}
#define NON_CONST_ONLY \
if (decoding_mode == kConstantExpression) { \
this->DecodeError("opcode %s is not allowed in init. expressions", \
this->SafeOpcodeNameAt(this->pc())); \
return 0; \
#define NON_CONST_ONLY \
if (decoding_mode == kConstantExpression) { \
this->DecodeError("opcode %s is not allowed in constant expressions", \
this->SafeOpcodeNameAt(this->pc())); \
return 0; \
}
int DecodeGCOpcode(WasmOpcode opcode, uint32_t opcode_length) {
......@@ -5825,12 +5824,10 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
bool TypeCheckStackAgainstMerge(uint32_t drop_values, Merge<Value>* merge) {
static_assert(validate, "Call this function only within VALIDATE");
constexpr const char* merge_description =
merge_type == kBranchMerge
? "branch"
: merge_type == kReturnMerge
? "return"
: merge_type == kInitExprMerge ? "init. expression"
: "fallthru";
merge_type == kBranchMerge ? "branch"
: merge_type == kReturnMerge ? "return"
: merge_type == kInitExprMerge ? "constant expression"
: "fallthru";
uint32_t arity = merge->arity;
uint32_t actual = stack_size() - control_.back().stack_depth;
// Here we have to check for !unreachable(), because we need to typecheck as
......
......@@ -1682,7 +1682,7 @@ class ModuleDecoderImpl : public Decoder {
WasmError intermediate_error_;
ModuleOrigin origin_;
AccountingAllocator allocator_;
Zone init_expr_zone_{&allocator_, "initializer expression zone"};
Zone init_expr_zone_{&allocator_, "constant expr. zone"};
bool has_seen_unordered_section(SectionCode section_code) {
return seen_unordered_sections_ & (1 << section_code);
......@@ -1940,12 +1940,12 @@ class ModuleDecoderImpl : public Decoder {
uint32_t length;
// The error message mimics the one generated by the {WasmFullDecoder}.
#define TYPE_CHECK(found) \
if (V8_UNLIKELY(!IsSubtypeOf(found, expected, module_.get()))) { \
errorf(pc() + 1, \
"type error in init. expression[0] (expected %s, got %s)", \
expected.name().c_str(), found.name().c_str()); \
return {}; \
#define TYPE_CHECK(found) \
if (V8_UNLIKELY(!IsSubtypeOf(found, expected, module_.get()))) { \
errorf(pc() + 1, \
"type error in constant expression[0] (expected %s, got %s)", \
expected.name().c_str(), found.name().c_str()); \
return {}; \
}
// To avoid initializing a {WasmFullDecoder} for the most common
......@@ -2027,7 +2027,7 @@ class ModuleDecoderImpl : public Decoder {
}
if (!decoder.interface().end_found()) {
error("Initializer expression is missing 'end'");
error("constant expression is missing 'end'");
return {};
}
......@@ -2153,7 +2153,7 @@ class ModuleDecoderImpl : public Decoder {
// - for non-active tables, whether the table is declarative (vs. passive).
constexpr uint8_t kHasTableIndexOrIsDeclarativeMask = 1 << 1;
// The mask for the bit in the flag which indicates if the functions of this
// segment are defined as function indices (0) or init. expressions (1).
// segment are defined as function indices (0) or constant expressions (1).
constexpr uint8_t kExpressionsAsElementsMask = 1 << 2;
constexpr uint8_t kFullMask = kNonActiveMask |
kHasTableIndexOrIsDeclarativeMask |
......
......@@ -445,7 +445,7 @@ InstanceBuilder::InstanceBuilder(Isolate* isolate,
module_object_(module_object),
ffi_(ffi),
memory_buffer_(memory_buffer),
init_expr_zone_(isolate_->allocator(), "init. expression zone") {
init_expr_zone_(isolate_->allocator(), "constant expression zone") {
sanitized_imports_.reserve(module_->import_table.size());
}
......
......@@ -21,9 +21,9 @@ namespace wasm {
struct WasmModule;
class WasmFeatures;
// Representation of an initializer expression. Unlike {ConstantExpression} in
// wasm-module.h, this does not use {WireBytesRef}, i.e., it does not depend on
// a wasm module's bytecode representation.
// Representation of an constant expression. Unlike {ConstantExpression}, this
// does not use {WireBytesRef}, i.e., it does not depend on a wasm module's
// bytecode representation.
class WasmInitExpr : public ZoneObject {
public:
enum Operator {
......
......@@ -880,7 +880,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer* buffer) const {
for (auto segment : data_segments_) {
buffer->write_u8(0); // linear memory segment
buffer->write_u8(kExprI32Const); // initializer expression for dest
buffer->write_u8(kExprI32Const); // constant expression for dest
buffer->write_u32v(segment.dest);
buffer->write_u8(kExprEnd);
buffer->write_u32v(static_cast<uint32_t>(segment.data.size()));
......
......@@ -292,9 +292,9 @@ std::ostream& operator<<(std::ostream& os, const PrintName& name) {
return os.put('\'').write(name.name.begin(), name.name.size()).put('\'');
}
// An interface for WasmFullDecoder used to decode initializer expressions. As
// An interface for WasmFullDecoder used to decode constant expressions. As
// opposed to the one in src/wasm/, this emits {WasmInitExpr} as opposed to a
// {WasmValue}.
// {ConstantExpression} (which evaluates to {WasmValue}).
class InitExprInterface {
public:
static constexpr Decoder::ValidateFlag validate = Decoder::kFullValidation;
......@@ -439,7 +439,7 @@ class InitExprInterface {
Zone* zone_;
};
// Appends an initializer expression encoded in {wire_bytes}, in the offset
// Appends an constant expression encoded in {wire_bytes}, in the offset
// contained in {expr}.
void AppendInitExpr(std::ostream& os, const WasmInitExpr& expr) {
os << "WasmInitExpr.";
......@@ -572,7 +572,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
CHECK_NOT_NULL(module);
AccountingAllocator allocator;
Zone zone(&allocator, "init. expression zone");
Zone zone(&allocator, "constant expression zone");
StdoutStream os;
......
......@@ -107,5 +107,5 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
() => builder.instantiate({m : {g :
new WebAssembly.Global({value: "anyfunc", mutable: true}, null)}}),
WebAssembly.CompileError,
/mutable globals cannot be used in initializer expressions/);
/mutable globals cannot be used in constant expressions/);
})();
......@@ -914,5 +914,5 @@ function js_div(a, b) { return (a / b) | 0; }
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
/non-imported globals cannot be used in initializer expressions/);
/non-imported globals cannot be used in constant expressions/);
})();
......@@ -1534,9 +1534,9 @@ class WasmModuleBuilder {
this.exports.push({name: name, kind: kExternalMemory, index: 0});
}
// {offset} is an initializer expression.
// {offset} is a constant expression.
// If {type} is undefined, then {elements} are function indices. Otherwise,
// they are initializer expressions.
// they are constant expressions.
addActiveElementSegment(table, offset, elements, type) {
checkExpr(offset);
if (type != undefined) {
......@@ -1548,7 +1548,7 @@ class WasmModuleBuilder {
}
// If {type} is undefined, then {elements} are function indices. Otherwise,
// they are initializer expressions.
// they are constant expressions.
addPassiveElementSegment(elements, type) {
if (type != undefined) {
for (let element of elements) checkExpr(element);
......@@ -1559,7 +1559,7 @@ class WasmModuleBuilder {
}
// If {type} is undefined, then {elements} are function indices. Otherwise,
// they are initializer expressions.
// they are constant expressions.
addDeclarativeElementSegment(elements, type) {
if (type != undefined) {
for (let element of elements) checkExpr(element);
......
......@@ -510,7 +510,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
};
EXPECT_FAILURE_WITH_MSG(
no_initializer,
"expected 1 elements on the stack for init. expression, found 0");
"expected 1 elements on the stack for constant expression, found 0");
static const byte too_many_initializers_no_end[] = {
SECTION(Global, // --
......@@ -521,7 +521,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
WASM_I32V_1(43)) // another value is too much
};
EXPECT_FAILURE_WITH_MSG(too_many_initializers_no_end,
"Initializer expression is missing 'end'");
"constant expression is missing 'end'");
static const byte too_many_initializers[] = {
SECTION(Global, // --
......@@ -533,7 +533,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
kExprEnd)};
EXPECT_FAILURE_WITH_MSG(
too_many_initializers,
"expected 1 elements on the stack for init. expression, found 2");
"expected 1 elements on the stack for constant expression, found 2");
static const byte missing_end_opcode[] = {
SECTION(Global, // --
......@@ -543,7 +543,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
WASM_I32V_1(42)) // init value
};
EXPECT_FAILURE_WITH_MSG(missing_end_opcode,
"Initializer expression is missing 'end'");
"constant expression is missing 'end'");
static const byte referencing_out_of_bounds_global[] = {
SECTION(Global, ENTRY_COUNT(1), // --
......@@ -596,7 +596,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
};
EXPECT_FAILURE_WITH_MSG(
referencing_mutable_global,
"mutable globals cannot be used in initializer expressions");
"mutable globals cannot be used in constant expressions");
static const byte referencing_mutable_imported_global[] = {
SECTION(Import, ENTRY_COUNT(1), // --
......@@ -611,7 +611,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
};
EXPECT_FAILURE_WITH_MSG(
referencing_mutable_imported_global,
"mutable globals cannot be used in initializer expressions");
"mutable globals cannot be used in constant expressions");
static const byte referencing_immutable_imported_global[] = {
SECTION(Import, ENTRY_COUNT(1), // --
......@@ -637,7 +637,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
};
EXPECT_FAILURE_WITH_MSG(
referencing_local_global,
"non-imported globals cannot be used in initializer expressions");
"non-imported globals cannot be used in constant expressions");
{
// But: experimental-wasm-gc should enable referencing immutable local
......@@ -647,7 +647,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
// Referencing mutable glocals still invalid.
EXPECT_FAILURE_WITH_MSG(
referencing_mutable_global,
"mutable globals cannot be used in initializer expressions");
"mutable globals cannot be used in constant expressions");
}
}
......@@ -811,7 +811,7 @@ TEST_F(WasmModuleVerifyTest, RttCanonGlobalTypeError) {
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(
result,
"type error in init. expression[0] (expected (rtt 0), got (rtt 1))");
"type error in constant expression[0] (expected (rtt 0), got (rtt 1))");
}
TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
......@@ -848,7 +848,7 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42), WASM_RTT_CANON(0)))};
EXPECT_FAILURE_WITH_MSG(
type_error,
"type error in init. expression[0] (expected (ref 1), got (ref 0))");
"type error in constant expression[0] (expected (ref 1), got (ref 0))");
static const byte subexpr_type_error[] = {
SECTION(Type, ENTRY_COUNT(2), // --
......@@ -902,7 +902,7 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
WASM_RTT_CANON(0)))};
EXPECT_FAILURE_WITH_MSG(
type_error,
"type error in init. expression[0] (expected (ref 1), got (ref 0))");
"type error in constant expression[0] (expected (ref 1), got (ref 0))");
static const byte subexpr_type_error[] = {
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI64Code, true)),
......@@ -1208,7 +1208,7 @@ TEST_F(WasmModuleVerifyTest, TypeCanonicalization) {
SECTION(Global, // --
ENTRY_COUNT(1), kRefCode, 0, 0, // Type, mutability
WASM_ARRAY_NEW_FIXED_STATIC(1, 1, WASM_I32V(10)),
kExprEnd) // Init. expression
kExprEnd) // initial value
};
// Global initializer should verify as identical type in other group
......@@ -1225,13 +1225,13 @@ TEST_F(WasmModuleVerifyTest, TypeCanonicalization) {
SECTION(Global, // --
ENTRY_COUNT(1), kRefCode, 0, 0, // Type, mutability
WASM_ARRAY_NEW_FIXED_STATIC(1, 1, WASM_I32V(10)),
kExprEnd) // Init. expression
kExprEnd) // initial value
};
// Global initializer should not verify as type in distinct rec. group.
EXPECT_FAILURE_WITH_MSG(
non_identical_group,
"type error in init. expression[0] (expected (ref 0), got (ref 1))");
"type error in constant expression[0] (expected (ref 0), got (ref 1))");
}
TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
......@@ -2036,7 +2036,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitFuncRefTableWithExternRefNull) {
EXPECT_FAILURE_WITH_MSG(
data,
"type error in init. expression[0] (expected funcref, got externref)");
"type error in constant expression[0] (expected funcref, got externref)");
}
TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) {
......@@ -2089,7 +2089,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionGlobalGetOutOfBounds) {
0x05, // Mode: Passive with expressions-as-elements
kFuncRefCode, // type
ENTRY_COUNT(1), // element count
kExprGlobalGet, 0x00, kExprEnd)}; // init. expression
kExprGlobalGet, 0x00, kExprEnd)}; // initial value
EXPECT_FAILURE_WITH_MSG(data, "Invalid global index: 0");
}
......@@ -2104,8 +2104,8 @@ TEST_F(WasmModuleVerifyTest, ExtendedConstantsFail) {
// initializer
kExprGlobalGet, 0x00, kExprGlobalGet, 0x00, kExprI32Add,
kExprEnd)};
EXPECT_FAILURE_WITH_MSG(data,
"opcode i32.add is not allowed in init. expressions");
EXPECT_FAILURE_WITH_MSG(
data, "opcode i32.add is not allowed in constant expressions");
}
TEST_F(WasmModuleVerifyTest, ExtendedConstantsI32) {
......@@ -2273,7 +2273,7 @@ TEST_F(WasmModuleVerifyTest, NonNullableTable) {
ENTRY_COUNT(1), // 1 table
kRefCode, 0, // table 0: type
0, 10, // table 0: limits
kExprRefFunc, 0, kExprEnd), // table 0: init. expression
kExprRefFunc, 0, kExprEnd), // table 0: initial value
SECTION(Code, ENTRY_COUNT(1), NOP_BODY)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......
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