Skip to content

[5.9] GenericSpecializer: fix a crash with -cross-module-optimization #64634

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
Mar 29, 2023

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Mar 27, 2023

If a thunk needs to be generated for a partial_apply specialization, but the specialization doesn't have a body, bail.

rdar://107165121

This is a cherry-pick of #64632

@eeckstein eeckstein requested a review from a team as a code owner March 27, 2023 10:22
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested a review from atrick March 27, 2023 10:23
@atrick
Copy link
Contributor

atrick commented Mar 27, 2023

Why is it bad to create a thunk for an external function? The included test case passes for me (without the corresponding fix on main), so I can't tell what the issue is or whether this fixes it.

If a thunk needs to be generated for a partial_apply specialization, but the specialization doesn't have a body, bail.

rdar://107165121
@eeckstein eeckstein force-pushed the fix-specializer-5.9 branch from 6147f22 to ab995c9 Compare March 28, 2023 12:09
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

Why is it bad to create a thunk for an external function?

It accesses the callee's function arguments (= arguments of the entry block) which are not there if it's an external function.

The included test case passes for me

Oops. I forgot to copy the last line from my isolated test file.
Good catch, thanks!
Should be fixed now

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

Fix for the test file on main: #64668

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

Looks good for 5.9

@@ -3119,6 +3119,12 @@ void swift::trySpecializeApplyOfGeneric(
<< SpecializedF->getLoweredFunctionType() << "\n");
NewFunctions.push_back(SpecializedF.getFunction());
}
if (replacePartialApplyWithoutReabstraction &&
SpecializedF.getFunction()->isExternalDeclaration()) {
// Cannot create a tunk without having the body of the function.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you create a main PR to fix the "tunk" typo, you could also explain that thunk creation needs to access the callee function's SIL arguments.

@eeckstein eeckstein merged commit d38e4e8 into swiftlang:release/5.9 Mar 29, 2023
@eeckstein eeckstein deleted the fix-specializer-5.9 branch March 29, 2023 12:05
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants