Skip to content

Conversation

@jamieQ
Copy link
Contributor

@jamieQ jamieQ commented Oct 3, 2025

Changes in #81370 addressed a number of issues with isolated default argument handling. However, there seemed to still be a problem when dealing with isolated default arguments of instance/static methods under the following conditions:

  • The method contained an isolated default parameter
  • The method contained a defaulted parameter that expanded to 0 or >1 values
  • Said parameter was followed by another defaulted parameter

The attempted fix here was to adjust the isolated default argument iteration bookkeeping.

resolves: #84647

Changes in swiftlang#81370 addressed a
number of issues with isolated default argument handling. However, there
seemed to still be a problem when dealing with isolated default
arguments of instance/static methods under the following conditions:

- The method contained an isolated default parameter
- The method contained a defaulted parameter that expanded to 0 or >1
  values
- Said parameter was followed by another defaulted parameter

The attempted fix here was to adjust the isolated default argument
iteration bookkeeping.
@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 3, 2025

@swift-ci please smoke test

@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 3, 2025

@rjmccall if you get a chance to take a look at this proposed fix, i'd appreciate your insights on:

  1. if the proposed solution seems appropriate
  2. anything else you think would be valuable to add to the test cases (currently they just ensure the previous crasher/assertion failure no longer occurs)

@jamieQ jamieQ marked this pull request as ready for review October 3, 2025 19:18
@jamieQ jamieQ requested review from jckarter and kavon as code owners October 3, 2025 19:18
Comment on lines +169 to +170
// - delayed arguments that expanded to zero or greater than one value
// - a subsequent delayed argument
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should probably say 'default' rather than 'delayed'

@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 10, 2025

ping @rjmccall / @kavon / @jckarter

@@ -3203,6 +3202,7 @@ static void emitDelayedArguments(SILGenFunction &SGF,
// Otherwise, reset the current index adjustment.
} else {
indexAdjustment = 0;
indexAdjustmentSite = site;
Copy link
Member

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 indexAdjustmentSite in this else branch. We were updating the indexAdjustment below in this loop unconditionally, but seemingly didn't update the indexAdjustmentSite at all, prior to this PR. Why is that?

Copy link
Contributor Author

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:

SILGen has some vestigial support for the old curried function call syntax that was removed in Swift 3. We still use it to represent the self parameter, so a method has type (Self) -> (Args...) -> Result in the AST, but in SIL it's (Args..., Self) -> Result. There are two "call sites" for a single "call", basically. But now it only ever comes up in this case.

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.

@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 27, 2025

@rjmccall / @kavon / @jckarter – any thoughts on this proposed fix?

@slavapestov
Copy link
Contributor

@swift-ci Please test

@slavapestov slavapestov enabled auto-merge October 30, 2025 02:16
@slavapestov slavapestov merged commit 4677512 into swiftlang:main Oct 30, 2025
4 of 5 checks passed
@jamieQ jamieQ deleted the fix-iso-default-param-idx-bug branch November 1, 2025 10:08
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.

Compiler crash involving isolated default arguments and default tuple arguments

3 participants