Skip to content

Conversation

@AnthonyLatsis
Copy link
Collaborator

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.

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Thanks!

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Oops!

@slavapestov
Copy link
Contributor

FWIW, Type values should never be const. It's pointless to make them const, because they are immutable anyway.

@AnthonyLatsis
Copy link
Collaborator Author

It's pointless to make them const, because they are immutable anyway.

Yeah, unless you want to declare a local let, which I quite like doing in large scopes 🙂

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

AnthonyLatsis added a commit to swiftlang/llvm-project that referenced this pull request Nov 13, 2025
@AnthonyLatsis
Copy link
Collaborator Author

swiftlang/llvm-project#11823

@swift-ci please smoke test

AnthonyLatsis added a commit to swiftlang/llvm-project that referenced this pull request Nov 13, 2025
AnthonyLatsis added a commit to swiftlang/llvm-project that referenced this pull request Nov 14, 2025
[stable/21.x][lldb] Swift: Fix `swift::Type` casts for swiftlang/swift#85487
AnthonyLatsis added a commit to swiftlang/llvm-project that referenced this pull request Nov 14, 2025
[next][lldb] Swift: Fix `swift::Type` casts for swiftlang/swift#85487
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`.
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke 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.

4 participants