[move-only] Rename mark_must_check -> mark_unresolved_non_copyable_value.

I was originally hoping to reuse mark_must_check for multiple types of checkers.
In practice, this is not what happened... so giving it a name specifically to do
with non copyable types makes more sense and makes the code clearer.

Just a pure rename.
This commit is contained in:
Michael Gottesman
2023-08-30 15:47:28 -07:00
parent 52c732fa92
commit 37d60a08bb
85 changed files with 1106 additions and 974 deletions

View File

@@ -543,29 +543,31 @@ static void replaceAllNonDebugUsesWith(SILValue value,
}
}
static void hoistMarkMustCheckInsts(SILValue stackBox,
MarkMustCheckInst::CheckKind checkKind) {
static void hoistMarkUnresolvedNonCopyableValueInsts(
SILValue stackBox,
MarkUnresolvedNonCopyableValueInst::CheckKind checkKind) {
StackList<Operand *> worklist(stackBox->getFunction());
for (auto *use : stackBox->getUses()) {
worklist.push_back(use);
}
StackList<MarkMustCheckInst *> targets(stackBox->getFunction());
StackList<MarkUnresolvedNonCopyableValueInst *> targets(
stackBox->getFunction());
while (!worklist.empty()) {
auto *nextUse = worklist.pop_back_val();
auto *nextUser = nextUse->getUser();
if (isa<BeginBorrowInst>(nextUser) || isa<BeginAccessInst>(nextUser) ||
isa<CopyValueInst>(nextUser) || isa<MarkUninitializedInst>(nextUser) ||
isa<MarkMustCheckInst>(nextUser)) {
isa<MarkUnresolvedNonCopyableValueInst>(nextUser)) {
for (auto result : nextUser->getResults()) {
for (auto *use : result->getUses())
worklist.push_back(use);
}
}
if (auto *mmci = dyn_cast<MarkMustCheckInst>(nextUser)) {
if (auto *mmci = dyn_cast<MarkUnresolvedNonCopyableValueInst>(nextUser)) {
targets.push_back(mmci);
}
}
@@ -587,9 +589,10 @@ static void hoistMarkMustCheckInsts(SILValue stackBox,
auto *undef = SILUndef::get(stackBox->getType(), *stackBox->getModule());
auto *mmci = builder.createMarkMustCheckInst(loc, undef, checkKind);
auto *mmci =
builder.createMarkUnresolvedNonCopyableValueInst(loc, undef, checkKind);
// Leave debug uses on the to-be-promoted box, but hoist all other uses to the
// new mark_must_check.
// new mark_unresolved_non_copyable_value.
replaceAllNonDebugUsesWith(stackBox, mmci);
mmci->setOperand(stackBox);
}
@@ -665,12 +668,13 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
// the address of the stack location.
replaceProjectBoxUsers(HeapBox, StackBox);
// Then hoist any mark_must_check [assignable_but_not_consumable] to the
// alloc_stack and convert them to [consumable_but_not_assignable]. This is
// because we are semantically converting from escaping semantics to
// non-escaping semantics.
hoistMarkMustCheckInsts(
StackBox, MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
// Then hoist any mark_unresolved_non_copyable_value
// [assignable_but_not_consumable] to the alloc_stack and convert them to
// [consumable_but_not_assignable]. This is because we are semantically
// converting from escaping semantics to non-escaping semantics.
hoistMarkUnresolvedNonCopyableValueInsts(
StackBox,
MarkUnresolvedNonCopyableValueInst::CheckKind::ConsumableAndAssignable);
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
&& "promoting multi-field box not implemented");
@@ -682,10 +686,12 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
for (auto LastRelease : FinalReleases) {
SILBuilderWithScope Builder(LastRelease);
if (!isa<DeallocBoxInst>(LastRelease)&& !Lowering.isTrivial()) {
// If we have a mark_must_check use of our stack box, we want to destroy
// that.
// If we have a mark_unresolved_non_copyable_value use of our stack box,
// we want to destroy that.
SILValue valueToDestroy = StackBox;
if (auto *mmci = StackBox->getSingleUserOfType<MarkMustCheckInst>()) {
if (auto *mmci =
StackBox
->getSingleUserOfType<MarkUnresolvedNonCopyableValueInst>()) {
valueToDestroy = mmci;
}
@@ -1059,10 +1065,12 @@ specializeApplySite(SILOptFunctionBuilder &FuncBuilder, ApplySite Apply,
if (F->getArgument(index)->getType().isBoxedNonCopyableType(*F)) {
auto boxType = F->getArgument(index)->getType().castTo<SILBoxType>();
bool isMutable = boxType->getLayout()->getFields()[0].isMutable();
auto checkKind =
isMutable ? MarkMustCheckInst::CheckKind::ConsumableAndAssignable
: MarkMustCheckInst::CheckKind::NoConsumeOrAssign;
hoistMarkMustCheckInsts(ClonedFn->getArgument(index), checkKind);
auto checkKind = isMutable ? MarkUnresolvedNonCopyableValueInst::
CheckKind::ConsumableAndAssignable
: MarkUnresolvedNonCopyableValueInst::
CheckKind::NoConsumeOrAssign;
hoistMarkUnresolvedNonCopyableValueInsts(ClonedFn->getArgument(index),
checkKind);
}
}
}