Skip to content

Commit 55ff73f

Browse files
committed
AST: Stronger assertions around CaptureInfo
1 parent 2f36a94 commit 55ff73f

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

include/swift/AST/CaptureInfo.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,19 @@ class CaptureInfo {
185185
}
186186

187187
bool isTrivial() const {
188+
assert(hasBeenComputed());
188189
return getCaptures().empty() && !hasGenericParamCaptures() &&
189190
!hasDynamicSelfCapture() && !hasOpaqueValueCapture();
190191
}
191192

192193
ArrayRef<CapturedValue> getCaptures() const {
193-
// FIXME: Ideally, everywhere that synthesizes a function should include
194-
// its capture info.
195-
if (!hasBeenComputed())
196-
return std::nullopt;
194+
assert(hasBeenComputed());
197195
return StorageAndFlags.getPointer()->getCaptures();
198196
}
199197

200198
/// \returns true if the function captures any generic type parameters.
201199
bool hasGenericParamCaptures() const {
202-
// FIXME: Ideally, everywhere that synthesizes a function should include
203-
// its capture info.
204-
if (!hasBeenComputed())
205-
return false;
200+
assert(hasBeenComputed());
206201
return StorageAndFlags.getInt().contains(Flags::HasGenericParamCaptures);
207202
}
208203

@@ -213,22 +208,17 @@ class CaptureInfo {
213208

214209
/// \returns the captured dynamic Self type, if any.
215210
DynamicSelfType *getDynamicSelfType() const {
216-
// FIXME: Ideally, everywhere that synthesizes a function should include
217-
// its capture info.
218-
if (!hasBeenComputed())
219-
return nullptr;
211+
assert(hasBeenComputed());
220212
return StorageAndFlags.getPointer()->getDynamicSelfType();
221213
}
222214

223215
bool hasOpaqueValueCapture() const {
216+
assert(hasBeenComputed());
224217
return getOpaqueValue() != nullptr;
225218
}
226219

227220
OpaqueValueExpr *getOpaqueValue() const {
228-
// FIXME: Ideally, everywhere that synthesizes a function should include
229-
// its capture info.
230-
if (!hasBeenComputed())
231-
return nullptr;
221+
assert(hasBeenComputed());
232222
return StorageAndFlags.getPointer()->getOpaqueValue();
233223
}
234224

include/swift/AST/Decl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7755,7 +7755,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
77557755
SourceRange getSignatureSourceRange() const;
77567756

77577757
CaptureInfo getCaptureInfo() const { return Captures; }
7758-
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }
7758+
7759+
void setCaptureInfo(CaptureInfo captures) {
7760+
assert(captures.hasBeenComputed());
7761+
Captures = captures;
7762+
}
77597763

77607764
/// Retrieve the Objective-C selector that names this method.
77617765
ObjCSelector getObjCSelector(DeclName preferredName = DeclName(),

include/swift/AST/Expr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3913,7 +3913,11 @@ class AbstractClosureExpr : public DeclContext, public Expr {
39133913
&foundIsolationCrossings);
39143914

39153915
CaptureInfo getCaptureInfo() const { return Captures; }
3916-
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }
3916+
3917+
void setCaptureInfo(CaptureInfo captures) {
3918+
assert(captures.hasBeenComputed());
3919+
Captures = captures;
3920+
}
39173921

39183922
/// Retrieve the parameters of this closure.
39193923
ParameterList *getParameters() { return parameterList; }

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8718,6 +8718,7 @@ void ParamDecl::setDefaultArgumentInitContext(Initializer *initContext) {
87188718

87198719
void ParamDecl::setDefaultArgumentCaptureInfo(CaptureInfo captures) {
87208720
assert(DefaultValueAndFlags.getPointer());
8721+
assert(captures.hasBeenComputed());
87218722
DefaultValueAndFlags.getPointer()->Captures = captures;
87228723
}
87238724

0 commit comments

Comments
 (0)