Skip to content

Commit f0aba4d

Browse files
authored
Merge pull request #73215 from slavapestov/capture-fix-and-cleanup
Fix regression from CaptureInfoRequest
2 parents 3fe8b71 + 95af3be commit f0aba4d

File tree

4 files changed

+51
-75
lines changed

4 files changed

+51
-75
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ class AnyFunctionRef {
7575
return TheFunction.get<AbstractClosureExpr *>()->getCaptureInfo();
7676
}
7777

78-
void setCaptureInfo(CaptureInfo captures) const {
79-
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
80-
AFD->setCaptureInfo(captures);
81-
return;
82-
}
83-
TheFunction.get<AbstractClosureExpr *>()->setCaptureInfo(captures);
84-
}
8578

8679
bool hasType() const {
8780
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())

lib/AST/PackConformance.cpp

Lines changed: 31 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -172,66 +172,6 @@ ProtocolConformanceRef PackConformance::subst(SubstitutionMap subMap,
172172
return subst(IFS);
173173
}
174174

175-
namespace {
176-
177-
struct PackConformanceExpander {
178-
InFlightSubstitution &IFS;
179-
ArrayRef<ProtocolConformanceRef> origConformances;
180-
181-
public:
182-
// Results built up by the expansion.
183-
SmallVector<Type, 4> substElementTypes;
184-
SmallVector<ProtocolConformanceRef, 4> substConformances;
185-
186-
PackConformanceExpander(InFlightSubstitution &IFS,
187-
ArrayRef<ProtocolConformanceRef> origConformances)
188-
: IFS(IFS), origConformances(origConformances) {}
189-
190-
private:
191-
/// Substitute a scalar element of the original pack.
192-
void substScalar(Type origElementType,
193-
ProtocolConformanceRef origConformance) {
194-
auto substElementType = origElementType.subst(IFS);
195-
auto substConformance = origConformance.subst(origElementType, IFS);
196-
197-
substElementTypes.push_back(substElementType);
198-
substConformances.push_back(substConformance);
199-
}
200-
201-
/// Substitute and expand an expansion element of the original pack.
202-
void substExpansion(PackExpansionType *origExpansionType,
203-
ProtocolConformanceRef origConformance) {
204-
IFS.expandPackExpansionType(origExpansionType,
205-
[&](Type substComponentType) {
206-
auto origPatternType = origExpansionType->getPatternType();
207-
208-
// Just substitute the conformance. We don't directly represent
209-
// pack expansion conformances here; it's sort of implicit in the
210-
// corresponding pack element type.
211-
auto substConformance = origConformance.subst(origPatternType, IFS);
212-
213-
substElementTypes.push_back(substComponentType);
214-
substConformances.push_back(substConformance);
215-
});
216-
}
217-
218-
public:
219-
void expand(PackType *origPackType) {
220-
assert(origPackType->getNumElements() == origConformances.size());
221-
222-
for (auto i : range(origPackType->getNumElements())) {
223-
auto origElementType = origPackType->getElementType(i);
224-
if (auto *origExpansion = origElementType->getAs<PackExpansionType>()) {
225-
substExpansion(origExpansion, origConformances[i]);
226-
} else {
227-
substScalar(origElementType, origConformances[i]);
228-
}
229-
}
230-
}
231-
};
232-
233-
} // end anonymous namespace
234-
235175
ProtocolConformanceRef PackConformance::subst(TypeSubstitutionFn subs,
236176
LookupConformanceFn conformances,
237177
SubstOptions options) const {
@@ -241,14 +181,41 @@ ProtocolConformanceRef PackConformance::subst(TypeSubstitutionFn subs,
241181

242182
ProtocolConformanceRef
243183
PackConformance::subst(InFlightSubstitution &IFS) const {
244-
PackConformanceExpander expander(IFS, getPatternConformances());
245-
expander.expand(ConformingType);
184+
// Results built up by the expansion.
185+
SmallVector<Type, 4> substElementTypes;
186+
SmallVector<ProtocolConformanceRef, 4> substConformances;
187+
188+
auto origConformances = getPatternConformances();
189+
assert(ConformingType->getNumElements() == origConformances.size());
190+
191+
for (auto i : range(ConformingType->getNumElements())) {
192+
auto origElementType = ConformingType->getElementType(i);
193+
if (auto *origExpansion = origElementType->getAs<PackExpansionType>()) {
194+
// Substitute and expand an expansion element of the original pack.
195+
IFS.expandPackExpansionType(origExpansion,
196+
[&](Type substComponentType) {
197+
substElementTypes.push_back(substComponentType);
198+
199+
// Just substitute the conformance. We don't directly represent
200+
// pack expansion conformances here; it's sort of implicit in the
201+
// corresponding pack element type.
202+
substConformances.push_back(
203+
origConformances[i].subst(origExpansion->getPatternType(), IFS));
204+
});
205+
} else {
206+
// Substitute a scalar element of the original pack.
207+
substElementTypes.push_back(origElementType.subst(IFS));
208+
209+
substConformances.push_back(
210+
origConformances[i].subst(origElementType, IFS));
211+
}
212+
}
246213

247214
auto &ctx = Protocol->getASTContext();
248-
auto *substConformingType = PackType::get(ctx, expander.substElementTypes);
215+
auto *substConformingType = PackType::get(ctx, substElementTypes);
249216

250217
auto substConformance = PackConformance::get(substConformingType, Protocol,
251-
expander.substConformances);
218+
substConformances);
252219
return ProtocolConformanceRef(substConformance);
253220
}
254221

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,16 @@ class FindCapturedVars : public ASTWalker {
627627

628628
CaptureInfo CaptureInfoRequest::evaluate(Evaluator &evaluator,
629629
AbstractFunctionDecl *AFD) const {
630-
BraceStmt *body = AFD->getTypecheckedBody();
631-
632630
auto type = AFD->getInterfaceType();
633-
if (type->is<ErrorType>() || body == nullptr)
631+
if (type->is<ErrorType>())
634632
return CaptureInfo::empty();
635633

636634
bool isNoEscape = type->castTo<AnyFunctionType>()->isNoEscape();
637635
FindCapturedVars finder(AFD->getLoc(), AFD, isNoEscape,
638636
AFD->isObjC(), AFD->isGeneric());
639-
body->walk(finder);
637+
638+
if (auto *body = AFD->getTypecheckedBody())
639+
body->walk(finder);
640640

641641
if (!AFD->isObjC()) {
642642
finder.checkType(type, AFD->getLoc());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types %s -emit-module-path %t/skip_local_function_bodies.swiftmodule
3+
4+
public protocol P {
5+
init()
6+
}
7+
8+
extension P {
9+
public func f() {
10+
typealias T = Self
11+
12+
func g(_ x: T) {}
13+
g(self)
14+
}
15+
}
16+

0 commit comments

Comments
 (0)