Skip to content

Conversation

@hamishknight
Copy link
Contributor

The pack expansion type variable may be a nested in the fixed type of another type variable, and as such we unfortunately need to fully simplifyType here. This fixes a regression from #84729.

rdar://162545380

…UnresolvedPackExpansions`

The pack expansion type variable may be a nested in the fixed type of
another type variable, and as such we unfortunately need to fully
`simplifyType` here.

rdar://162545380
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

// this is called from `matchTypes`. We need to completely simplify the type
// though since pack expansions can be present in fixed types for nested
// type vars.
auto baseTy = cs.simplifyType(type->getDependentMemberRoot());
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is a hotspot, an alternate implementation is to call getFixedTypeRecursive() and recurse on each type variable that appears therein

Copy link
Contributor

Choose a reason for hiding this comment

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

This is really unfortunate, I was trying to avoid it…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is a hotspot, an alternate implementation is to call getFixedTypeRecursive() and recurse on each type variable that appears therein

Happy to try that instead

Copy link
Contributor Author

@hamishknight hamishknight Oct 14, 2025

Choose a reason for hiding this comment

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

Actually I wonder if we could fix this by moving this logic into the TypeSimplifier itself, I didn't actually realize that getFixedTypeRecursive is calling into simplifyType for DependentMemberType, seems like we ought to be able to change type simplification to decline to simplify a DMT base with an unresolved pack expansion

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is that we delay matching only if the base is a type variable at the moment, that’s why this and the other check for tuples are directly in matchTypes, in this case the base is not a type variable. I think fix that you’d that to change the meaning of isTypeVariableOrMember()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm not sure I follow, for context this is the follow-up I'm planning on doing hamishknight@536304f, which seems to work fine

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried almost exactly that to fix the issue in #84729. I'm talking about check in - https://github.com/swiftlang/swift/blob/main/lib/Sema/CSSimplify.cpp#L7371-L7374, in the example I added the "base" isn't actually a type variable so even though the dependent member didn't get simplified we end up still attempting to match it against the other type and failing that's why I didn't end up going with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I think the problem with my change might have been that it still produced a dependent member type with "newBase" instead of returning the original type... I'm a bit worried if we'd be in a situation that does have a partially resolved dependent member base type at some point though and that would cause too aggressive simplification in matchTypes...

@hamishknight
Copy link
Contributor Author

Source compat failures are unrelated, will do a follow-up PR to clean up this logic

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test macOS

@hamishknight hamishknight merged commit e3c1a3b into swiftlang:main Oct 15, 2025
4 of 7 checks passed
@hamishknight hamishknight deleted the simple-fix branch October 15, 2025 08:10
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.

3 participants