Skip to content

[6.2] [CS] Avoid solver-allocated inputs with typesSatisfyConstraint #82152

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

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Jun 10, 2025

6.2 cherry-pick of #82147, minus the more risky parts of that change

  • Explanation: Fixes an issue where we would allow solver-allocated types to leak into a nested ConstraintSystem arena, which lead to lifetime issues in cases where e.g the ContextSubMap for a NominalOrBoundGenericNominalType is lazily computed. This resulted in use-after-frees.
  • Scope: Affects diagnostic logic and CSRanking
  • Issue: rdar://152763265
  • Risk: Low/Medium, it does touch CSRanking logic, but it should only affect solutions that are already invalid. I've also tweaked the check to be even narrower for 6.2, it just checks for isSolverAllocated instead of hasTypeVariableOrPlaceholder.
  • Testing: Added tests to test suite
  • Reviewer: Slava Pestov

Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
Check for `isSolverAllocated` rather than
`hasTypeVariableOrPlaceholder`, and downgrade an `ASSERT` to
`CONDITIONAL_ASSERT`.
@hamishknight hamishknight requested a review from hborla June 10, 2025 15:34
@hamishknight hamishknight requested a review from a team as a code owner June 10, 2025 15:34
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight requested a review from bnbarham June 10, 2025 15:37
@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight hamishknight merged commit 19bc18f into swiftlang:release/6.2 Jun 13, 2025
7 checks passed
@hamishknight hamishknight deleted the fix-nested-arenas-6.2 branch June 13, 2025 07:02
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