Rename target.abi to target.cfg_abi and enum-ify llvm_abiname#153857
Rename target.abi to target.cfg_abi and enum-ify llvm_abiname#153857RalfJung wants to merge 3 commits intorust-lang:mainfrom
target.abi to target.cfg_abi and enum-ify llvm_abiname#153857Conversation
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| // If llvm_abiname is empty, emit nothing. | ||
| let llvm_abiname = &sess.target.options.llvm_abiname; | ||
| if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) && !llvm_abiname.is_empty() { | ||
| if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) { |
There was a problem hiding this comment.
We force all riscv targets to set an ABI so no check for an empty ABI name is needed here.
| bug!("No ABI specified for this PPC64 ELF target"); | ||
| LlvmAbi::ElfV1 => EF_PPC64_ABI_ELF_V1, | ||
| LlvmAbi::ElfV2 => EF_PPC64_ABI_ELF_V2, | ||
| _ if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => { |
There was a problem hiding this comment.
ElfV1 and ElfV2 are the only allowed ABI names here so we can error on everything else.
9cc36ca to
2b82fad
Compare
|
Also, to quote some of my arguments from #153769 where this change was first proposed (this was in reply to questions/comments by @madsmtm):
I agree that it is a bummer to lose this consistency, but I think it's the preferable outcome over people misunderstanding what
Yeah we just recently fixed a few of them
In both cases AFAIK all targets had a consistent value for
Yeah, agreed. has_reliable_f16_f128 is a hopefully temporary internal hack/heuristic so it's not very critical. I don't know anything about the SPE situation (hence the FIXME).
You mean instead of or on top of the field rename? I'd be fine with doing both, but I do think we should do the field rename.
Exactly.
We discussed this a bit on Zulip but it's not clear what one could do. I think even if we do that, a PR like this one is a helpful first step to map the territory. Personally I have no concrete plans to further cleanup after this PR (mostly due to a lack of good ideas, and also because I don't want to touch the hot potato of actually changing the user-visible |
|
Maybe r? @workingjubilee (or Mads) |
|
|
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
||
| crate::target_spec_enum! { | ||
| pub enum Abi { | ||
| pub enum CfgAbi { |
There was a problem hiding this comment.
Maybe add a comment here? Seems like we ought to be able to say something about the meaning of CfgAbi vs LlvmAbi (below) vs. (maybe) ccABI (if that's defined anywhere).
There was a problem hiding this comment.
The meaning is in the field, not the type... like, we could use this type elsewhere in the compiler. So I'm not sure why one would expect such docs on the type.
There was a problem hiding this comment.
I think it would be confusing to reuse this for a different purpose (e.g., for directly passing to llvm or so). So even a short comment that the cfg here is cfg(target_abi = ...) seems plausible to me.
But definitely not blocking for this PR.
There was a problem hiding this comment.
I did add a short comment, does that help?
There was a problem hiding this comment.
Yeah, that's perfect. Thanks!
| /// In a target spec, this field generally *informs* the user about what the ABI is, but you | ||
| /// have to also set up other parts of the target spec to ensure that this information is | ||
| /// correct. In the rest of the compiler, do not check this field if what you actually need to |
There was a problem hiding this comment.
Is it accurate to say that users should be using this field for e.g. naked asm to determine the right calling convention to expect? Or what is the right way for user code to use this? (Doesn't necessarily need answering here, mostly curious on how useful this actually is).
There was a problem hiding this comment.
We don't currently provide enough information to the user to determine the right calling convention -- e.g., on RISCV there are at least 4 of them and we don't set any cfg flag that would let users systematically observe them. target_abi sounds like maybe it should have that role, but historically it has been used for things that have nothing to do with the calling convention, such as whether this is a real iOS target or a simulated one, or whether this is a regular Windows binary or an UWP one.
This will need a thorough cleanup, which is non-trivial and might involve breaking changes or a new cfg value. I am not here to do that cleanup, I just want to document the current messy situation better so that it is less likely to lead to mistakes.
There was a problem hiding this comment.
Yeah, that makes sense. Just making sure I have the right understanding.
| | CfgAbi::MacAbi | ||
| | CfgAbi::Sim | ||
| | CfgAbi::Unspecified | ||
| | CfgAbi::Other(_) |
There was a problem hiding this comment.
fwiw it feels a little strange to restrict the list of known ABIs and then allow other... is it accurate that Other shouldn't be used by any built-in targets? Maybe we need some kind of lint for that?
There was a problem hiding this comment.
Yeah I think that is the intent for Other. The idea for this check is to ensure that the "reserved" names we use for builtin targets are used consistently, while still allowing experimentation by JSON targets. We could skip the entire check for JSON targets but IMO if a JSON target uses a "reserved" name it should play by its rules.
Also this PR doesn't change that logic.
There was a problem hiding this comment.
I added a consistency check ensuring that builtin targets don't use Other.
|
r=me on the latest changes |
|
@bors r=Mark-Simulacrum |
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in rust-lang#153769 (comment) too. This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI). Also turn llvm_abiname into an enum to make it more natural to match on. Cc @workingjubilee @madsmtm
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in rust-lang#153769 (comment) too. This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI). Also turn llvm_abiname into an enum to make it more natural to match on. Cc @workingjubilee @madsmtm
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in rust-lang#153769 (comment) too. This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI). Also turn llvm_abiname into an enum to make it more natural to match on. Cc @workingjubilee @madsmtm
See Zulip for more context. Discussed a bit in #153769 (comment) too.
This renames
target.abitotarget.cfg_abito make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target.target.abidoes not control that calling convention, it just sometimes informs the user about that calling convention (and also about other aspects of the ABI).Also turn llvm_abiname into an enum to make it more natural to match on.
Cc @workingjubilee @madsmtm