Skip to content

Skip setting type expansion context for captures of skipped functions #70835

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
Jan 19, 2024

Conversation

jkshtj
Copy link
Contributor

@jkshtj jkshtj commented Jan 11, 2024

Type-checking and SILGen for non-inlinable functions is skipped in the presence of -experimental-skip-non-inlinable-function-bodies and -experimental-skip-non-inlinable-function-bodies-without-types flags.

Such functions may be top-level and may contain captures (if they appear after a guard statement), for which we were setting the type expansion context during SILGen. Setting type expansion context however, relied on the capture info being computed -- which was never happening because of the abovementioned flags.

Changes in this commit make setting type expansion context, for captures, conditional on a flag that ensures that the function has already been typechecked.

Fixes #57646

@jkshtj
Copy link
Contributor Author

jkshtj commented Jan 11, 2024

@BradLarson could you please kick off swift-ci?

@slavapestov
Copy link
Contributor

This means that such functions should be typechecked and SILGen-ed in the presence of -experimental-skip-non-inlinable-function-bodies and -experimental-skip-non-inlinable-function-bodies-without-types flags.

I’m not sure I understand why. These functions cannot be referenced so why do we need their captures when skipping bodies?

@jkshtj
Copy link
Contributor Author

jkshtj commented Jan 11, 2024

This means that such functions should be typechecked and SILGen-ed in the presence of -experimental-skip-non-inlinable-function-bodies and -experimental-skip-non-inlinable-function-bodies-without-types flags.

I’m not sure I understand why. These functions cannot be referenced so why do we need their captures when skipping bodies?

You're right. I was initially going off of the function SILGen invariants you established in this commit. But if a function's body is never going to be emitted then I don't see any reason why we would need their captures.

One incorrect assumption that I made initially was that this capture info is represented in the "function signatures" on top of a SIL file. But, those are swift signatures.

I think the fix should be to simply not set the type expansion context for captures here based on whether or not the function body is going to be emitted?

Type-checking and SILGen for non-inlinable functions is skipped in the
presence of `-experimental-skip-non-inlinable-function-bodies` and
`-experimental-skip-non-inlinable-function-bodies-without-types` flags.

Such functions may be top-level and may contain captures (if they appear
after a `guard` statement), for which we were setting the type expansion
context during SILGen. Setting type expansion context however, relied on
the capture info being computed -- which was never happening because of
the abovementioned flags.

Changes in this commit make setting type expansion context, for
captures, conditional on a flag that ensures that the function has already
been typechecked.

Fixes swiftlang#57646
@jkshtj jkshtj changed the title Ensures top-level functions after guard statements are typechecked and SILGen-ed unless skipping all function bodies Skip setting type expansion context for captures of skipped functions Jan 11, 2024
@jkshtj
Copy link
Contributor Author

jkshtj commented Jan 12, 2024

@slavapestov could you please take a look at this?

@BradLarson
Copy link
Contributor

@swift-ci Please test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Nice!

@jkshtj
Copy link
Contributor Author

jkshtj commented Jan 19, 2024

@slavapestov Is there anything else needed to merge this? Or are we waiting on more approvals?

@slavapestov slavapestov merged commit be35394 into swiftlang:main Jan 19, 2024
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.

[SR-15324] Function with default value after guard statement triggers captureInfo.hasBeenComputed() assertion failure
3 participants