Skip to content

Target modifiers (special marked options) are recorded in metainfo#133138

Merged
bors merged 1 commit intorust-lang:masterfrom
azhogin:azhogin/target-modifiers
Feb 3, 2025
Merged

Target modifiers (special marked options) are recorded in metainfo#133138
bors merged 1 commit intorust-lang:masterfrom
azhogin:azhogin/target-modifiers

Conversation

@azhogin
Copy link
Contributor

@azhogin azhogin commented Nov 17, 2024

Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates.

PR for this RFC: rust-lang/rfcs#3716

Option may be marked as TARGET_MODIFIER, example: regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER].
If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a Vec<TargetModifier>:

pub struct TargetModifier {
    pub opt: OptionsTargetModifiers,
    pub value_name: String,
}

OptionsTargetModifiers is a macro-generated enum.

Option value code (for comparison) is generated using Debug trait.

Error example:

error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm`
  --> $DIR/incompatible_regparm.rs:10:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
   = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm`
   = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm`
   = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error

error: aborting due to 1 previous error

-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return to disable list of flags.

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2024

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2024
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from d99ff62 to bd52a23 Compare November 18, 2024 19:21
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from bd52a23 to 500600b Compare November 18, 2024 22:37
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch 2 times, most recently from db91299 to 43e5956 Compare November 20, 2024 22:32
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 43e5956 to 6793451 Compare November 21, 2024 10:31
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2024
@azhogin azhogin force-pushed the azhogin/target-modifiers branch 2 times, most recently from 95f9595 to 9cd86c3 Compare November 26, 2024 22:28
@azhogin
Copy link
Contributor Author

azhogin commented Nov 28, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2024
@azhogin azhogin marked this pull request as ready for review November 28, 2024 10:54
@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 9cd86c3 to 97a8240 Compare November 28, 2024 11:57
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 97a8240 to 8603b2b Compare November 28, 2024 13:12
@bors

This comment was marked as resolved.

@azhogin
Copy link
Contributor Author

azhogin commented Jan 30, 2025

I have no idea how to fix those apple build problems.
Auxiliary dependence crate is built as a shared library (dylib), when #![crate_type = "rlib"] is declared in test code. Why?
Shared library linking cc, probably, converts "-m32" flag into -arch armv4t. And this arch is absent (probably) on aarch64.

May I use "only-x86" in tests to avoid this problem?

error in revision `error`: auxiliary build of "/Users/runner/work/rust/rust/tests/ui/target_modifiers/auxiliary/[default_reg_struct_return.rs](http://default_reg_struct_return.rs/)" failed to compile: 
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2/bin/rustc" "/Users/runner/work/rust/rust/tests/ui/target_modifiers/auxiliary/[default_reg_struct_return.rs](http://default_reg_struct_return.rs/)" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/work/rust/rust/vendor" "--sysroot" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2" "--cfg" "error" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/target_modifiers/defaults_check.error/auxiliary" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "--target" "i686-unknown-linux-gnu" "-Cpanic=abort" "--crate-type" "dylib" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/target_modifiers/defaults_check.error/auxiliary"
--- stderr -------------------------------
error: linking with `cc` failed: exit status: 1
   |
   |
   = note:  "cc" "-Wl,--version-script=/var/folders/2s/h6hvv9ps03xgz_krkkstvq_r0000gn/T/rustcZa04xa/list" "-Wl,--no-undefined-version" "-m32" "/var/folders/2s/h6hvv9ps03xgz_krkkstvq_r0000gn/T/rustcZa04xa/symbols.o" "<1 object files omitted>" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/target_modifiers/defaults_check.error/auxiliary/default_reg_struct_return.ax0jv2gekq29a92ihecgk1l7u.rcgu.rmeta" "-Wl,--as-needed" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/target_modifiers/defaults_check.error/auxiliary" "-L" "<sysroot>/lib/rustlib/i686-unknown-linux-gnu/lib" "-o" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/target_modifiers/defaults_check.error/auxiliary/libdefault_reg_struct_return.so" "-shared" "-Wl,-soname=libdefault_reg_struct_return.so" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,--enable-new-dtags,-z,origin"
   = note: ld: warning: directory not found for option '-L/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2/lib/rustlib/i686-unknown-linux-gnu/lib'
   = note: ld: warning: directory not found for option '-L/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2/lib/rustlib/i686-unknown-linux-gnu/lib'
           ld: unknown/unsupported architecture name for: -arch armv4t
           clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to 1 previous error

@saethlin
Copy link
Member

May I use "only-x86" in tests to avoid this problem?

Yes, so long as you also comment alongside that directive that

Shared library linking cc seems to convert "-m32" flag into -arch armv4t

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from a3a4327 to e3aa87a Compare January 30, 2025 18:07
@saethlin
Copy link
Member

@bors r=davidtwco,saethlin

@bors
Copy link
Collaborator

bors commented Jan 30, 2025

📌 Commit e3aa87a has been approved by davidtwco,saethlin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 30, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 31, 2025
…davidtwco,saethlin

Target modifiers (special marked options) are recorded in metainfo

Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates.

PR for this RFC: rust-lang/rfcs#3716

Option may be marked as `TARGET_MODIFIER`, example: `regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER]`.
If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a `Vec<TargetModifier>`:
```
pub struct TargetModifier {
    pub opt: OptionsTargetModifiers,
    pub value_name: String,
}
```

OptionsTargetModifiers is a macro-generated enum.

Option value code (for comparison) is generated using `Debug` trait.

Error example:
```
error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm`
  --> $DIR/incompatible_regparm.rs:10:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
   = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm`
   = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm`
   = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error

error: aborting due to 1 previous error
```

`-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return` to disable list of flags.
@bors
Copy link
Collaborator

bors commented Jan 31, 2025

⌛ Testing commit e3aa87a with merge 2248e35...

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as resolved.

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 31, 2025
@azhogin azhogin force-pushed the azhogin/target-modifiers branch from e3aa87a to 05c88a3 Compare February 2, 2025 15:12
@saethlin
Copy link
Member

saethlin commented Feb 2, 2025

@bors r=davidtwco,saethlin

@bors
Copy link
Collaborator

bors commented Feb 2, 2025

📌 Commit 05c88a3 has been approved by davidtwco,saethlin

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Feb 3, 2025

⌛ Testing commit 05c88a3 with merge 73e2412...

@rust-log-analyzer

This comment was marked as resolved.

@bors

This comment was marked as resolved.

@saethlin
Copy link
Member

saethlin commented Feb 3, 2025

@bors retry

@bors
Copy link
Collaborator

bors commented Feb 3, 2025

⌛ Testing commit 05c88a3 with merge 7daf4cf...

@bors
Copy link
Collaborator

bors commented Feb 3, 2025

☀️ Test successful - checks-actions
Approved by: davidtwco,saethlin
Pushing 7daf4cf to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7daf4cf): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (primary 4.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
4.5% [4.5%, 4.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.5% [4.5%, 4.5%] 1

Binary size

Results (secondary 0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 778.369s -> 779.014s (0.08%)
Artifact size: 328.65 MiB -> 328.74 MiB (0.03%)

@petrochenkov
Copy link
Contributor

The tests are unignored on all platforms in #137801.

@petrochenkov
Copy link
Contributor

Also, the amount of over-engineering in the implementation here is very high.

There will only be several options like this, half of them will likely use some individual approach and smart comparison.
So there's no need to introduce the TARGET_MODIFIER syntax and parse it using elaborated tt munchers.
There's also no need to generalize over various modifiers to put them into a single map or vector.

A structure with a manually written field per every modifier should work well enough here.

@Darksonn
Copy link
Member

@rustbot label F-target_modifiers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-metadata Area: Crate metadata CI-spurious-fail-msvc CI spurious failure: target env msvc F-target_modifiers `#![feature(target_modifiers)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.