Skip to content

Commit 58a6e2a

Browse files
committed
[region-isolation] Add Asserting support for {alloc,dealloc}_pack_metadata since they only appear in Lowered SIL.
I also added a note to the SIL.rst and an assert into the SILVerifier to better document this requirement.
1 parent 4a635b6 commit 58a6e2a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/SIL.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,8 @@ Notionally, ``alloc_pack_metadata`` is a stack allocation instruction. See the
38443844
section above on stack discipline. The corresponding stack deallocation
38453845
instruction is ``dealloc_pack_metadata``.
38463846

3847+
Only valid in Lowered SIL.
3848+
38473849
alloc_ref
38483850
`````````
38493851
::
@@ -4124,6 +4126,8 @@ instruction after its operand) must be cleaned up here.
41244126
on Stack Discipline above. The operand must be an ``alloc_pack_metadata``
41254127
instruction.
41264128

4129+
Only valid in Lowered SIL.
4130+
41274131
dealloc_box
41284132
```````````
41294133
::

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6273,13 +6273,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
62736273
require(apmi->getIntroducer()->mayRequirePackMetadata(),
62746274
"Introduces instruction of kind which cannot emit on-stack pack "
62756275
"metadata");
6276+
require(F.getModule().getStage() == SILStage::Lowered,
6277+
"Only supported in lowered SIL");
62766278
}
62776279

62786280
void checkDeallocPackMetadataInst(DeallocPackMetadataInst *dpmi) {
62796281
auto *apmi = dpmi->getOperand()->getDefiningInstruction();
62806282
require(apmi, "Must have instruction operand.");
62816283
require(isa<AllocPackMetadataInst>(apmi),
62826284
"Must have alloc_pack_metadata operand");
6285+
require(F.getModule().getStage() == SILStage::Lowered,
6286+
"Only supported in lowered SIL");
62836287
}
62846288

62856289
void checkMoveOnlyWrapperToCopyableAddrInst(

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,6 @@ CONSTANT_TRANSLATION(YieldInst, Require)
24092409

24102410
// Unhandled instructions
24112411
CONSTANT_TRANSLATION(AllocVectorInst, Unhandled)
2412-
CONSTANT_TRANSLATION(AllocPackMetadataInst, Unhandled)
24132412
CONSTANT_TRANSLATION(AllocExistentialBoxInst, Unhandled)
24142413
CONSTANT_TRANSLATION(IndexRawPointerInst, Unhandled)
24152414
CONSTANT_TRANSLATION(UncheckedTrivialBitCastInst, Unhandled)
@@ -2464,7 +2463,6 @@ CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
24642463
CONSTANT_TRANSLATION(ThrowAddrInst, Unhandled)
24652464
CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, Unhandled)
24662465
CONSTANT_TRANSLATION(DeallocPackInst, Unhandled)
2467-
CONSTANT_TRANSLATION(DeallocPackMetadataInst, Unhandled)
24682466
CONSTANT_TRANSLATION(DeallocStackRefInst, Unhandled)
24692467
CONSTANT_TRANSLATION(DeallocRefInst, Unhandled)
24702468
CONSTANT_TRANSLATION(DeallocPartialRefInst, Unhandled)
@@ -2513,6 +2511,11 @@ CONSTANT_TRANSLATION(StrongRetainUnownedInst, Asserting)
25132511
CONSTANT_TRANSLATION(UnownedReleaseInst, Asserting)
25142512
CONSTANT_TRANSLATION(UnownedRetainInst, Asserting)
25152513

2514+
// Instructions only valid in lowered SIL. Please only add instructions here
2515+
// after adding an assert into the SILVerifier that this property is true.
2516+
CONSTANT_TRANSLATION(AllocPackMetadataInst, Asserting)
2517+
CONSTANT_TRANSLATION(DeallocPackMetadataInst, Asserting)
2518+
25162519
#undef CONSTANT_TRANSLATION
25172520

25182521
#ifdef LOOKTHROUGH_IF_NONSENDABLE_RESULT_REQUIRE_OTHERWISE

0 commit comments

Comments
 (0)