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

Open
wants to merge 3 commits 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<TargetModifier>:

pub struct TargetModifier {
    pub name_hash: u64,     // option name hash
    pub value_name: String, // User-provided option value (before parsing)
}

Option value code is generated using Debug trait.

Error example:

error: mixing `-Zregparm` will cause an ABI mismatch
  --> $DIR/incompatible_regparm.rs:9:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: `-Zregparm` 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: alternatively, 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
compiler/rustc_metadata/src/creader.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_metadata/src/creader.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
tests/ui/target_modifiers/incompatible_regparm.rs Outdated Show resolved Hide resolved
@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
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
@bors

This comment was marked as resolved.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 95ffdf8 to c59d611 Compare December 10, 2024 06:39
@azhogin
Copy link
Contributor Author

azhogin commented Dec 10, 2024

Re-worked as a hard error.
Only user option values are stored in metainfo (with name hash). User values are parsed again and converted into tech values (printed by Debug trait) for comparison during verification procedure.
'Allow-all' flag option removed.

@azhogin
Copy link
Contributor Author

azhogin commented Dec 10, 2024

@rustbot ready

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from c59d611 to 7dfbf13 Compare December 12, 2024 06:18
@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/target-modifiers branch from 7dfbf13 to 6741a49 Compare December 12, 2024 08:53
compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
//@ needs-llvm-components: x86
//@ revisions:error_generated allow_regparm_mismatch

//@[allow_regparm_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=regparm
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 add another test showing that -Cunsafe-allow-abi-mismatch must be provided a value?

compiler/rustc_session/src/options.rs Outdated Show resolved Hide resolved
metadata_incompatible_target_modifiers =
mixing `{$flag_name_prefixed}` will cause an ABI mismatch
.note = `{$flag_name_prefixed}={$flag_local_value}` in this crate is incompatible with `{$flag_name_prefixed}={$flag_extern_value}` in dependency `{$extern_crate}`
.help = `{$flag_name_prefixed}` modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.help = `{$flag_name_prefixed}` modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
.help = this error occurs because the `{$flag_name_prefixed}` flag modifies the ABI,
and different crates in your project were compiled with inconsistent
values
.help = to resolve this, ensure that `{$flag_name_prefixed}` is set to the same value
for all crates during compilation

@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 Dec 12, 2024
@azhogin
Copy link
Contributor Author

azhogin commented Dec 18, 2024

Implemented CodegenOptionsTargetModifiers and UnstableOptionsTargetModifiers enums generation. To generate enums with macro_rules it is necessary to use recursive mechanic, that's why #![recursion_limit = "256"] in rustc_session.
Small fixes performed too.
@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 Dec 18, 2024
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

I think the enum key is a lot better, I'll pass this on to someone else just to get another opinion on it.

pub enum OptionsTargetModifiers {
CodegenOptions(CodegenOptionsTargetModifiers),
UnstableOptions(UnstableOptionsTargetModifiers),
}
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be generated like the Options struct, just in case any top-level arguments are target modifiers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OptionsTargetModifiers enum is now generated by macro to support substruct option groups. But top-level arguments can't now be target modifiers, because they are processed in a different way, they are not parsed by the same "parse_*" functions system. They are set manually in different places.
Target modifiers are now supported only for codegen/unstable option groups.

@@ -1986,10 +2221,10 @@ options! {
"enable queries of the dependency graph for regression testing (default: no)"),
randomize_layout: bool = (false, parse_bool, [TRACKED],
"randomize the layout of types (default: no)"),
reg_struct_return: bool = (false, parse_bool, [TRACKED],
reg_struct_return: bool = (false, parse_bool, [TRACKED TMOD],
Copy link
Member

Choose a reason for hiding this comment

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

I think it would better if TMOD was TARGET_MODIFIER in these macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@davidtwco
Copy link
Member

r? compiler

@rustbot rustbot assigned petrochenkov and unassigned davidtwco Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants