Repository navigation
fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature - #166008
Conversation
|
cc @bjorn3
cc @rust-lang/miri
|
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
||
| fn init(&mut self, _sess: &EarlySession) -> CodegenBackendInit { | ||
| Default::default() | ||
| fn init(&mut self, _sess: &EarlySession) -> (CodegenBackendInit, TargetConfig) { |
There was a problem hiding this comment.
The 2nd commit refactors backend initialization by merging init and target_config. This is because the LLVM backend can avoid recomputing some data if it can take intermediate results from init and use them to construct target_config. This makes it so that base_llvm_features is actually finally called only once ever, which makes me very happy.
Maybe that means the two types should be merged as well, but I'd prefer to leave that to a future PR as it seems mostly orthogonal, logic-wise.
4262fd4 to
bc2cf69
Compare
|
r? @folkertdev |
|
|
This comment has been minimized.
This comment has been minimized.
bc2cf69 to
7721e8d
Compare
This comment has been minimized.
This comment has been minimized.
7721e8d to
01422ce
Compare
This comment has been minimized.
This comment has been minimized.
01422ce to
e00304e
Compare
This comment has been minimized.
This comment has been minimized.
| None, | ||
| &sess.target, | ||
| ); | ||
| let _ = native_codegen_backend.init(sess); |
There was a problem hiding this comment.
Why is removing the call to init here correct? That function takes &mut self so it might update the session.
There was a problem hiding this comment.
The call has been moved into MiriCodegenBackend::init, because it felt more natural to have it there.
There was a problem hiding this comment.
It's not clear locally how MiriCodegenBackend::init gets called (I guess in compiler/rustc_interface/src/interface.rs?), but I'll happily believe you wrt Miri code.
There was a problem hiding this comment.
MiriCodegenBackend is basically wrapping another codegen backend, so forwarding these calls makes most sense to me. I'm not sure why we previously went for eager initialization...
| // Typically we'll want more explicit settings to override the implicit ones, so: | ||
| // | ||
| // * Features from -Ctarget-cpu=*; are overridden by [^1] | ||
| // * Features implied by --target; are overridden by |
There was a problem hiding this comment.
does this mean "overridden by empty string"? it reads really weird?
There was a problem hiding this comment.
No, it means "overriden by the things listed later in this enumeration"
e00304e to
c9e3b90
Compare
| None, | ||
| &sess.target, | ||
| ); | ||
| let _ = native_codegen_backend.init(sess); |
There was a problem hiding this comment.
It's not clear locally how MiriCodegenBackend::init gets called (I guess in compiler/rustc_interface/src/interface.rs?), but I'll happily believe you wrt Miri code.
This comment has been minimized.
This comment has been minimized.
687e034 to
ba6921e
Compare
This comment has been minimized.
This comment has been minimized.
ba6921e to
47cf3f6
Compare
This comment has been minimized.
This comment has been minimized.
c71ded2 to
72d4c98
Compare
|
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. |
|
@bors r=folkertdev |
This comment has been minimized.
This comment has been minimized.
72d4c98 to
7649596
Compare
|
This pull request was unapproved. |
|
@bors r=folkertdev |
…uwer Rollup of 10 pull requests Successful merges: - #164252 (Share retain implementation between Vec and VecDeque) - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - #166156 (tests: cover proc-macro metadata path remapping) - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - #166506 (traits: Fix dead match arm for String type suggestions.) - #164542 (Add regression test for #151312) - #165651 (compiletest: Further clean up directive parsing) - #166196 (autodiff: don't ICE on invalid macro arguments) - #166556 (remove `Box::into_boxed_slice`) - #166562 (docs: add backticks around `!` in primitive docs )
…uwer Rollup of 10 pull requests Successful merges: - #164252 (Share retain implementation between Vec and VecDeque) - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - #166156 (tests: cover proc-macro metadata path remapping) - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - #166506 (traits: Fix dead match arm for String type suggestions.) - #164542 (Add regression test for #151312) - #165651 (compiletest: Further clean up directive parsing) - #166196 (autodiff: don't ICE on invalid macro arguments) - #166556 (remove `Box::into_boxed_slice`) - #166562 (docs: add backticks around `!` in primitive docs )
Rollup merge of #166008 - RalfJung:llvm-target-feature-precedence, r=folkertdev fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature Currently, -Zllvm-target-feature takes precedence for populating `internal_target_features`, but -Ctarget-feature takes precedence for what we actually tell LLVM. That's pretty bad, so this PR makes them consistent. I first wanted -Zllvm-target-feature to take precedence everywhere, as that was the intent in #160457. However, I don't see a good way to implement that: internal_target_features are computed by instantiating an actual LLVM data structure *without* -Ctarget-feature, querying which Rust target features that supports, and then applying -Ctarget-feature and its implications "manually". This is done to prevent backend implications from affecting `cfg(target_feature)`. But this means we can't really apply -Zllvm-target-feature after having done that as that would take us back down to the LLVM level. So instead, the precedence order is that all LLVM-level stuff comes first, and then -Ctarget-feature comes all the way at the end. Cc @folkertdev (reviewer of #160457), @nnethercote (recently did some refactoring of the backend init logic that is being further adjusted here) Tracking issue: #157753
…uwer Rollup of 10 pull requests Successful merges: - rust-lang/rust#164252 (Share retain implementation between Vec and VecDeque) - rust-lang/rust#166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - rust-lang/rust#166156 (tests: cover proc-macro metadata path remapping) - rust-lang/rust#166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - rust-lang/rust#166506 (traits: Fix dead match arm for String type suggestions.) - rust-lang/rust#164542 (Add regression test for rust-lang/rust#151312) - rust-lang/rust#165651 (compiletest: Further clean up directive parsing) - rust-lang/rust#166196 (autodiff: don't ICE on invalid macro arguments) - rust-lang/rust#166556 (remove `Box::into_boxed_slice`) - rust-lang/rust#166562 (docs: add backticks around `!` in primitive docs )
View all comments
Currently, -Zllvm-target-feature takes precedence for populating
internal_target_features, but -Ctarget-feature takes precedence for what we actually tell LLVM. That's pretty bad, so this PR makes them consistent.I first wanted -Zllvm-target-feature to take precedence everywhere, as that was the intent in #160457. However, I don't see a good way to implement that: internal_target_features are computed by instantiating an actual LLVM data structure without -Ctarget-feature, querying which Rust target features that supports, and then applying -Ctarget-feature and its implications "manually". This is done to prevent backend implications from affecting
cfg(target_feature). But this means we can't really apply -Zllvm-target-feature after having done that as that would take us back down to the LLVM level. So instead, the precedence order is that all LLVM-level stuff comes first, and then -Ctarget-feature comes all the way at the end.Cc @folkertdev (reviewer of #160457), @nnethercote (recently did some refactoring of the backend init logic that is being further adjusted here)
Tracking issue: #157753