Skip to content

Commit 0522697

Browse files
committed
fix
1 parent 35e71d7 commit 0522697

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/passes/GlobalTypeOptimization.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ struct GlobalTypeOptimization : public Pass {
589589
return;
590590
}
591591

592+
// Remove an unneeded descriptor.
593+
if (parent.haveUnneededDescriptors.count(oldType)) {
594+
typeBuilder[i].descriptor(std::nullopt);
595+
}
596+
592597
// Remove an unneeded describee or describe a placeholder type.
593598
if (auto described = oldType.getDescribedType()) {
594599
if (parent.haveUnneededDescriptors.count(*described)) {
@@ -614,11 +619,6 @@ struct GlobalTypeOptimization : public Pass {
614619
}
615620
}
616621
}
617-
618-
// Remove an unneeded descriptor.
619-
if (parent.haveUnneededDescriptors.count(oldType)) {
620-
typeBuilder[i].descriptor(std::nullopt);
621-
}
622622
}
623623
};
624624

test/lit/passes/gto-desc.wast

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,8 +1251,40 @@
12511251
)
12521252
)
12531253

1254+
;; Regression test for a bug where a placeholder was not set up to be described
1255+
;; by its intended descriptor if that intended descriptor also happened to have
1256+
;; its own unneeded descriptor.
1257+
(module
1258+
(rec
1259+
;; CHECK: (rec
1260+
;; CHECK-NEXT: (type $public (descriptor $public.desc (struct)))
1261+
(type $public (descriptor $public.desc (struct)))
1262+
;; CHECK: (type $public.desc (sub (describes $public (struct))))
1263+
(type $public.desc (sub (describes $public (struct))))
1264+
)
1265+
(rec
1266+
;; CHECK: (rec
1267+
;; CHECK-NEXT: (type $private (struct))
1268+
(type $private (descriptor $private.desc (struct)))
1269+
;; CHECK: (type $3 (sub (descriptor $private.desc (struct))))
1270+
1271+
;; CHECK: (type $private.desc (sub $public.desc (describes $3 (struct))))
1272+
(type $private.desc (sub $public.desc (describes $private (descriptor $private.meta (struct)))))
1273+
;; CHECK: (type $private.meta (struct))
1274+
(type $private.meta (describes $private.desc (struct)))
1275+
)
1276+
1277+
;; Force $private.desc to remain a descriptor.
1278+
;; CHECK: (global $public (ref null $public) (ref.null none))
1279+
(global $public (export "public") (ref null $public) (ref.null none))
1280+
1281+
;; CHECK: (global $private (ref null $private) (ref.null none))
1282+
(global $private (ref null $private) (ref.null none))
1283+
)
1284+
12541285
;; Sibling types $A and $B. The supertype that connects them should not stop us
12551286
;; from optimizing $B here, even though $A cannot be optimized.
1287+
;; CHECK: (export "public" (global $public))
12561288
(module
12571289
(rec
12581290
;; CHECK: (rec

0 commit comments

Comments
 (0)