sess: target modifiers under -T - #160167
Draft
davidtwco wants to merge 27 commits into
Draft
Conversation
The existing implementation of target modifiers is quite complicated and hard to work with because it relies so heavily on macros. To some extent, this is unavoidable because only a subset of the `UnstableOptions` or `CodegenOptions` flags are target modifiers and so it needs to filter for those. A simpler implementation will be possible given the additional constraint that all target modifier options are in the same group.
A small refactoring just to give each of these meta-variables better names.
Reporting good target modifier mismatch errors will require at least knowing whether a option was set by the user explicitly rather than just having its default value. This small addition to the infrastructure enables that to be tracked. It is not persisted into the cross-crate metadata, it will only be required in the local crate.
Introduces a new implementation of target modifiers under the `-T` prefix, leveraging that all of the options are in the one struct so that the whole type can just be encoded or decoded to keep track of the values set in downstream crates. The term "target modifiers" is leaked, not just "target flags" because `--target` is already used (unsurprisingly!).
Introduce a generic mechanism for requiring `-Zunstable-options` on flags so this doesn't need to be checked per-flag manually.
Introduces a new trait to control printing of the values of target modifier options in the target modifier diagnostics.
This additional argument will be used in a future commit to allow some flags to accept arguments on when used as target modifiers (once flags can be both `-T` and `-C`).
Another big refactoring making all codegen flags both `-T` target modifiers and `-C` regular codegen flags, and enforcing that values match only when a flag is given as `-T`. Flags can be required to be target modifiers, optionally be target modifiers, or never be target modifiers. This commit no longer stores the entire `TargetOpts` struct, which no longer exists in metadata. Instead, produce a map from a new key enum (with one variant for each option) to the value set with `-T` and store that map. Values are converted to a `TargetModifierValue` type that stores only the types that target-modifier-compatible options - this is hypothetically better than `Box<dyn Any>` that is not encodable and is large, or storing all of the option values.
Re-using the key enum that was introduced in the previous commit to track options being set using a `HashSet` rather than a new struct with boolean fields.
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Contributor
|
☔ The latest upstream changes (presumably #160190) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc rust-lang/compiler-team#980 (#t-compiler/major changes > group target modifier options under `-T` compiler-team#980)
This patch re-implements target modifiers so that they are grouped under
-Tinstead of being regular flags.The current implementation is quite complex, using lots of
macro_rules!s to filter out the target modifier options from the rest of the codegen options, and then storing the original string values of the target modifiers in cross-crate metadata before re-parsing them again in the downstream crate. Some of this complexity is desirable - we don't want to store every option value in the cross-crate metadata because that would hurt compile times. This patch removes the current approach entirely and starts again, leveraging simplifications made possible by the-Tdesign.-Tcompiler-team#980TargetOptionsstruct is introduced that is parsed from-Tand target modifier options are moved to itTargetOptionsis serialised in its entirety into cross-crate metadata, which is a lot simpler and isn't storing any more information than necessaryTRACKED_UNSTABLEto require that-Zunstable-optionsbe provided if they are used - all current target modifiers are unstable so this is used for all of them-Tand-Z, with onlyaddressandleakbeing in-Zand everything else being in-Tw/-Zunstable-options-Ttarget-cpuis required for targets withTargetOptions::requires_consistent_cpu, otherwise-Ctarget-cpuremains usable-Titself is insta-stable, but all the options under are unstable, so it's effectively unstable-Coptions can also be used as-ToptionsTargetOptionsis removed again and target modifier options are now moved intoCodegenOptions(they're still unstable thanks to the aforementionedTRACKED_UNSTABLE)CodegenOptionsis parsed from both-Cand-T-Ttakes precedenceTargetModifierFilter::Only(only-T, no-C) orTargetModifierFilter::Never(only-C, no-T)-Toption values are stored into aFxHashMap, these are stored into cross-crate metadata so we know which options were set as target modifiers in dependencies and we only store those that were set with-TCodegenOptionsKeyenum that has a variant for each optionTargetModifierValuetype that contains variants for each distinct value type of the options we support as being target modifiersTargetModifierValuedoesn't support should be marked as never-target-modifiers, I haven't done that yet and rustc will ICE if you use them with-TTargetModifierValuewas introduced as an attempt to try and keep cross-crate metadata size down - avoidingBox<dyn Any>or storing strings for every option-Tis insta-stable for any of the currently stable-CoptionsTo-do:
-Zsanitizers-cfi-normalize-integerswas previously only a target modifier for-Zsanitizers=kcfi, not-Zsanitizers=cfi, but it is now a target modifier for both-C/-Tversion) Which options should never be usable as target modifiers? Options related to linking or file paths?Opening this as a draft as there are clearly some questions to resolve above.