-
Notifications
You must be signed in to change notification settings - Fork 13.5k
inherit #[align]
from trait method prototypes
#143156
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: master
Are you sure you want to change the base?
inherit #[align]
from trait method prototypes
#143156
Conversation
tests/codegen/align-fn.rs
Outdated
// CHECK-LABEL: trait_method_inherit_default | ||
// CHECK-SAME: align 32 | ||
#[align(32)] | ||
#[no_mangle] |
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.
no_mangle
on a trait declaration item is a FCW
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.
(Also, should probably be unsafe(no_mangle)
)
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 don't see another way of forcing codegen on the symbol? I'm already using -Clink-dead-code
but that is not enough here apparently.
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.
The default method body is implicitly generic in Self
, so “forcing codegen on the symbol” doesn’t even really make sense here I think.
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.
That's what the
pub struct InstantiateDefaultMethods;
impl T for InstantiateDefaultMethods {
fn trait_method_inherit_low(self) {}
fn trait_method_inherit_high(self) {}
}
bit is for.
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 really have a #[rustc_force_codegen]
or something.
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'm also not sure how well it would work here, but it would be nicer than #[no_mangle]
, which is really trying to say an entirely different thing, and -Clink-dead-code
.
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.
Yes, turns out that does work, but because the name is unmangled, rust inserts an extra comment that also contains the function name, so you have to take that into account when writing the CHECK
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.
That's what the […] bit is for.
Imagine if the default body referenced Self
, and you had two instantiations for different types. Then we would have two no_mangle
symbols with the same name.
Maybe add a few tests for multiple |
923f7fc
to
3bc59cd
Compare
@folkertdev I can't promise this won't somehow flow back into concerns for the implementation of the feature we're stabilizing in that PR, but I agree this should be enough for here. |
In particular, "there is one universal rule for how this trait's code should be aligned" reduces the number of things we need to worry about when trying to correctly instantiate the alignment of that code's functions. |
Sure, we'll see how that develops. At least we've thought about this now, and have something concrete to create tests against if the need arises. |
|
Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs |
@workingjubilee this seems straightforward enough. Now that we're planning to make
-Cmin-function-alignment
a target modifier, I don't think there are any cross-crate complications here?@Jules-Bertholet is this the behavior you had in mind? In particular the inheritance of the attribute of a default impl is maybe a bit unintuitive at first? (but I think it's ok if that behavior is explicitly documented).
r? ghost