-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[SILGen]: fix a bug in isolated default argument handling #84664
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
slavapestov
merged 1 commit into
swiftlang:main
from
jamieQ:fix-iso-default-param-idx-bug
Oct 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,3 +161,66 @@ func useCallerIsolatedDefaultArg() async { | |
| // CHECK: // function_ref default argument 0 of | ||
| // CHECK-NEXT: [[GEN:%.*]] = function_ref @$s4test24callerIsolatedDefaultArg1xySi_tYaFfA_ : | ||
| // CHECK-NEXT: [[ARG:%.*]] = apply [[GEN]]() | ||
|
|
||
| // The following tests failed due to a book-keeping error when processing delayed | ||
| // isolated arguments in methods with: | ||
| // | ||
| // - a `self` parameter | ||
| // - delayed arguments that expanded to zero or greater than one value | ||
| // - a subsequent delayed argument | ||
|
Comment on lines
+169
to
+170
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably say 'default' rather than 'delayed' |
||
| // | ||
| // https://github.com/swiftlang/swift/issues/84647 | ||
|
|
||
| @MainActor | ||
| enum E { | ||
| static func tupleIsolatedDefaultArgStatic( | ||
| _: Int, | ||
| x: Int = main_actor_int_x(), | ||
| // need not be isolated defaults | ||
| tup: (Int, Int) = (1, 2), | ||
| i: Int = 0 | ||
| ) {} | ||
|
|
||
| static func voidIsolatedDefaultArgStatic( | ||
| _: Int, | ||
| v: Void = main_actor_void(), | ||
| // need not be isolated defaults | ||
| tup: (Int, Int) = (1, 2), | ||
| i: Int = 0 | ||
| ) {} | ||
| } | ||
|
|
||
| func testTupleIsolatedDefaultArgStatic() async { | ||
| await E.tupleIsolatedDefaultArgStatic(0) | ||
| } | ||
|
|
||
| func testVoidIsolatedDefaultArgStatic() async { | ||
| await E.voidIsolatedDefaultArgStatic(0) | ||
| } | ||
|
|
||
| @MainActor | ||
| final class Klazz { | ||
| func tupleIsolatedDefaultArgInstanceMethod( | ||
| _: Int, | ||
| x: Int = main_actor_int_x(), | ||
| // need not be isolated defaults | ||
| tup: (Int, Int) = (1, 2), | ||
| i: Int = 0 | ||
| ) {} | ||
|
|
||
| func voidIsolatedDefaultArgInstanceMethod( | ||
| _: Int, | ||
| v: Void = main_actor_void(), | ||
| // need not be isolated defaults | ||
| tup: (Int, Int) = (1, 2), | ||
| i: Int = 0 | ||
| ) {} | ||
| } | ||
|
|
||
| func testTupleIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async { | ||
| await klazz.tupleIsolatedDefaultArgInstanceMethod(0) | ||
| } | ||
|
|
||
| func testVoidIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async { | ||
| await klazz.voidIsolatedDefaultArgInstanceMethod(0) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on a cursory look at this bit of code, it seems suspicious to me that we'd only update
indexAdjustmentSitein this else branch. We were updating theindexAdjustmentbelow in this loop unconditionally, but seemingly didn't update theindexAdjustmentSiteat all, prior to this PR. Why is that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume that was an error/oversight as not updating it causes the added tests to hit assertion failures when they overwrite prior default arguments. IIUC the 'site args' stuff is perhaps a vestige from curried function call syntax. this is what Slava informed me of here:
so now i think there are only ever at most 2 'levels' of 'site args'. most of the existing test cases i saw for this isolated default args stuff appeared to use free functions and not instance methods (static or otherwise), so i'm not sure they exercised this case.