-
-
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 :) |
This comment has been minimized.
This comment has been minimized.
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 :)
| 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)
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.
I am also not sure. Right now the new attribute expects a string literal as an argument (e.g. #[export_visibility = "target_default"] - this is the syntax that has been used so far by the RFC) . And it seems that expected_specific_argument_strings is meant to be used with symbols rather than with string literals (e.g. #[export_visibility = target_default]). Do you think the new attribute should use the latter syntax?
| 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
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 you please help me understand what you mean by "struct errors"? Can you point at a piece of code that I should mimic?
Are you asking me to hoist the error string into impl DiagMessage for NewStructForThisParticularError?
| 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)
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.
I am also not sure. I think if #[export_name = ...] needs to be exported, then so does #[export_visibility = ...] although I can't really convincingly point to a specific scenario where this is needed.
|
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.
Adding //@ add-minicore + #![feature(no_core)] + #![no_core] results in build errors of the test code:
error: cannot find macro `line` in this scope
--> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:82:5
|
82 | line!()
| ^^^^
And also another error that I don't quite understand:
error: requires `sized` lang_item
--> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:43:1
|
43 | pub static TEST_STATIC_NO_ATTR: [u8; 7] = *b"static1";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think I'd rather avoid multiplying test expectations and revisions by multiple target platforms. I think focusing on x86_64 in this test is ok. FWIW I tried explaining this in the comment in the new test file:
// 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
For now maybe I can leave things as-is here, but also try to add make-based, end-to-end tests.
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.
Adding
//@ add-minicore+#![feature(no_core)]+#![no_core]results in build errors of the test code:error: cannot find macro `line` in this scope --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:82:5 | 82 | line!() | ^^^^
Could it just return a different int rather than line!()?
And also another error that I don't quite understand:
error: requires `sized` lang_item --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:43:1 | 43 | pub static TEST_STATIC_NO_ATTR: [u8; 7] = *b"static1"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Huh, this definitely happened with //@ add-minicore? Minicore should pull it in
rust/tests/auxiliary/minicore.rs
Lines 58 to 63 in d222ddc
| #[lang = "sized"] | |
| #[diagnostic::on_unimplemented( | |
| message = "the size for values of type `{Self}` cannot be known at compilation time", | |
| label = "doesn't have a size known at compile-time" | |
| )] | |
| pub trait Sized: MetaSized {} |
For reference https://github.com/rust-lang/rust/blob/d222ddc4d90743dfc1e53b610be8fc9d95893d2c/src/doc/rustc-dev-guide/src/tests/minicore.md
I think I'd rather avoid multiplying test expectations and revisions by multiple target platforms. I think focusing on x86_64 in this test is ok. FWIW I tried explaining this in the comment in the new test file:
I agree that testing only a x86-64 target is good. But only- restricts the host in addition to the target, so my suggestions were intended to drop it and use --target with minicore instead (just a convenience so anyone can run the tests easy, even if they're not on an x64 Linux machine).
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).
2043b51 to
8dc8f60
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This PR is an implementation of the RFC tracked in #151425