Skip to content

Conversation

@AnthonyLatsis
Copy link
Collaborator

  • Explanation:
    We currently disallow these by deleting them in the swift namespace. This approach has several loopholes, all of which ultimately work because we happen to define specializations of simplify_type for swift::Type:

    • llvm::isa/cast/dyn_cast. The deleted partial specializations will not be selected because they are not defined in the llvm namespace.
    • The argument is a non-const Type. The deleted function templates will not be selected because they all accept a const Type &, and there is a better Y &Val partial specialization in LLVM.
    • Other casting function templates such as isa_and_nonull and cast_if_present are not deleted.

    Eliminate these loopholes by instead triggering a static assertion failure with a helpful message upon instantiation of CastInfo for swift::Type.

  • Scope: The only behavioral change here is the replacement of several exact casts that were inadvertently using the aforementioned loopholes with desugaring casts.

  • Issues: —

  • Original PRs: AST: Properly disallow isa/cast/dyn_cast on Type #85487

  • Risk: Low.

  • Testing:

  • Reviewers: @hamishknight

We currently disallow these by deleting them in the `swift` namespace.
This approach has several loopholes, all of which ultimately work
because we happen to define specializations of `simplify_type` for
`swift::Type`:
* `llvm::isa/cast/dyn_cast`. The deleted partial specializations will
  not be selected because they are not defined in the `llvm` namespace.
* The argument is a non-const `Type`. The deleted function templates
  will not be selected because they all accept a `const Type &`, and
  there is a better `Y &Val` partial specialization in LLVM.
* Other casting function templates such as `isa_and_nonull` and
  `cast_if_present` are not deleted.

Eliminate these loopholes by instead triggering a static assertion
failure with a helpful message upon instantiation of `CastInfo` for
`swift::Type`.

(cherry picked from commit dd5ac83)
@AnthonyLatsis AnthonyLatsis requested a review from a team as a code owner November 18, 2025 16:27
@AnthonyLatsis AnthonyLatsis changed the title AST: Properly disallow isa/cast/dyn_cast on Type [6.2] AST: Properly disallow isa/cast/dyn_cast on Type Nov 18, 2025
@AnthonyLatsis AnthonyLatsis changed the title [6.2] AST: Properly disallow isa/cast/dyn_cast on Type [6.3] AST: Properly disallow isa/cast/dyn_cast on Type Nov 18, 2025
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.

2 participants