4

Github Allow specifying alignment for functions by repnop · Pull Request #81234...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/81234
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

New issue

Allow specifying alignment for functions #81234

Conversation

Copy link

Contributor

repnop commented on Jan 21

Fixes #75072

This allows the user to specify alignment for functions, which can be useful for low level work where functions need to necessarily be aligned to a specific value.

I believe the error cases not covered in the match are caught earlier based on my testing so I had them just return None.

Copy link

Collaborator

rust-highfive commented on Jan 21

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

Copy link

Collaborator

rust-highfive commented on Jan 21

warningWarning warning

  • These commits modify submodules.

Copy link

Contributor

Author

repnop commented on Jan 21

Not sure how that submodule got added, but removed thinking

This comment has been hidden.

Copy link

Contributor

lcnr commented on Jan 21

nominating for t-lang for now, I expect us to land this unstably first if we want to do so, but it does seem desirable to do so imo.

Copy link

Member

joshtriplett commented on Feb 9

edited

This seems reasonable to me, to add on an unstable basis. (There needs to be a feature-gate added.)

I also think many codebases will want to set this for all functions using a compiler option (e.g. set in a Cargo profile). But supporting it on individual functions seems reasonable as well.

EDIT: We discussed this in today's lang-team meeting, and this was the general consensus:

  • Please add a feature-gate (e.g. func_align)
  • When this is merged, we'll need a tracking issue

Copy link

Contributor

Author

repnop commented on Feb 9

Awesome! I should hopefully have some time soon to do that :)

Copy link

Member

joshtriplett commented 26 days ago

We discussed this in today's @rust-lang/lang meeting, and we're in favor of adding this to nightly, for experimentation, as soon as there's a feature-gate added.

@rfcbot fcp merge
@rfcbot concern feature-gate

Copy link

rfcbot commented 26 days ago

edited

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

This comment has been hidden.

This comment has been hidden.

Copy link

Contributor

Author

repnop commented 25 days ago

I think I added all the requests, any other changes that need made?

Copy link

Member

joshtriplett commented 19 days ago

@rfcbot resolve feature-gate

Thank you!

Copy link

rfcbot commented 19 days ago

bellThis is now entering its final comment period, as per the review above. bell

Copy link

Contributor

bors commented 19 days ago

umbrella The latest upstream changes (presumably #82443) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link

Contributor

Havvy commented 11 days ago

Shouldn't this be going through the RFC process?

Copy link

Contributor

memoryruins commented 11 days ago

Shouldn't this be going through the RFC process?

#[repr(align(x))] for enums did not require a RFC either in #57998, which was introduced as an extension to the repr(align) attribute from RFC 1358. It appears to have gone through a similar process and agreement by the lang team here, except this time rfcbot has been involved ^^

Copy link

rfcbot commented 9 days ago

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

Copy link

Contributor

Author

repnop commented 5 days ago

Anything else before this is merged? :)

Copy link

Contributor

lcnr left a comment

a few nits, after that r=me

let alignment = match &literal.kind {

ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) => {

if literal.is_power_of_two() {

// rustc_middle::ty::layout::Align restricts align to <= 2^29

if *literal <= 1 << 29 {

Ok(*literal as u32)

} else {

Err("larger than 2^29")

}

} else {

Err("not a power of two")

}

}

_ => Err("not an unsuffixed integer"),

};

Comment on lines

+2848 to +2862

lcnr 4 days ago

Contributor

can you deduplicate this and move it into a function?

let parse_alignment = |node: &ast::LitKind| -> Result<u32, &'static str> { if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node { if literal.is_power_of_two() { // rustc_middle::ty::layout::Align restricts align to <= 2^29 if *literal <= 1 << 29 { Ok(*literal as u32) } else { Err("larger than 2^29") } } else { Err("not a power of two") } } else { Err("not an unsuffixed integer") } };

&self.tcx.sess.parse_sess,

sym::fn_align,

hint.span(),

"the attribute `repr(align(...))` on functions is unstable",

lcnr 4 days ago

Contributor

Suggested change
"the attribute `repr(align(...))` on functions is unstable", "`repr(align)` attributes on functions are unstable",

nit: copying the way we write this in

@@ -989,16 +989,36 @@ impl CheckAttrVisitor<'tcx> {

for hint in &hints {

let (article, allowed_targets) = match hint.name_or_empty() {

_ if !matches!(target, Target::Struct | Target::Enum | Target::Union) => {

("a", "struct, enum, or union")

_ if !matches!(

lcnr 4 days ago

edited

Contributor

this already existed before, but why do we match eagerly here thinking

this seems unnecessary and slightly worsens diagnostics. I would prefer us to remove that match arm and
put a delay_span_bug in the wildcard arm here.

You don't have to do that in this PR if you want though.

Copy link

Contributor

bors commented 4 days ago

umbrella The latest upstream changes (presumably #76570) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

lcnr

Assignees

lcnr

Projects

None yet

Milestone

No milestone

Linked issues

Successfully merging this pull request may close these issues.

11 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK