Skip to content

Fix specialization of checked_cast_br instruction#89367

Open
meg-gupta wants to merge 1 commit into
swiftlang:mainfrom
meg-gupta:fixcastspl
Open

Fix specialization of checked_cast_br instruction#89367
meg-gupta wants to merge 1 commit into
swiftlang:mainfrom
meg-gupta:fixcastspl

Conversation

@meg-gupta
Copy link
Copy Markdown
Contributor

When a generic function containing checked_cast_br on a metatype is specialized with a parameterized existential type (e.g. any P<Int>), the substituted types may no longer satisfy the requirements of canSILUseScalarCheckedCastInstructions.

The fix adds a visitCheckedCastBranchInst override to TypeSubstCloner that checks whether the substituted types are still valid for scalar checked cast. If not, it converts the checked_cast_br into a checked_cast_addr_br using stack temporaries.

@meg-gupta meg-gupta requested review from atrick and tbkka May 22, 2026 17:09
@meg-gupta
Copy link
Copy Markdown
Contributor Author

@swift-ci test

When a generic function containing `checked_cast_br` on a metatype is
specialized with a parameterized existential type (e.g. `any P<Int>`),
the substituted types may no longer satisfy the requirements of
`canSILUseScalarCheckedCastInstructions`.

The fix adds a `visitCheckedCastBranchInst` override to TypeSubstCloner
that checks whether the substituted types are still valid for scalar
checked cast. If not, it converts the `checked_cast_br` into a
`checked_cast_addr_br` using stack temporaries.
@meg-gupta
Copy link
Copy Markdown
Contributor Author

@swift-ci test

2 similar comments
@meg-gupta
Copy link
Copy Markdown
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Copy Markdown
Contributor Author

@swift-ci test

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.

1 participant