@@ -102,14 +102,16 @@ extension LifetimeDependentApply {
102102 }
103103}
104104
105- /// Replace the each dependent apply result with a chain of
106- /// mark_dependence [nonescaping] instructions; one for each base.
105+ /// If the result of this apply depends on the scope of one or more
106+ /// arguments, then insert a mark_dependence [unresolved] from the
107+ /// result on each argument so that the result is recognized as a
108+ /// dependent value within each scope.
107109private func insertDependencies( for apply: LifetimeDependentApply ,
108110 _ context: FunctionPassContext ) {
109111 precondition ( apply. applySite. results. count > 0 ,
110112 " a lifetime-dependent instruction must have at least one result " )
111113
112- let bases = recursivelyFindDependenceBases ( of: apply, context)
114+ let bases = findDependenceBases ( of: apply, context)
113115 let builder = Builder ( after: apply. applySite, context)
114116 for dependentValue in apply. applySite. resultOrYields {
115117 insertMarkDependencies ( value: dependentValue, initializer: nil ,
@@ -138,6 +140,31 @@ private func insertDependencies(for apply: LifetimeDependentApply,
138140 }
139141}
140142
143+ private func findDependenceBases( of apply: LifetimeDependentApply ,
144+ _ context: FunctionPassContext )
145+ -> [ Value ] {
146+ log ( " Creating dependencies for \( apply. applySite) " )
147+ var bases : [ Value ] = [ ]
148+ for lifetimeArg in apply. getLifetimeArguments ( ) {
149+ switch lifetimeArg. convention {
150+ case . inherit:
151+ continue
152+ case . scope:
153+ // Create a new dependence on the apply's access to the argument.
154+ for varIntoducer in gatherVariableIntroducers ( for: lifetimeArg. value,
155+ context) {
156+ if let scope =
157+ LifetimeDependence . Scope ( base: varIntoducer, context) {
158+ log ( " Scoped lifetime from \( lifetimeArg. value) " )
159+ log ( " scope: \( scope) " )
160+ bases. append ( scope. parentValue)
161+ }
162+ }
163+ }
164+ }
165+ return bases
166+ }
167+
141168private func insertMarkDependencies( value: Value , initializer: Instruction ? ,
142169 bases: [ Value ] , builder: Builder ,
143170 _ context: FunctionPassContext ) {
@@ -155,6 +182,7 @@ private func insertMarkDependencies(value: Value, initializer: Instruction?,
155182 }
156183}
157184
185+ /*
158186/// Return base values that this return value depends on.
159187///
160188/// For lifetime copies, walk up the dependence chain to find the
@@ -212,3 +240,4 @@ private func recursivelyUpdate(scope: LifetimeDependence.Scope,
212240 }
213241 return scope
214242}
243+ */
0 commit comments