Skip to content

Commit bd7d3ec

Browse files
committed
LifetimeDependentInsertion: assert on non-inout parameter dependency
The will be supported in a future commit that adds mark_dependence_addr.
1 parent dc41b21 commit bd7d3ec

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ private func insertParameterDependencies(apply: LifetimeDependentApply, target:
272272

273273
sources.initializeBases(context)
274274

275+
assert(target.value.type.isAddress,
276+
"lifetime-dependent parameter must be 'inout'")
277+
275278
Builder.insert(after: apply.applySite, context) {
276279
insertMarkDependencies(value: target.value, initializer: nil, bases: sources.bases, builder: $0, context)
277280
}
@@ -285,14 +288,14 @@ private func insertMarkDependencies(value: Value, initializer: Instruction?,
285288
let markDep = builder.createMarkDependence(
286289
value: currentValue, base: base, kind: .Unresolved)
287290

288-
// Address dependencies cannot be represented as SSA values, so it does not make sense to replace any uses of the
289-
// dependent address.
290-
//
291-
// TODO: either (1) insert a separate mark_dependence_addr instruction with no return value, or (2) perform data
292-
// flow to replace all reachable address uses, and if any aren't dominated by base, then insert an extra
293-
// escaping mark_dependence at this apply site that directly uses the mark_dependence [nonescaping] to force
294-
// diagnostics to fail.
295-
if !value.type.isAddress {
291+
if value.type.isAddress {
292+
// Address dependencies cannot be represented as SSA values, so it does not make sense to replace any uses of the
293+
// dependent address.
294+
//
295+
// TODO: insert a separate mark_dependence_addr instruction with no return value and do not update currentValue.
296+
} else {
297+
// TODO: implement non-inout parameter dependencies. This assumes that currentValue is the apply immediately
298+
// preceeding the mark_dependence.
296299
let uses = currentValue.uses.lazy.filter {
297300
if $0.isScopeEndingUse {
298301
return false

test/SILOptimizer/lifetime_dependence/semantics.swift

+9
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,12 @@ func testBorrowedAddressableIntReturn(arg: Holder) -> Span<Int> {
600600
} // todo-note {{this use causes the lifetime-dependent value to escape}}
601601

602602
*/
603+
604+
605+
// =============================================================================
606+
// Parameter dependencies
607+
// =============================================================================
608+
609+
// rdar://146401190 ([nonescapable] implement non-inout parameter dependencies)
610+
@lifetime(span: borrow holder)
611+
func testParameterDep(holder: Holder, span: Span<Int>) {} // expected-error {{lifetime-dependent parameter must be 'inout'}}

0 commit comments

Comments
 (0)