Skip to content

[Sema] Build TRC for delayed functions bodies #39064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2021
Merged

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Aug 26, 2021

The compiler builds the full TypeRefinementContext of a source file before parsing delayed function bodies. This can lead to availability checking errors in delayed function bodies as the TRCs are incomplete.

Make sure we complete the TRC of each delayed function before type-checking them.

rdar://82269657

We used to build the full TypeRefinementContext of a source file before
parsing delayed function bodies. This can lead to availability checking
errors in delayed function bodies as the TRCs are incomplete.

Complete the TRC of each delayed function before type-checking them to
fix this.

rdar://82269657
@xymus xymus requested a review from bnbarham August 26, 2021 20:38
@xymus
Copy link
Contributor Author

xymus commented Aug 26, 2021

@swift-ci Please smoke test

Comment on lines 4 to 7
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-non-inlinable-function-bodies
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-non-inlinable-function-bodies-without-types
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target x86_64-apple-macos10.12 -experimental-skip-all-function-bodies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth checking the dumped contexts to make sure they aren't built in the skip-all (for all) and skip-non-inlinable (for funcWithType) cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not, it's a somewhat reliable way to detect if those functions were type-checked or not. I've added this check as a new commit!

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to remove TypeChecker::getOrBuildTypeRefinementContext as well? There's only a single call in TypeChecker::overApproximateAvailabilityAtLocation and I believe that one can just assume it's built. getOrBuild seems somewhat unsafe since it doesn't handle delayed functions.

Would the refinement context for a delayed Decl ever be needed while typechecking a different Decl? Ie. should we ensure all contexts have been built prior to doing any typechecking?

LGTM otherwise

@xymus
Copy link
Contributor Author

xymus commented Aug 27, 2021

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Aug 27, 2021

I think getOrBuildTypeRefinementContext is safe-ish, it would build the TRC for what is currently parsed and afterwards buildTypeRefinementContextHierarchyDelayed would start building the TRC for delayed bodies as there would now be a file-level TRC root. I presume it's there for when availability checking is disabled, that's pretty rare (🤞) and not really supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants