Skip to content

Commit 6b776f5

Browse files
committed
Move lifetime diagnostics after consume operator diagnostics.
This fixes bugs when ~Escapable types depended on values that are passed to 'consume'. The consume operator diagnostics are broken when dependent values are present. This sidesteps the problem for lifetime dependence. And we generally want to diagnose lifetime dependence after all move-only related diagnostics. That way, using a dependent value after consume provides a more informative diagnostic about the dependent value and its scope.
1 parent f81f7f9 commit 6b776f5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ bool CheckerLivenessInfo::compute() {
155155
}
156156
}
157157
}
158+
// FIXME: this ignores all other forms of Borrow ownership, such as
159+
// partial_apply [onstack] and mark_dependence [nonescaping].
158160
break;
159161
}
160162
case OperandOwnership::GuaranteedForwarding:

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,6 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
171171
// Check noImplicitCopy and move only types for objects and addresses.
172172
P.addMoveOnlyChecker();
173173

174-
// Check ~Escapable.
175-
if (P.getOptions().EnableLifetimeDependenceDiagnostics) {
176-
P.addLifetimeDependenceDiagnostics();
177-
}
178-
if (EnableDeinitDevirtualizer)
179-
P.addDeinitDevirtualizer();
180-
181174
// FIXME: rdar://122701694 (`consuming` keyword causes verification error on
182175
// invalid SIL types)
183176
//
@@ -189,6 +182,19 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
189182
// No uses after consume operator of copyable value.
190183
P.addConsumeOperatorCopyableValuesChecker();
191184

185+
// Check ~Escapable.
186+
if (P.getOptions().EnableLifetimeDependenceDiagnostics) {
187+
P.addLifetimeDependenceDiagnostics();
188+
}
189+
190+
// Devirtualize deinits early if requested.
191+
//
192+
// FIXME: why is DeinitDevirtualizer in the middle of the mandatory pipeline,
193+
// and what passes/compilation modes depend on it? This pass is never executed
194+
// or tested without '-Xllvm enable-deinit-devirtualizer'.
195+
if (EnableDeinitDevirtualizer)
196+
P.addDeinitDevirtualizer();
197+
192198
// As a temporary measure, we also eliminate move only for non-trivial types
193199
// until we can audit the later part of the pipeline. Eventually, this should
194200
// occur before IRGen.

0 commit comments

Comments
 (0)