Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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

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

Option value is generated using Debug trait.

Error example:

error: crate `incompatible_regparm` has incompatible target modifier with extern crate `wrong_regparm`: `regparm = ( Some(1) | Some(2) )`
  --> $DIR/incompatible_regparm.rs:5:1
   |
LL | #![no_core]
   | ^
   |
   = note: `#[deny(incompatible_target_modifiers)]` on by default

error: aborting due to 1 previous error

@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.

@rust-log-analyzer

This comment has been minimized.

@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.

Comment on lines +305 to +309
if let Some(vec) = &sess.opts.cg.unsafe_allow_abi_mismatch
&& vec.is_empty()
{
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Given that you check access unsafe_allow_abi_mismatch later, maybe do something like this:

Suggested change
if let Some(vec) = &sess.opts.cg.unsafe_allow_abi_mismatch
&& vec.is_empty()
{
return;
}
let allowed_flag_mismatches = sets.opts.cg.unsafe_allow_abi_mismatch.as_ref().unwrap_or_default();
if allowed_flag_mismatches.is_empty() {
// Setting `-Zunsafe-allow-abi-mismatch=` to an empty
// value allows all target modifier mismatches.
return;
}

..and then use allowed_flag_mismatches after this.

(that suggestion might not compile exactly, but you should be able to do something like it)

@@ -58,10 +58,58 @@ macro_rules! hash_substruct {
};
}

macro_rules! gather_tmods {
($_opt_name:ident, $init:expr, $opt_expr:expr, $mods:expr, [SUBSTRUCT], [TMOD]) => {
compile_error!("SUBSTRUCT can't be TMOD (target modifier)");
Copy link
Member

Choose a reason for hiding this comment

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

Can you just use "target modifier" without the TMOD abbreviation throughout?

if let Some(vec) = &sess.opts.cg.unsafe_allow_abi_mismatch
&& vec.is_empty()
{
return;
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to allow users to opt-out of all mismatches?

v: Option<&str>,
) -> bool {
match v {
Some(s) => {
Copy link
Member

Choose a reason for hiding this comment

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

can you call parse_opt_comma_list in this branch and re-use that code?

lint_incompatible_target_modifiers =
mixing `{$flag_name_suffixed}` will cause an ABI mismatch
.note1 = `{$flag_name_suffixed}`=`{$flag_local_value}` in crate `{$local_crate}`, `{$flag_name_suffixed}`=`{$flag_extern_value}` in crate `{$extern_crate}`
.help = This error occurs because the `{$flag_name_suffixed}` flag modifies the ABI,
Copy link
Member

Choose a reason for hiding this comment

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

Ideally this should say something like:

Suggested change
.help = This error occurs because the `{$flag_name_suffixed}` flag modifies the ABI,
.help = `{$flag_name_suffixed}` modifies the ABI and Rust crates compiled with different values of this flag cannot be used together safely

It would be good if we could provide the whole option, not just the name, so -Zregparm rather than regparm.

macro_rules! top_level_options {
( $( #[$top_level_attr:meta] )* pub struct Options { $(
$( #[$attr:meta] )*
$opt:ident : $t:ty [$dep_tracking_marker:ident],
$opt:ident : $t:ty [$dep_tracking_marker:ident $( $tmod:ident )*],
Copy link
Member

Choose a reason for hiding this comment

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

Is the $( )* just because it can be optional? Can you use ? instead?

compile_error!("SUBSTRUCT can't be TMOD (target modifier)");
};
($opt_name:ident, $opt_expr:expr, $mods:expr, [UNTRACKED], [TMOD]) => {
compile_error!("Top level option can't be TMOD (target modifier)");
Copy link
Member

Choose a reason for hiding this comment

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

Why not?

compile_error!("SUBSTRUCT can't be TMOD (target modifier)");
};
($opt_name:ident, $init:expr, $opt_expr:expr, $mods:expr, [UNTRACKED], [TMOD]) => {
if *$opt_expr != $init {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also record a target modifier set to its default value?

};
($opt_name:ident, $init:expr, $opt_expr:expr, $mods:expr, [UNTRACKED], [TMOD]) => {
if *$opt_expr != $init {
$mods.push(format!("{}={:?}", stringify!($opt_name), $opt_expr));
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid storing things like Some(1) or CodeModel::Small or w/e here and instead store whatever the user wrote, since that's what we'll want to show to them.

#![no_core]
#![feature(no_core, lang_items, repr_simd)]

#![cfg_attr(allow_attr, allow(incompatible_target_modifiers))]
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to support this?

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

4 participants