5

Implement builtin # syntax and use it for offset_of!(...) by est31 · Pull Reques...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/110694
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.
neoserver,ios ssh client

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

Merged

Conversation

Contributor

@est31 est31

commented

Apr 22, 2023

edited

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

clubby789 and coolreader18 reacted with eyes emoji

Collaborator

r? @WaffleLapkin

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

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

This comment has been minimized.

rustbot

added the A-meta Area: Issues about the rust-lang/rust repository. label

Apr 22, 2023

This comment has been minimized.

This comment has been minimized.

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

This comment has been minimized.

This comment has been minimized.

Contributor

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

Contributor

Author

@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].

clubby789 reacted with thumbs up emoji

This comment has been minimized.

Contributor

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

Contributor

Author

est31

commented

Apr 23, 2023

edited

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

Collaborator

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

Contributor

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

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: marked as blocked ❌ on something else such as an RFC or other implementation work.

labels

May 4, 2023

Contributor

Author

@rustbot ready

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

Contributor

@bors r+

Contributor

pushpin Commit d5669bf has been approved by petrochenkov

It is now in the queue for this repository.

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

This comment has been hidden.

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

Contributor

@bors r+

Contributor

pushpin Commit 83b4df4 has been approved by petrochenkov

It is now in the queue for this repository.

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

merged commit dbd090c into

rust-lang:master

May 9, 2023

11 checks passed

rustbot

added this to the 1.71.0 milestone

May 9, 2023

rust-timer

added a commit to rust-lang-ci/rust that referenced this pull request

May 9, 2023

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

Reviewers

fbstj

fbstj left review comments

petrochenkov

petrochenkov left review comments
Labels
A-meta Area: Issues about the rust-lang/rust repository. 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

Milestone

1.71.0

Development

Successfully merging this pull request may close these issues.

None yet

9 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK