Skip to content

Commit b223e9d

Browse files
authored
Merge pull request swiftlang#39337 from xymus/delay-parsing-did-set-main
[Sema] Generate TRC for unparsed functions right before type-checking
2 parents bd7d212 + c8104aa commit b223e9d

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class SourceFile final : public FileUnit {
515515
/// null if the context hierarchy has not been built yet. Use
516516
/// TypeChecker::getOrBuildTypeRefinementContext() to get a built
517517
/// root of the hierarchy.
518-
TypeRefinementContext *getTypeRefinementContext();
518+
TypeRefinementContext *getTypeRefinementContext() const;
519519

520520
/// Set the root refinement context for the file.
521521
void setTypeRefinementContext(TypeRefinementContext *TRC);

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ SynthesizedFileUnit &SourceFile::getOrCreateSynthesizedFile() {
28922892
return *SynthesizedFile;
28932893
}
28942894

2895-
TypeRefinementContext *SourceFile::getTypeRefinementContext() {
2895+
TypeRefinementContext *SourceFile::getTypeRefinementContext() const {
28962896
return TRC;
28972897
}
28982898

lib/Sema/TypeCheckStmt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,10 @@ TypeCheckFunctionBodyRequest::evaluate(Evaluator &evaluator,
19551955
if (tyOpts.DebugTimeFunctionBodies || tyOpts.WarnLongFunctionBodies)
19561956
timer.emplace(AFD);
19571957

1958+
auto SF = AFD->getParentSourceFile();
1959+
if (SF)
1960+
TypeChecker::buildTypeRefinementContextHierarchyDelayed(*SF, AFD);
1961+
19581962
BraceStmt *body = AFD->getBody();
19591963
assert(body && "Expected body to type-check");
19601964

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ static void typeCheckDelayedFunctions(SourceFile &SF) {
252252
while (currentFunctionIdx < SF.DelayedFunctions.size()) {
253253
auto *AFD = SF.DelayedFunctions[currentFunctionIdx];
254254
assert(!AFD->getDeclContext()->isLocalContext());
255-
256-
TypeChecker::buildTypeRefinementContextHierarchyDelayed(SF, AFD);
257-
258255
(void) AFD->getTypecheckedBody();
259256
++currentFunctionIdx;
260257
}

test/Sema/availability_and_delayed_parsing.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ public func foo() { }
1717
// TRC-API: (root versions=[10.10.0,+Inf)
1818
// TRC-API: (decl versions=[10.12,+Inf) decl=foo()
1919

20+
struct S {
21+
fileprivate var actual: [String] = [] {
22+
didSet {
23+
if #available(macOS 10.15, *) {
24+
foo()
25+
}
26+
}
27+
}
28+
}
29+
// TRC-API: (condition_following_availability versions=[10.15,+Inf)
30+
// TRC-API: (if_then versions=[10.15,+Inf)
31+
2032
@inlinable public func inlinableFunc() {
2133
if #available(macOS 10.12, *) {
2234
foo()

0 commit comments

Comments
 (0)