File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ class CapturedValue {
64
64
65
65
bool isDynamicSelfMetadata () const { return !Value.getPointer (); }
66
66
67
+ CapturedValue mergeFlags (CapturedValue cv) {
68
+ assert (Value.getPointer () == cv.Value .getPointer () &&
69
+ " merging flags on two different value decls" );
70
+ return CapturedValue (Value.getPointer (), getFlags () & cv.getFlags ());
71
+ }
72
+
67
73
ValueDecl *getDecl () const {
68
74
assert (Value.getPointer () && " dynamic Self metadata capture does not "
69
75
" have a value" );
Original file line number Diff line number Diff line change @@ -2144,16 +2144,36 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
2144
2144
goto capture_value;
2145
2145
}
2146
2146
}
2147
+
2148
+ if (!capturedVar->hasStorage ())
2149
+ continue ;
2150
+
2151
+ // We can always capture the storage in these cases.
2152
+ Type captureType = capturedVar->getType ();
2153
+ if (auto *metatypeType = captureType->getAs <MetatypeType>())
2154
+ captureType = metatypeType->getInstanceType ();
2155
+
2156
+ if (auto *selfType = captureType->getAs <DynamicSelfType>()) {
2157
+ captureType = selfType->getSelfType ();
2158
+
2159
+ // We're capturing a 'self' value with dynamic 'Self' type;
2160
+ // handle it specially.
2161
+ if (captureType->getClassOrBoundGenericClass ()) {
2162
+ if (selfCapture)
2163
+ selfCapture = selfCapture->mergeFlags (capture);
2164
+ else
2165
+ selfCapture = capture;
2166
+ continue ;
2167
+ }
2168
+ }
2147
2169
}
2148
2170
capture_value:
2149
2171
// Collect non-function captures.
2150
2172
ValueDecl *value = capture.getDecl ();
2151
2173
if (capturedValues.count (value)) {
2152
2174
for (auto it = captures.begin (); it != captures.end (); ++it) {
2153
2175
if (it->getDecl () == value) {
2154
- // The value is already in the list, it needs to have the logical
2155
- // AND of each flag of all uses.
2156
- *it = CapturedValue (value, it->getFlags () & capture.getFlags ());
2176
+ *it = it->mergeFlags (capture);
2157
2177
break ;
2158
2178
}
2159
2179
}
You can’t perform that action at this time.
0 commit comments