Skip to content

Commit 9062271

Browse files
committed
SILGen: Skip SIL verification and optimization if errors were emitted.
In lazy typechecking mode, errors in the program may only be discovered during SILGen, which can leave the SIL in a bad state for subsequent stages of compilation. If errors were detected, skip SIL verification and optimization to prevent knock-on failures. Partially reverts swiftlang#75428, which included a more targeted fix for one of the possible knock-on effects of bad SIL coming out of SILGen. Resolves rdar://132107752.
1 parent 06604a0 commit 9062271

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ extension LifetimeDependence {
193193
if arg.isIndirectResult {
194194
return nil
195195
}
196-
guard let scope = Scope(base: arg, context) else {
197-
// Ignore invalid argument types.
198-
return nil
199-
}
200-
self.scope = scope
196+
self.scope = Scope(base: arg, context)!
201197
self.dependentValue = arg
202198
}
203199

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,13 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
16431643
return writeSIL(*SM, PSPs, Instance, Invocation.getSILOptions());
16441644
}
16451645

1646+
// In lazy typechecking mode, SILGen may have triggered requests which
1647+
// resulted in errors. We don't want to proceed with optimization or
1648+
// serialization if there were errors since the SIL may be incomplete or
1649+
// invalid.
1650+
if (Context.TypeCheckerOpts.EnableLazyTypecheck && Context.hadError())
1651+
return true;
1652+
16461653
if (Action == FrontendOptions::ActionType::EmitSIBGen) {
16471654
serializeSIB(SM.get(), PSPs, Context, MSF);
16481655
return Context.hadError();

lib/SILGen/SILGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ SILGenModule::~SILGenModule() {
9595
f.setLinkage(SILLinkage::PublicExternal);
9696
}
9797

98+
// Skip verification if a lazy typechecking error occurred.
99+
auto &ctx = getASTContext();
100+
if (ctx.TypeCheckerOpts.EnableLazyTypecheck && ctx.hadError())
101+
return;
102+
98103
M.verifyIncompleteOSSA();
99104
}
100105

0 commit comments

Comments
 (0)