File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -871,6 +871,25 @@ void TypeChecker::buildTypeRefinementContextHierarchy(SourceFile &SF) {
871
871
}
872
872
}
873
873
874
+ void TypeChecker::buildTypeRefinementContextHierarchyDelayed (SourceFile &SF, AbstractFunctionDecl *AFD) {
875
+ // If there's no TRC for the file, we likely don't want this one either.
876
+ // RootTRC is not set when availability checking is disabled.
877
+ TypeRefinementContext *RootTRC = SF.getTypeRefinementContext ();
878
+ if (!RootTRC)
879
+ return ;
880
+
881
+ if (AFD->getBodyKind () != AbstractFunctionDecl::BodyKind::Unparsed)
882
+ return ;
883
+
884
+ // Parse the function body.
885
+ AFD->getBody (/* canSynthesize=*/ true );
886
+
887
+ // Build the refinement context for the function body.
888
+ ASTContext &Context = SF.getASTContext ();
889
+ TypeRefinementContextBuilder Builder (RootTRC, Context);
890
+ Builder.build (AFD);
891
+ }
892
+
874
893
TypeRefinementContext *
875
894
TypeChecker::getOrBuildTypeRefinementContext (SourceFile *SF) {
876
895
TypeRefinementContext *TRC = SF->getTypeRefinementContext ();
Original file line number Diff line number Diff line change @@ -256,6 +256,7 @@ static void typeCheckDelayedFunctions(SourceFile &SF) {
256
256
++currentFunctionIdx) {
257
257
auto *AFD = SF.DelayedFunctions [currentFunctionIdx];
258
258
assert (!AFD->getDeclContext ()->isLocalContext ());
259
+ TypeChecker::buildTypeRefinementContextHierarchyDelayed (SF, AFD);
259
260
(void )AFD->getTypecheckedBody ();
260
261
}
261
262
Original file line number Diff line number Diff line change @@ -958,6 +958,10 @@ AvailabilityContext overApproximateAvailabilityAtLocation(
958
958
// / Walk the AST to build the hierarchy of TypeRefinementContexts
959
959
void buildTypeRefinementContextHierarchy (SourceFile &SF);
960
960
961
+ // / Walk the AST to complete the hierarchy of TypeRefinementContexts for
962
+ // / the delayed function body of \p AFD.
963
+ void buildTypeRefinementContextHierarchyDelayed (SourceFile &SF, AbstractFunctionDecl *AFD);
964
+
961
965
// / Build the hierarchy of TypeRefinementContexts for the entire
962
966
// / source file, if it has not already been built. Returns the root
963
967
// / TypeRefinementContext for the source file.
Original file line number Diff line number Diff line change
1
+ /// Check for reliable availability checking in inlinable code even when
2
+ /// skipping some function bodies. rdar://82269657
3
+
4
+ // RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12
5
+ // RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-non-inlinable-function-bodies
6
+ // RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-non-inlinable-function-bodies-without-types
7
+ // RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-all-function-bodies
8
+
9
+ // REQUIRES: OS=macosx
10
+
11
+ @available ( macOS 10 . 14 , * )
12
+ public func foo( ) { }
13
+
14
+ @inlinable public func inlinableFunc( ) {
15
+ if #available( macOS 10 . 14 , * ) {
16
+ foo ( )
17
+ }
18
+ }
19
+
20
+ public func funcWithType( ) {
21
+ struct S { }
22
+ if #available( macOS 10 . 14 , * ) {
23
+ foo ( )
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments