-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Add new unstable attribute: #[export_visibility = ...].
#151431
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
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
r? @chenyukang rustbot has assigned @chenyukang. Use |
|
i had a quick look, mostly looks good, but i'd like to maybe @JonathanBrouwer take a look on this as well, i may overlooked something r? JonathanBrouwer |
|
Would like to take a look, will do so tomorrow :) |
|
☔ The latest upstream changes (presumably #151436) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Some minor questions, looks good on a high level :)
| const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; | ||
| const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; | ||
| const ALLOWED_TARGETS: AllowedTargets = | ||
| AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn), Allow(Target::Static)]); |
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 there a reason you choose WarnRest here?
I'd prefer for new attributes to default to AllowedTargets::AllowList.
| return None; | ||
| }; | ||
| let Ok(visibility) = ExportVisibilityAttrValue::from_str(sv.as_str()) else { | ||
| cx.emit_err(InvalidExportVisibility { |
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.
Could this use cx.expected_specific_argument_strings instead?
(not sure)
| export_visibility_span, | ||
| "#[export_visibility = ...]` will be ignored without \ | ||
| `export_name`, `no_mangle`, or similar attribute", | ||
| ); |
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 we make these struct errors?
In my opinion these are still nicer for simple errors like this. If you strongly disagree feel free to keep them like this
| fn from_str(s: &str) -> Result<ExportVisibilityAttrValue, Self::Err> { | ||
| match s { | ||
| "target_default" => Ok(ExportVisibilityAttrValue::TargetDefault), | ||
| _ => Err(format!("'{s}' is not a valid value for #[export_visibility = ...]",)), |
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 this string used anywhere? If not, could we make the Err type ()?
| EiiImpls(..) => No, | ||
| ExportName { .. } => Yes, | ||
| ExportStable => No, | ||
| ExportVisibility { .. } => Yes, |
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 exporting this attribute needed? (Not sure, genuine question)
|
Reminder, once the PR becomes ready for a review, use |
| // Exact LLVM IR differs depending on the target triple (e.g. `hidden constant` | ||
| // vs `internal constant` vs `constant`). Because of this, we only apply the | ||
| // specific test expectations below to one specific target triple. If needed, | ||
| // additional targets can be covered by adding copies of this test file with | ||
| // a different `only-X` directive. | ||
| // | ||
| //@ only-x86_64-unknown-linux-gnu |
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.
It would be good to use add-minicore here so it gets checked on all targets:
//@ add-minicore
//@ compile-flags: --target x86_64-unknown-linux-gnu
#![feature(no_core)]
#![no_core]Possibly also roll this into the revisions so different targets wouldn't need different files.
//@ revisions: LINUX-X86-HIDDEN LINUX-X86-PROTECTED
//@ [LINUX-X86-HIDDEN,LINUX-X86-PROTECTED] compile-flags: --target x86_64-unknown-linux-gnu
...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.
Because of how complex and target-specific everything linker-related is, I think an end-to-end test in tests/run-make would be great to cover an ELF/PE/Mach-O target. Then you have access to the object crate via run_make_support for checking symbol visibility.
To allow each object file type to be built on all platforms with just --target, the test can use a minicore like
| mod minicore { |
//@ add-minicore).
This PR is an implementation of the RFC tracked in #151425