rustc_target: Begin unifying Arch enum#142775
rustc_target: Begin unifying Arch enum#142775workingjubilee wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
These commits modify compiler targets. |
|
also cc @thomcc I intend to make the QNX targets part of this PR too, and also reuse this code elsewhere in |
|
☔ The latest upstream changes (presumably #145126) made this pull request unmergeable. Please resolve the merge conflicts. |
| pub(crate) enum Arch { | ||
| Arm(ArmVer), | ||
| Aarch64(Aarch64Ver), | ||
| X86_32(Ix86), | ||
| X86_64(X86_64Ver), | ||
| } |
There was a problem hiding this comment.
Hmm, I get why you'd want to simplify things in this manner (arch enum with subarch enums), but I'm not sure that's actually a good idea?
I particularly don't like the Arch::Arm64 to Aarch64Ver::V8A.into() change, it makes it harder to understand what's going on (are we specifying the arch or subarch here?), and it becomes incorrect as soon as you pass -Ctarget-cpu=apple-a10.
I'd prefer a single-level Arch enum, and rather have helpers like .is_aarch64() or .is_arm() (if those are even useful in the face of things like ARM64EC).
|
It's always been my experience that "single enum with helpers" is
worse on a few different levels.
Namely, my goal is generally to incentivize matching against precisely
the relevant patterns and to minimize the noise of other patterns. In
particular, I believe the top level `match` should ideally not bottom
out to a plain `_`.
The problem is that such is effectively what `if let` does.
If the only complaint is an `into`, I can work on reducing that. But
if the problems are deeper, I am happy to think of a different
approach if this does not suit.
It's been a while so I'm not sure what you mean by
`-Ctarget-cpu=apple-a10` changing things, though. Do the number of
changes necessary actually alter significantly...?
|
I went into this with the presumption that the plan is to use this If that is the case, then I kinda feel like we don't really have the data on whether a big or several smaller enums would be preferable? E.g. if you're gonna match on the subarch all the time anyhow, then it's just extra noise. I did a quick count on the number of archs in
What I meant here is that I think
That would certainly help, |
I simply don't understand what you mean. When reasoning about target architectures, the minimum is burned into the target. Later usage of |
There was a problem hiding this comment.
When reasoning about target architectures, the minimum is burned into the target.
I guess that's fair.
In any case, this is somewhat outside my domain knowledge. Feel free to do whatever you think is best here, as long as we do the Aarch64Ver::V8A.into() -> Arch::Aarch64(Aarch64Ver::V8A) in the target definitions then I'm fine with it.
There are a few different instances of this Arch enum in
rustc_target. I would like to unify them so that we use shared code in more cases, as part of an incremental step towards turning Target into a proper builder with type-level correctness instead of its current constructor. However, it's definitely true the immediate changes look somewhat jank and have the disadvantage of in some cases handling some code less exhaustively, so I'm going to ask some maintainers if it's okay.This PR currently starts with lifting from the Apple code, so
r? @madsmtm