-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
This comment has been minimized.
This comment has been minimized.
d99ff62
to
bd52a23
Compare
This comment has been minimized.
This comment has been minimized.
bd52a23
to
500600b
Compare
This comment has been minimized.
This comment has been minimized.
db91299
to
43e5956
Compare
This comment has been minimized.
This comment has been minimized.
…d compared to be equal in different crates
43e5956
to
6793451
Compare
if let Some(vec) = &sess.opts.cg.unsafe_allow_abi_mismatch | ||
&& vec.is_empty() | ||
{ | ||
return; | ||
} |
There was a problem hiding this comment.
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:
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)"); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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:
.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 )*], |
There was a problem hiding this comment.
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)"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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))] |
There was a problem hiding this comment.
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?
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: