@@ -91,44 +91,36 @@ static bool hasSingletonMetatype(CanType instanceType) {
9191CaptureKind TypeConverter::getDeclCaptureKind (CapturedValue capture,
9292 ResilienceExpansion expansion) {
9393 auto decl = capture.getDecl ();
94- if (auto *var = dyn_cast<VarDecl>(decl)) {
95- assert (var->hasStorage () &&
96- " should not have attempted to directly capture this variable" );
97-
98- // If this is a non-address-only stored 'let' constant, we can capture it
99- // by value. If it is address-only, then we can't load it, so capture it
100- // by its address (like a var) instead.
101- if (var->isImmutable () &&
102- (!SILModuleConventions (M).useLoweredAddresses () ||
103- !getTypeLowering (var->getType (), expansion).isAddressOnly ()))
104- return CaptureKind::Constant;
105-
106- // In-out parameters are captured by address.
107- if (var->isInOut ()) {
108- return CaptureKind::StorageAddress;
109- }
110-
111- // Reference storage types can appear in a capture list, which means
112- // we might allocate boxes to store the captures. However, those boxes
113- // have the same lifetime as the closure itself, so we must capture
114- // the box itself and not the payload, even if the closure is noescape,
115- // otherwise they will be destroyed when the closure is formed.
116- if (var->getType ()->is <ReferenceStorageType>()) {
117- return CaptureKind::Box;
118- }
119-
120- // If we're capturing into a non-escaping closure, we can generally just
121- // capture the address of the value as no-escape.
122- return capture.isNoEscape () ?
123- CaptureKind::StorageAddress : CaptureKind::Box;
94+ auto *var = cast<VarDecl>(decl);
95+ assert (var->hasStorage () &&
96+ " should not have attempted to directly capture this variable" );
97+
98+ // If this is a non-address-only stored 'let' constant, we can capture it
99+ // by value. If it is address-only, then we can't load it, so capture it
100+ // by its address (like a var) instead.
101+ if (var->isImmutable () &&
102+ (!SILModuleConventions (M).useLoweredAddresses () ||
103+ !getTypeLowering (var->getType (), expansion).isAddressOnly ()))
104+ return CaptureKind::Constant;
105+
106+ // In-out parameters are captured by address.
107+ if (var->isInOut ()) {
108+ return CaptureKind::StorageAddress;
124109 }
125-
126- // "Captured" local types require no context.
127- if (isa<TypeAliasDecl>(decl) || isa<GenericTypeParamDecl>(decl) ||
128- isa<AssociatedTypeDecl>(decl))
129- return CaptureKind::None;
130-
131- llvm_unreachable (" function-like captures should have been lowered away" );
110+
111+ // Reference storage types can appear in a capture list, which means
112+ // we might allocate boxes to store the captures. However, those boxes
113+ // have the same lifetime as the closure itself, so we must capture
114+ // the box itself and not the payload, even if the closure is noescape,
115+ // otherwise they will be destroyed when the closure is formed.
116+ if (var->getType ()->is <ReferenceStorageType>()) {
117+ return CaptureKind::Box;
118+ }
119+
120+ // If we're capturing into a non-escaping closure, we can generally just
121+ // capture the address of the value as no-escape.
122+ return capture.isNoEscape () ?
123+ CaptureKind::StorageAddress : CaptureKind::Box;
132124}
133125
134126using RecursiveProperties = TypeLowering::RecursiveProperties;
0 commit comments