@@ -38,48 +38,6 @@ namespace {
3838
3939using RecGroupInfo = std::vector<HeapType>;
4040
41- struct HeapTypeInfo {
42- using type_t = HeapType;
43- // Used in assertions to ensure that temporary types don't leak into the
44- // global store.
45- bool isTemp = false ;
46- bool isOpen = false ;
47- Shareability share = Unshared;
48- // The supertype of this HeapType, if it exists.
49- HeapTypeInfo* supertype = nullptr ;
50- // The descriptor of this HeapType, if it exists.
51- HeapTypeInfo* descriptor = nullptr ;
52- // The HeapType described by this one, if it exists.
53- HeapTypeInfo* described = nullptr ;
54- // The recursion group of this type or null if the recursion group is trivial
55- // (i.e. contains only this type).
56- RecGroupInfo* recGroup = nullptr ;
57- size_t recGroupIndex = 0 ;
58- HeapTypeKind kind;
59- union {
60- Signature signature;
61- Continuation continuation;
62- Struct struct_;
63- Array array;
64- };
65-
66- HeapTypeInfo (Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
67- HeapTypeInfo (Continuation continuation)
68- : kind(HeapTypeKind::Cont), continuation(continuation) {}
69- HeapTypeInfo (const Struct& struct_)
70- : kind(HeapTypeKind::Struct), struct_(struct_) {}
71- HeapTypeInfo (Struct&& struct_)
72- : kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
73- HeapTypeInfo (Array array) : kind(HeapTypeKind::Array), array(array) {}
74- ~HeapTypeInfo ();
75-
76- constexpr bool isSignature () const { return kind == HeapTypeKind::Func; }
77- constexpr bool isContinuation () const { return kind == HeapTypeKind::Cont; }
78- constexpr bool isStruct () const { return kind == HeapTypeKind::Struct; }
79- constexpr bool isArray () const { return kind == HeapTypeKind::Array; }
80- constexpr bool isData () const { return isStruct () || isArray (); }
81- };
82-
8341// Helper for coinductively checking whether a pair of Types or HeapTypes are in
8442// a subtype relation.
8543struct SubTyper {
@@ -223,7 +181,7 @@ namespace {
223181
224182HeapTypeInfo* getHeapTypeInfo (HeapType ht) {
225183 assert (!ht.isBasic ());
226- return ( HeapTypeInfo*) ht.getID ();
184+ return reinterpret_cast < HeapTypeInfo*>( ht.getID () );
227185}
228186
229187HeapType asHeapType (std::unique_ptr<HeapTypeInfo>& info) {
@@ -242,95 +200,6 @@ bool isTemp(HeapType type) {
242200// from reference types to the referenced heap types are not walked, so
243201// subclasses should handle referenced heap types when their reference types are
244202// visited.
245- template <typename Self> struct TypeGraphWalkerBase {
246- void walkRoot (Type* type) {
247- assert (taskList.empty ());
248- taskList.push_back (Task::scan (type));
249- doWalk ();
250- }
251-
252- void walkRoot (HeapType* ht) {
253- assert (taskList.empty ());
254- taskList.push_back (Task::scan (ht));
255- doWalk ();
256- }
257-
258- protected:
259- Self& self () { return *static_cast <Self*>(this ); }
260-
261- void scanType (Type* type) {
262- if (type->isTuple ()) {
263- auto & types = const_cast <Tuple&>(type->getTuple ());
264- for (auto it = types.rbegin (); it != types.rend (); ++it) {
265- taskList.push_back (Task::scan (&*it));
266- }
267- }
268- }
269-
270- void scanHeapType (HeapType* ht) {
271- if (ht->isBasic ()) {
272- return ;
273- }
274- auto * info = getHeapTypeInfo (*ht);
275- switch (info->kind ) {
276- case HeapTypeKind::Func:
277- taskList.push_back (Task::scan (&info->signature .results ));
278- taskList.push_back (Task::scan (&info->signature .params ));
279- break ;
280- case HeapTypeKind::Cont:
281- taskList.push_back (Task::scan (&info->continuation .type ));
282- break ;
283- case HeapTypeKind::Struct: {
284- auto & fields = info->struct_ .fields ;
285- for (auto field = fields.rbegin (); field != fields.rend (); ++field) {
286- taskList.push_back (Task::scan (&field->type ));
287- }
288- break ;
289- }
290- case HeapTypeKind::Array:
291- taskList.push_back (Task::scan (&info->array .element .type ));
292- break ;
293- case HeapTypeKind::Basic:
294- WASM_UNREACHABLE (" unexpected kind" );
295- }
296- }
297-
298- private:
299- struct Task {
300- enum Kind {
301- ScanType,
302- ScanHeapType,
303- } kind;
304- union {
305- Type* type;
306- HeapType* heapType;
307- };
308- static Task scan (Type* type) { return Task (type, ScanType); }
309- static Task scan (HeapType* ht) { return Task (ht, ScanHeapType); }
310-
311- private:
312- Task (Type* type, Kind kind) : kind(kind), type(type) {}
313- Task (HeapType* ht, Kind kind) : kind(kind), heapType(ht) {}
314- };
315-
316- std::vector<Task> taskList;
317-
318- void doWalk () {
319- while (!taskList.empty ()) {
320- auto curr = taskList.back ();
321- taskList.pop_back ();
322- switch (curr.kind ) {
323- case Task::ScanType:
324- self ().scanType (curr.type );
325- break ;
326- case Task::ScanHeapType:
327- self ().scanHeapType (curr.heapType );
328- break ;
329- }
330- }
331- }
332- };
333-
334203// A type graph walker that scans each each direct HeapType child of the root.
335204template <typename Self> struct HeapTypeChildWalker : TypeGraphWalkerBase<Self> {
336205 void scanType (Type* type) {
0 commit comments