Skip to content

Refactor FnDecl and FnSig non-type fields into a new wrapper type#155223

Draft
teor2345 wants to merge 2 commits intorust-lang:mainfrom
teor2345:fndef-refactor
Draft

Refactor FnDecl and FnSig non-type fields into a new wrapper type#155223
teor2345 wants to merge 2 commits intorust-lang:mainfrom
teor2345:fndef-refactor

Conversation

@teor2345
Copy link
Copy Markdown
Contributor

@teor2345 teor2345 commented Apr 13, 2026

This PR is part of an initial cleanup for the arg splat experiment, but it's a useful refactor by itself.

It refactors the non-type fields of FnDecl, FnSig, and FnHeader into a new packed wrapper types, based on this comment:
#153697 (comment)

It also refactors some common FnSig creation settings into their own methods. I did this instead of creating a struct with defaults. I wasn't sure how to do that, because we need the bit-packing to create space for the splatted argument index for the splat experiment.

We need to pack the FnDecl and FnSig values somehow, to avoid breaking "type is small" assertions for commonly used types when splat gets added. This PR packs these types:

  • ExternAbi: enum + unwind variants (38) -> 6 bits
  • ImplicitSelfKind: enum variants (5) -> 3 bits
  • lifetime_elision_allowed, safety, c_variadic: bool -> 1 bit

For now, I just want to check CI passes:
r? ghost

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 13, 2026
Comment on lines +896 to 899
let c_variadic_from = fn_args_kind_from.c_variadic();
let c_variadic_to = fn_args_kind_to.c_variadic();
assert_eq!(
c_variadic_from, c_variadic_to,
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since the review

Can this directly check equality for the FnArgsKind`?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this directly check equality for the FnArgsKind`?

Yep, but then when we add more fields the error stops providing useful details.

I think it would be clearer to move more fields into the type in this PR, so I'll do that over the next week or so.

@teor2345 teor2345 changed the title Refactor FnDef fields into a new wrapper type Refactor FnDecl and FnSig non-type fields into a new wrapper type Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants