Skip to content
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

Implement builtin # syntax and use it for offset_of!(...) #110694

Merged
merged 3 commits into from
May 9, 2023

Conversation

est31
Copy link
Member

@est31 est31 commented Apr 22, 2023

Add builtin # syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the offset_of! macro, added by #106934.

cc @petrochenkov @drmeepster

cc #110680 builtin # tracking issue
cc #106655 offset_of! tracking issue

@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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. labels Apr 22, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-meta Area: Issues & PRs about the rust-lang/rust repository itself label Apr 22, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 22, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@clubby789
Copy link
Contributor

Once builtin# syntax is merged, would it make sense to implement builtin#ptr_write, as suggested in #108516 (comment) ?

@est31
Copy link
Member Author

est31 commented Apr 22, 2023

@clubby789 personally I'd like that, yes. It is imo better to have such a primitive than #[rustc_box], as its main use is inside the vec![] macro which immediately converts the boxed slice into a Vec. Outside of rust, builtin#write (and its macro wrapper) can support users who don't have alloc or std but do have core, say rust-on-linux folks. The offset_of macro btw helps people with these use cases as well because it makes it easier for them to build macros that get you 95% there... but all of this obviously doesn't change the fact that one can't remove builtin#write/#[rustc_box] from vec![]'s implementation and IMO it's simpler to have builtin#write than to have #[rustc_box].

@rust-log-analyzer

This comment has been minimized.

@beepster4096
Copy link
Contributor

It might be better to have a builtin#shallow_init_box instead to more closely match the mir that #[rustc_box] generates.

@est31
Copy link
Member Author

est31 commented Apr 23, 2023

Oh I was unaware of rust-lang/compiler-team#460 and #89030 . It seems to be a special case just to support box syntax / #[rustc_box]. Maybe it would be possible to use something that builds on MaybeUninit instead, say for example Box::new_uninit_slice? IIRC the magic that avoids the copies onto the stack is inside the expr_into_dest stuff to write into the Box pointer, not the stuff before it.

Unwinding seems to be implemented weirdly, order depending on whether there is a panic call or not:

struct LoudDrop(u8);

impl Drop for LoudDrop {
    fn drop(&mut self) {
        println!("dropping {}", self.0);
    }
}
fn main() {
    {
        let _v = vec!(LoudDrop(0), LoudDrop(1));
    }
    println!("Hi");
    {
        let _v = vec!(LoudDrop(2), LoudDrop(3), LoudDrop(4), panic!());
    }
}

prints

dropping 0
dropping 1
Hi
dropping 4
dropping 3
dropping 2

anyways we should better discuss this in a separate thread, I want to keep this one dedicated to my PR. Edit: filed #110715

@est31 est31 marked this pull request as ready for review April 23, 2023 11:16
@rustbot
Copy link
Collaborator

rustbot commented Apr 23, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

src/tools/tidy/src/ui_tests.rs Outdated Show resolved Hide resolved
compiler/rustc_lexer/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/mod.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

#110970 has landed, r=me after rebase.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels May 4, 2023
@est31
Copy link
Member Author

est31 commented May 4, 2023

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 4, 2023
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 5, 2023

📌 Commit d5669bf7f881d194c9c5ff1536c67fa635d4030c has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#103056 (Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds)
 - rust-lang#108801 (Implement RFC 3348, `c"foo"` literals)
 - rust-lang#110773 (Reduce MIR dump file count for MIR-opt tests)
 - rust-lang#110876 (Added default target cpu to `--print target-cpus` output and updated docs)
 - rust-lang#111068 (Improve check-cfg implementation)
 - rust-lang#111238 (btree_map: `Cursor{,Mut}::peek_prev` must agree)

Failed merges:

 - rust-lang#110694 (Implement builtin # syntax and use it for offset_of!(...))

r? `@ghost`
`@rustbot` modify labels: rollup
@bors

This comment was marked as resolved.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 5, 2023
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 5, 2023

📌 Commit 83b4df4 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#110304 (Add GNU Property Note)
 - rust-lang#110504 (Tweak borrow suggestion span)
 - rust-lang#110583 (tweak "make mut" spans when assigning to locals)
 - rust-lang#110694 (Implement builtin # syntax and use it for offset_of!(...))
 - rust-lang#111120 (Suggest let for possible binding with ty)
 - rust-lang#111252 (Min specialization improvements)
 - rust-lang#111361 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dbd090c into rust-lang:master May 9, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants