Skip to content

Commit b77deec

Browse files
manoskoukCommit Bot
authored andcommitted
[wasm-gc] Remove abstract rtts
In the latest wasm-gc spec, rtts of abstract types are no longer allowed. Consequently, canonical rtts of concrete types always have a depth of 0. Changes: - Change the immediate argument of rtts to a type index over a heap type. Abstract it with TypeIndexImmediate in function body decoding. This affects: value_type.h, read_value_type(), decoding of relevant opcodes, wasm subtyping, WasmInitExpr, consume_init_expr(), and wasm-module-builder.cc. - In function-body-decoder-impl.h, update rtt.canon to always produce an rtt of depth 0. - Pass a unit32_t type index over a HeapType to all rtt-related utilities. - Remove infrastructure for abstract-type rtts from the wasm compilers, setup-heap-internal.cc, roots.h, and module-instantiate.cc. - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches from ref.test, ref.cast and br_on_cast implementations in the wasm compilers. - Remove unused 'parent' field from WasmTypeInfo. - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap, and CreateArrayMap. - Use more convenient arguments in IsHeapSubtypeOf. - Update tests. Bug: v8:7748 Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248 Commit-Queue: Manos Koukoutos <manoskouk@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#72321}
1 parent 4adf55a commit b77deec

24 files changed

Lines changed: 410 additions & 794 deletions

src/compiler/wasm-compiler.cc

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5719,42 +5719,17 @@ Node* WasmGraphBuilder::ArrayNewWithRtt(uint32_t array_index,
57195719
return a;
57205720
}
57215721

5722-
Node* WasmGraphBuilder::RttCanon(wasm::HeapType type) {
5723-
RootIndex index;
5724-
switch (type.representation()) {
5725-
case wasm::HeapType::kEq:
5726-
index = RootIndex::kWasmRttEqrefMap;
5727-
break;
5728-
case wasm::HeapType::kExtern:
5729-
index = RootIndex::kWasmRttExternrefMap;
5730-
break;
5731-
case wasm::HeapType::kFunc:
5732-
index = RootIndex::kWasmRttFuncrefMap;
5733-
break;
5734-
case wasm::HeapType::kI31:
5735-
index = RootIndex::kWasmRttI31refMap;
5736-
break;
5737-
case wasm::HeapType::kAny:
5738-
index = RootIndex::kWasmRttAnyrefMap;
5739-
break;
5740-
case wasm::HeapType::kBottom:
5741-
UNREACHABLE();
5742-
default: {
5743-
// User-defined type.
5744-
Node* maps_list =
5745-
LOAD_INSTANCE_FIELD(ManagedObjectMaps, MachineType::TaggedPointer());
5746-
return LOAD_FIXED_ARRAY_SLOT_PTR(maps_list, type.ref_index());
5747-
}
5748-
}
5749-
return LOAD_FULL_POINTER(BuildLoadIsolateRoot(),
5750-
IsolateData::root_slot_offset(index));
5722+
Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
5723+
Node* maps_list =
5724+
LOAD_INSTANCE_FIELD(ManagedObjectMaps, MachineType::TaggedPointer());
5725+
return LOAD_FIXED_ARRAY_SLOT_PTR(maps_list, type_index);
57515726
}
57525727

5753-
Node* WasmGraphBuilder::RttSub(wasm::HeapType type, Node* parent_rtt) {
5754-
return CALL_BUILTIN(WasmAllocateRtt,
5755-
graph()->NewNode(mcgraph()->common()->Int32Constant(
5756-
type.representation())),
5757-
parent_rtt);
5728+
Node* WasmGraphBuilder::RttSub(uint32_t type_index, Node* parent_rtt) {
5729+
return CALL_BUILTIN(
5730+
WasmAllocateRtt,
5731+
graph()->NewNode(mcgraph()->common()->Int32Constant(type_index)),
5732+
parent_rtt);
57585733
}
57595734

57605735
void AssertFalse(MachineGraph* mcgraph, GraphAssembler* gasm, Node* condition) {
@@ -5773,9 +5748,6 @@ Node* WasmGraphBuilder::RefTest(Node* object, Node* rtt,
57735748
ObjectReferenceKnowledge config) {
57745749
auto done = gasm_->MakeLabel(MachineRepresentation::kWord32);
57755750
if (config.object_can_be_i31) {
5776-
if (config.rtt_is_i31) {
5777-
return gasm_->IsI31(object);
5778-
}
57795751
gasm_->GotoIf(gasm_->IsI31(object), &done, gasm_->Int32Constant(0));
57805752
} else {
57815753
AssertFalse(mcgraph(), gasm_.get(), gasm_->IsI31(object));
@@ -5810,12 +5782,7 @@ Node* WasmGraphBuilder::RefCast(Node* object, Node* rtt,
58105782
ObjectReferenceKnowledge config,
58115783
wasm::WasmCodePosition position) {
58125784
if (config.object_can_be_i31) {
5813-
if (config.rtt_is_i31) {
5814-
TrapIfFalse(wasm::kTrapIllegalCast, gasm_->IsI31(object), position);
5815-
return object;
5816-
} else {
5817-
TrapIfTrue(wasm::kTrapIllegalCast, gasm_->IsI31(object), position);
5818-
}
5785+
TrapIfTrue(wasm::kTrapIllegalCast, gasm_->IsI31(object), position);
58195786
} else {
58205787
AssertFalse(mcgraph(), gasm_.get(), gasm_->IsI31(object));
58215788
}
@@ -5861,17 +5828,12 @@ Node* WasmGraphBuilder::BrOnCast(Node* object, Node* rtt,
58615828

58625829
Node* is_i31 = gasm_->IsI31(object);
58635830
if (config.object_can_be_i31) {
5864-
if (config.rtt_is_i31) {
5865-
BranchExpectFalse(is_i31, match_control, no_match_control);
5866-
return nullptr;
5867-
} else {
5868-
Node* i31_branch = graph()->NewNode(
5869-
mcgraph()->common()->Branch(BranchHint::kFalse), is_i31, control());
5870-
SetControl(graph()->NewNode(mcgraph()->common()->IfFalse(), i31_branch));
5871-
no_match_controls.emplace_back(
5872-
graph()->NewNode(mcgraph()->common()->IfTrue(), i31_branch));
5873-
no_match_effects.emplace_back(effect());
5874-
}
5831+
Node* i31_branch = graph()->NewNode(
5832+
mcgraph()->common()->Branch(BranchHint::kFalse), is_i31, control());
5833+
SetControl(graph()->NewNode(mcgraph()->common()->IfFalse(), i31_branch));
5834+
no_match_controls.emplace_back(
5835+
graph()->NewNode(mcgraph()->common()->IfTrue(), i31_branch));
5836+
no_match_effects.emplace_back(effect());
58755837
} else {
58765838
AssertFalse(mcgraph(), gasm_.get(), is_i31);
58775839
}

src/compiler/wasm-compiler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ class WasmGraphBuilder {
166166
bool object_can_be_null;
167167
bool object_must_be_data_ref;
168168
bool object_can_be_i31;
169-
bool rtt_is_i31;
170169
uint8_t rtt_depth;
171170
};
172171
enum EnforceBoundsCheck : bool { // --
@@ -434,8 +433,8 @@ class WasmGraphBuilder {
434433
Node* I31New(Node* input);
435434
Node* I31GetS(Node* input);
436435
Node* I31GetU(Node* input);
437-
Node* RttCanon(wasm::HeapType type);
438-
Node* RttSub(wasm::HeapType type, Node* parent_rtt);
436+
Node* RttCanon(uint32_t type_index);
437+
Node* RttSub(uint32_t type_index, Node* parent_rtt);
439438
Node* RefTest(Node* object, Node* rtt, ObjectReferenceKnowledge config);
440439
Node* RefCast(Node* object, Node* rtt, ObjectReferenceKnowledge config,
441440
wasm::WasmCodePosition position);

src/diagnostics/objects-printer.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,6 @@ void AsmWasmData::AsmWasmDataPrint(std::ostream& os) { // NOLINT
17161716
void WasmTypeInfo::WasmTypeInfoPrint(std::ostream& os) { // NOLINT
17171717
PrintHeader(os, "WasmTypeInfo");
17181718
os << "\n - type address: " << reinterpret_cast<void*>(foreign_address());
1719-
os << "\n - parent: " << Brief(parent());
17201719
os << "\n";
17211720
}
17221721

src/heap/factory.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,24 +1308,22 @@ Handle<Foreign> Factory::NewForeign(Address addr) {
13081308
}
13091309

13101310
Handle<WasmTypeInfo> Factory::NewWasmTypeInfo(Address type_address,
1311-
Handle<Map> parent) {
1311+
Handle<Map> opt_parent) {
13121312
Handle<ArrayList> subtypes = ArrayList::New(isolate(), 0);
13131313
Handle<FixedArray> supertypes;
1314-
if (parent->IsWasmStructMap() || parent->IsWasmArrayMap()) {
1315-
supertypes = CopyFixedArrayAndGrow(
1316-
handle(parent->wasm_type_info().supertypes(), isolate()), 1);
1317-
supertypes->set(supertypes->length() - 1, *parent);
1314+
if (opt_parent.is_null()) {
1315+
supertypes = NewUninitializedFixedArray(0);
13181316
} else {
1319-
supertypes = NewUninitializedFixedArray(1);
1320-
supertypes->set(0, *parent);
1317+
supertypes = CopyFixedArrayAndGrow(
1318+
handle(opt_parent->wasm_type_info().supertypes(), isolate()), 1);
1319+
supertypes->set(supertypes->length() - 1, *opt_parent);
13211320
}
13221321
Map map = *wasm_type_info_map();
13231322
HeapObject result = AllocateRawWithImmortalMap(map.instance_size(),
13241323
AllocationType::kYoung, map);
13251324
Handle<WasmTypeInfo> info(WasmTypeInfo::cast(result), isolate());
13261325
info->AllocateExternalPointerEntries(isolate());
13271326
info->set_foreign_address(isolate(), type_address);
1328-
info->set_parent(*parent);
13291327
info->set_supertypes(*supertypes);
13301328
info->set_subtypes(*subtypes);
13311329
return info;

src/heap/factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
548548
Handle<JSModuleNamespace> NewJSModuleNamespace();
549549

550550
Handle<WasmTypeInfo> NewWasmTypeInfo(Address type_address,
551-
Handle<Map> parent);
551+
Handle<Map> opt_parent);
552552

553553
Handle<SourceTextModule> NewSourceTextModule(Handle<SharedFunctionInfo> code);
554554
Handle<SyntheticModule> NewSyntheticModule(

src/heap/setup-heap-internal.cc

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,6 @@ bool Heap::CreateInitialMaps() {
504504
ALLOCATE_MAP(CODE_DATA_CONTAINER_TYPE, CodeDataContainer::kSize,
505505
code_data_container)
506506

507-
// The wasm_rttcanon_* maps are never used for real objects, only as
508-
// sentinels. They are maps so that they fit in with their subtype maps
509-
// (which are real maps).
510-
ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_eqref)
511-
ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_externref)
512-
ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_funcref)
513-
ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_i31ref)
514-
ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_anyref)
515507
ALLOCATE_MAP(WASM_TYPE_INFO_TYPE, WasmTypeInfo::kSize, wasm_type_info)
516508

517509
ALLOCATE_MAP(WEAK_CELL_TYPE, WeakCell::kSize, weak_cell)
@@ -621,74 +613,6 @@ bool Heap::CreateInitialMaps() {
621613
set_empty_closure_feedback_cell_array(ClosureFeedbackCellArray::cast(obj));
622614
}
623615

624-
// Set up the WasmTypeInfo objects for built-in generic Wasm RTTs.
625-
// anyref:
626-
{
627-
/* Subtypes. We do not cache subtypes for (rtt.canon any). */
628-
int slot_count = ArrayList::kHeaderFields;
629-
if (!AllocateRaw(ArrayList::SizeFor(slot_count), AllocationType::kOld)
630-
.To(&obj)) {
631-
return false;
632-
}
633-
obj.set_map_after_allocation(roots.array_list_map());
634-
ArrayList subtypes = ArrayList::cast(obj);
635-
subtypes.set_length(slot_count);
636-
subtypes.SetLength(0);
637-
/* TypeInfo */
638-
if (!AllocateRaw(WasmTypeInfo::kSize, AllocationType::kOld).To(&obj)) {
639-
return false;
640-
}
641-
obj.set_map_after_allocation(roots.wasm_type_info_map(),
642-
SKIP_WRITE_BARRIER);
643-
WasmTypeInfo type_info = WasmTypeInfo::cast(obj);
644-
type_info.set_subtypes(subtypes);
645-
type_info.set_supertypes(roots.empty_fixed_array());
646-
type_info.set_parent(roots.null_map());
647-
type_info.clear_foreign_address(isolate());
648-
wasm_rttcanon_anyref_map().set_wasm_type_info(type_info);
649-
}
650-
651-
// Rest of builtin types:
652-
#define ALLOCATE_TYPE_INFO(which) \
653-
{ \
654-
/* Subtypes */ \
655-
int slot_count = ArrayList::kHeaderFields; \
656-
if (!AllocateRaw(ArrayList::SizeFor(slot_count), AllocationType::kOld) \
657-
.To(&obj)) { \
658-
return false; \
659-
} \
660-
obj.set_map_after_allocation(roots.array_list_map()); \
661-
ArrayList subtypes = ArrayList::cast(obj); \
662-
subtypes.set_length(slot_count); \
663-
subtypes.SetLength(0); \
664-
/* Supertypes */ \
665-
if (!AllocateRaw(FixedArray::SizeFor(1), AllocationType::kOld).To(&obj)) { \
666-
return false; \
667-
} \
668-
obj.set_map_after_allocation(roots.fixed_array_map(), SKIP_WRITE_BARRIER); \
669-
FixedArray supertypes = FixedArray::cast(obj); \
670-
supertypes.set_length(1); \
671-
supertypes.set(0, wasm_rttcanon_anyref_map()); \
672-
/* TypeInfo */ \
673-
if (!AllocateRaw(WasmTypeInfo::kSize, AllocationType::kOld).To(&obj)) { \
674-
return false; \
675-
} \
676-
obj.set_map_after_allocation(roots.wasm_type_info_map(), \
677-
SKIP_WRITE_BARRIER); \
678-
WasmTypeInfo type_info = WasmTypeInfo::cast(obj); \
679-
type_info.set_subtypes(subtypes); \
680-
type_info.set_supertypes(supertypes); \
681-
type_info.set_parent(wasm_rttcanon_anyref_map()); \
682-
type_info.clear_foreign_address(isolate()); \
683-
wasm_rttcanon_##which##_map().set_wasm_type_info(type_info); \
684-
}
685-
686-
ALLOCATE_TYPE_INFO(eqref)
687-
ALLOCATE_TYPE_INFO(externref)
688-
ALLOCATE_TYPE_INFO(funcref)
689-
ALLOCATE_TYPE_INFO(i31ref)
690-
#undef ALLOCATE_TYPE_INFO
691-
692616
DCHECK(!InYoungGeneration(roots.empty_fixed_array()));
693617

694618
roots.bigint_map().SetConstructorFunctionIndex(

src/objects/objects-body-descriptors-inl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ class WasmTypeInfo::BodyDescriptor final : public BodyDescriptorBase {
563563
ObjectVisitor* v) {
564564
Foreign::BodyDescriptor::IterateBody<ObjectVisitor>(map, obj, object_size,
565565
v);
566-
IteratePointer(obj, kParentOffset, v);
567566
IteratePointer(obj, kSupertypesOffset, v);
568567
IteratePointer(obj, kSubtypesOffset, v);
569568
}

src/roots/roots.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ class Symbol;
200200
/* Maps */ \
201201
V(Map, external_map, ExternalMap) \
202202
V(Map, message_object_map, JSMessageObjectMap) \
203-
V(Map, wasm_rttcanon_eqref_map, WasmRttEqrefMap) \
204-
V(Map, wasm_rttcanon_externref_map, WasmRttExternrefMap) \
205-
V(Map, wasm_rttcanon_funcref_map, WasmRttFuncrefMap) \
206-
V(Map, wasm_rttcanon_i31ref_map, WasmRttI31refMap) \
207-
V(Map, wasm_rttcanon_anyref_map, WasmRttAnyrefMap) \
208203
/* Canonical empty values */ \
209204
V(Script, empty_script, EmptyScript) \
210205
V(FeedbackCell, many_closures_cell, ManyClosuresCell) \

0 commit comments

Comments
 (0)