Skip to content

AST/SILGen: Requestify function body skipping #68760

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 1 commit into from
Sep 29, 2023

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Sep 26, 2023

Function bodies are skipped during typechecking when one of the -experimental-skip-*-function-bodies flags is passed to the frontend. This was implemented by setting the "body kind" of an AbstractFunctionDecl during decl checking in TypeCheckDeclPrimary. This approach had a couple of issues:

  • It is incompatible with skipping function bodies during lazy typechecking, since the skipping is only evaluated during a phase of eager typechecking.
  • It prevents skipped function bodies from being parsed on-demand ("skipped" is a state that is distinct from "parsed", when they ought to be orthogonal). This needlessly prevented complete module interfaces from being emitted with -experimental-skip-all-function-bodies.

Storing the skipped status of a function separately from body kind and requestifying the determination of whether to skip a function solves these problems.

Resolves rdar://116020403

@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli force-pushed the requestify-function-body-skipping branch 2 times, most recently from 263a278 to 66d75f8 Compare September 26, 2023 18:34
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli tshortli force-pushed the requestify-function-body-skipping branch from 9b81054 to dbb21a0 Compare September 27, 2023 06:45
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli
Copy link
Contributor Author

@swift-ci please build toolchain macOS platform

@tshortli tshortli marked this pull request as ready for review September 27, 2023 06:48
@tshortli tshortli requested a review from xymus September 27, 2023 15:12
@ahoppen ahoppen removed their request for review September 27, 2023 17:07
@tshortli tshortli force-pushed the requestify-function-body-skipping branch from dbb21a0 to c22e046 Compare September 27, 2023 19:52
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

It looks good and surprisingly clean! (except for that last commit)

@tshortli tshortli force-pushed the requestify-function-body-skipping branch from 34d5efc to 9faa2e5 Compare September 28, 2023 17:59
@tshortli
Copy link
Contributor Author

It looks good and surprisingly clean! (except for that last commit)

Thanks! Yeah, I found one last minute case that I need to handle and I'm just about done with it. I will fix up the commit in a bit

@tshortli tshortli force-pushed the requestify-function-body-skipping branch 2 times, most recently from 77c7754 to b175d1b Compare September 28, 2023 21:16
Function bodies are skipped during typechecking when one of the
-experimental-skip-*-function-bodies flags is passed to the frontend. This was
implemented by setting the "body kind" of an `AbstractFunctionDecl` during decl
checking in `TypeCheckDeclPrimary`. This approach had a couple of issues:

- It is incompatible with skipping function bodies during lazy typechecking,
  since the skipping is only evaluated during a phase of eager typechecking.
- It prevents skipped function bodies from being parsed on-demand ("skipped" is
  a state that is distinct from "parsed", when they ought to be orthogonal).
  This needlessly prevented complete module interfaces from being emitted with
  -experimental-skip-all-function-bodies.

Storing the skipped status of a function separately from body kind and
requestifying the determination of whether to skip a function solves these
problems.

Resolves rdar://116020403
@tshortli tshortli force-pushed the requestify-function-body-skipping branch from b175d1b to 1d8fc10 Compare September 29, 2023 02:18
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test Linux

@tshortli tshortli merged commit a744d3e into swiftlang:main Sep 29, 2023
@tshortli tshortli deleted the requestify-function-body-skipping branch September 29, 2023 16:43
@xedin
Copy link
Contributor

xedin commented Sep 30, 2023

@xedin
Copy link
Contributor

xedin commented Sep 30, 2023

But somehow only in Debug configuration.

@tshortli
Copy link
Contributor Author

tshortli commented Oct 2, 2023

@xedin Thanks for the heads up, I'll take a look

@tshortli
Copy link
Contributor Author

tshortli commented Oct 2, 2023

@tshortli looks like this changes regressed one of the projects in the source compatibility suite

Fixed: #68917

hamishknight added a commit to hamishknight/swift that referenced this pull request Jul 23, 2024
The refactoring in swiftlang#68760 accidentally caused us to
start parsing skipped function bodies if they have
parameters, as the local discriminator request kicks
parsing through `getBody()`. Cherry-pick part of
47ff956 which was
never landed, ensuring we don't call `getBody` for
a skipped function body.

This is meant to be a minimal low-risk change that
fixes the issue in question, restoring the behavior
we had in 5.10. We ought to see if we can do a
better job of enforcing we never parse a skipped
body, as well as actually fixing the parser
skipping behavior for `#sourceLocation`, in a
follow-up.

rdar://131726797
hamishknight added a commit to hamishknight/swift that referenced this pull request Jul 23, 2024
The refactoring in swiftlang#68760 accidentally caused us to
start parsing skipped function bodies if they have
parameters, as the local discriminator request kicks
parsing through `getBody()`. Cherry-pick part of
47ff956 which was
never landed, ensuring we don't call `getBody` for
a skipped function body.

This is meant to be a minimal low-risk change that
fixes the issue in question, restoring the behavior
we had in 5.10. Fixing the parser skipping
behavior for `#sourceLocation` will be done in
a follow-up.

rdar://131726797
hamishknight added a commit to hamishknight/swift that referenced this pull request Jul 23, 2024
The refactoring in swiftlang#68760 accidentally caused us to
start parsing skipped function bodies if they have
parameters, as the local discriminator request kicks
parsing through `getBody()`. Cherry-pick part of
47ff956 which was
never landed, ensuring we don't call `getBody` for
a skipped function body.

This is meant to be a minimal low-risk change that
fixes the issue in question, restoring the behavior
we had in 5.10. Fixing the parser skipping
behavior for `#sourceLocation` will be done in
a follow-up. We also ought to see if there's a
better way we can enforce that skipped function
bodies don't end up getting parsed, for now I've
added a test.

rdar://131726797
hamishknight added a commit that referenced this pull request Jul 24, 2024
The refactoring in #68760 accidentally caused us to
start parsing skipped function bodies if they have
parameters, as the local discriminator request kicks
parsing through `getBody()`. Cherry-pick part of
47ff956 which was
never landed, ensuring we don't call `getBody` for
a skipped function body.

This is meant to be a minimal low-risk change that
fixes the issue in question, restoring the behavior
we had in 5.10. Fixing the parser skipping
behavior for `#sourceLocation` will be done in
a follow-up. We also ought to see if there's a
better way we can enforce that skipped function
bodies don't end up getting parsed, for now I've
added a test.

rdar://131726797
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.

4 participants