Skip to content

Commit 402bc34

Browse files
authored
Merge pull request swiftlang#39725 from nate-chandler/lexical_lifetimes/disable-destroy-hoisting-with-flag
2 parents 6cbaee4 + 339ef00 commit 402bc34

File tree

10 files changed

+15
-16
lines changed

10 files changed

+15
-16
lines changed

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class SILOptions {
4444
/// Remove all runtime assertions during optimizations.
4545
bool RemoveRuntimeAsserts = false;
4646

47+
/// Enable experimental support for emitting defined borrow scopes.
48+
bool EnableExperimentalLexicalLifetimes = false;
49+
4750
/// Force-run SIL copy propagation to shorten object lifetime in whatever
4851
/// optimization pipeline is currently used.
4952
/// When this is 'false' the pipeline has default behavior.

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ namespace swift {
303303
/// Enable experimental concurrency model.
304304
bool EnableExperimentalConcurrency = false;
305305

306-
/// Enable experimental support for emitting defined borrow scopes.
307-
bool EnableExperimentalLexicalLifetimes = false;
308-
309306
/// Enable experimental support for named opaque result types, e.g.
310307
/// `func f() -> <T> T`.
311308
bool EnableExperimentalNamedOpaqueTypes = false;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
434434
Opts.EnableExperimentalConcurrency |=
435435
Args.hasArg(OPT_enable_experimental_concurrency);
436436

437-
Opts.EnableExperimentalLexicalLifetimes |=
438-
Args.hasArg(OPT_enable_experimental_lexical_lifetimes);
439-
440437
Opts.EnableExperimentalNamedOpaqueTypes |=
441438
Args.hasArg(OPT_enable_experimental_named_opaque_types);
442439

@@ -1400,6 +1397,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
14001397
// -Ounchecked might also set removal of runtime asserts (cond_fail).
14011398
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);
14021399

1400+
Opts.EnableExperimentalLexicalLifetimes |=
1401+
Args.hasArg(OPT_enable_experimental_lexical_lifetimes);
14031402
Opts.EnableCopyPropagation |= Args.hasArg(OPT_enable_copy_propagation);
14041403
Opts.DisableCopyPropagation |= Args.hasArg(OPT_disable_copy_propagation);
14051404
Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);

lib/SILGen/SILGenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class DestroyLocalVariable : public Cleanup {
255255
void emit(SILGenFunction &SGF, CleanupLocation l,
256256
ForUnwind_t forUnwind) override {
257257
SILValue val = SGF.VarLocs[Var].value;
258-
if (SGF.getASTContext().LangOpts.EnableExperimentalLexicalLifetimes &&
258+
if (SGF.getASTContext().SILOpts.EnableExperimentalLexicalLifetimes &&
259259
val->getOwnershipKind() != OwnershipKind::None)
260260
SGF.B.createEndBorrow(l, val);
261261
SGF.destroyLocalVariable(l, Var);
@@ -526,7 +526,7 @@ class LetValueInitialization : public Initialization {
526526
address = value;
527527
SILLocation PrologueLoc(vd);
528528

529-
if (SGF.getASTContext().LangOpts.EnableExperimentalLexicalLifetimes &&
529+
if (SGF.getASTContext().SILOpts.EnableExperimentalLexicalLifetimes &&
530530
value->getOwnershipKind() != OwnershipKind::None)
531531
value = SILValue(
532532
SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ true));
@@ -1717,7 +1717,7 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
17171717
SILValue Val = loc.value;
17181718
if (!Val->getType().isAddress()) {
17191719
SILValue valueToBeDestroyed;
1720-
if (getASTContext().LangOpts.EnableExperimentalLexicalLifetimes &&
1720+
if (getASTContext().SILOpts.EnableExperimentalLexicalLifetimes &&
17211721
Val->getOwnershipKind() != OwnershipKind::None) {
17221722
auto *inst = cast<BeginBorrowInst>(Val.getDefiningInstruction());
17231723
valueToBeDestroyed = inst->getOperand();

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ struct ArgumentInitHelper {
254254
SILValue value = argrv.getValue();
255255
SILDebugVariable varinfo(pd->isImmutable(), ArgNo);
256256
if (!argrv.getType().isAddress()) {
257-
if (SGF.getASTContext().LangOpts.EnableExperimentalLexicalLifetimes &&
257+
if (SGF.getASTContext().SILOpts.EnableExperimentalLexicalLifetimes &&
258258
value->getOwnershipKind() == OwnershipKind::Owned) {
259259
value =
260260
SILValue(SGF.B.createBeginBorrow(loc, value, /*isLexical*/ true));

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
138138
P.addSILSkippingChecker();
139139
#endif
140140

141-
if (Options.shouldOptimize()) {
141+
if (Options.shouldOptimize() && !Options.EnableExperimentalLexicalLifetimes) {
142142
P.addDestroyHoisting();
143143
}
144144
P.addMandatoryInlining();

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
536536
bool isLexical = ABI->getFunction()
537537
->getModule()
538538
.getASTContext()
539-
.LangOpts.EnableExperimentalLexicalLifetimes;
539+
.SILOpts.EnableExperimentalLexicalLifetimes;
540540
auto *ASI = Builder.createAllocStack(
541541
ABI->getLoc(),
542542
getSILBoxFieldType(TypeExpansionContext(*ABI->getFunction()),

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static bool shouldAddLexicalLifetime(AllocStackInst *asi) {
316316
asi->getFunction()
317317
->getModule()
318318
.getASTContext()
319-
.LangOpts.EnableExperimentalLexicalLifetimes &&
319+
.SILOpts.EnableExperimentalLexicalLifetimes &&
320320
asi->isLexical() &&
321321
!asi->getElementType().isTrivial(*asi->getFunction());
322322
}

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ SILValue SILInlineCloner::borrowFunctionArgument(SILValue callArg,
600600
auto enableLexicalLifetimes = Apply.getFunction()
601601
->getModule()
602602
.getASTContext()
603-
.LangOpts.EnableExperimentalLexicalLifetimes;
603+
.SILOpts.EnableExperimentalLexicalLifetimes;
604604
if (!AI.getFunction()->hasOwnership() ||
605605
(callArg.getOwnershipKind() != OwnershipKind::Owned &&
606606
!enableLexicalLifetimes)) {

tools/sil-opt/SILOpt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ int main(int argc, char **argv) {
424424
EnableExperimentalConcurrency;
425425
Invocation.getLangOptions().EnableExperimentalDistributed =
426426
EnableExperimentalDistributed;
427-
Invocation.getLangOptions().EnableExperimentalLexicalLifetimes =
428-
EnableExperimentalLexicalLifetimes;
429427

430428
Invocation.getLangOptions().EnableObjCInterop =
431429
EnableObjCInterop ? true :
@@ -513,6 +511,8 @@ int main(int argc, char **argv) {
513511
SILOpts.EnableOSSAModules = EnableOSSAModules;
514512
SILOpts.EnableCopyPropagation = EnableCopyPropagation;
515513
SILOpts.DisableCopyPropagation = DisableCopyPropagation;
514+
SILOpts.EnableExperimentalLexicalLifetimes =
515+
EnableExperimentalLexicalLifetimes;
516516

517517
serialization::ExtendedValidationInfo extendedInfo;
518518
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =

0 commit comments

Comments
 (0)