@@ -102,14 +102,16 @@ extension LifetimeDependentApply {
102
102
}
103
103
}
104
104
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.
107
109
private func insertDependencies( for apply: LifetimeDependentApply ,
108
110
_ context: FunctionPassContext ) {
109
111
precondition ( apply. applySite. results. count > 0 ,
110
112
" a lifetime-dependent instruction must have at least one result " )
111
113
112
- let bases = recursivelyFindDependenceBases ( of: apply, context)
114
+ let bases = findDependenceBases ( of: apply, context)
113
115
let builder = Builder ( after: apply. applySite, context)
114
116
for dependentValue in apply. applySite. resultOrYields {
115
117
insertMarkDependencies ( value: dependentValue, initializer: nil ,
@@ -138,6 +140,31 @@ private func insertDependencies(for apply: LifetimeDependentApply,
138
140
}
139
141
}
140
142
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
+
141
168
private func insertMarkDependencies( value: Value , initializer: Instruction ? ,
142
169
bases: [ Value ] , builder: Builder ,
143
170
_ context: FunctionPassContext ) {
@@ -155,6 +182,7 @@ private func insertMarkDependencies(value: Value, initializer: Instruction?,
155
182
}
156
183
}
157
184
185
+ /*
158
186
/// Return base values that this return value depends on.
159
187
///
160
188
/// For lifetime copies, walk up the dependence chain to find the
@@ -212,3 +240,4 @@ private func recursivelyUpdate(scope: LifetimeDependence.Scope,
212
240
}
213
241
return scope
214
242
}
243
+ */
0 commit comments