Skip to content

Implement symbol interning infra #17584

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

Merged
merged 6 commits into from
Jul 15, 2024
Merged

Implement symbol interning infra #17584

merged 6 commits into from
Jul 15, 2024

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Jul 12, 2024

Will fix #15590

My unsafe-fu is not the best but it does satisfy miri.

There is still some follow up work to do, notably a lot of places using strings instead of symbols/names, most notably the token tree.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 12, 2024
@Veykril Veykril force-pushed the landing-page branch 2 times, most recently from 7ef7246 to 6643336 Compare July 12, 2024 10:26
@Veykril Veykril force-pushed the landing-page branch 3 times, most recently from 8ac43e2 to 02e4561 Compare July 12, 2024 11:30
Comment on lines 44 to 51
// SAFETY: The pointer is non-null as it is derived from a reference
// Ideally we would call out to `pack_arc` but for a `false` tag, unfortunately the
// packing stuff requires reading out the pointer to an integer which is not supported
// in const contexts, so here we make use of the fact that for the non-arc version the
// tag is false (0) and thus does not need touching the actual pointer value.ext)
packed: unsafe {
NonNull::new_unchecked((r as *const &str).cast::<*const str>().cast_mut())
},
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not too fond of this part as I'd really like to make sure to clear out the LSB but I am not aware of a way of doing this that does not involve transmuting the address to a usize which is disallowed in const contexts

@Veykril Veykril changed the title Implement rough symbol interning infra Implement symbol interning infra Jul 12, 2024
@Veykril Veykril marked this pull request as ready for review July 12, 2024 14:09
@Veykril
Copy link
Member Author

Veykril commented Jul 12, 2024

Oh dear I am getting a STATUS_HEAP_CORRUPTION when running analysis-stats

@lnicola
Copy link
Member

lnicola commented Jul 12, 2024

Just wondering, do we really need to support static strings, or is it more for the convenience of using consts?

@Veykril
Copy link
Member Author

Veykril commented Jul 12, 2024

Mostly the convenience I'd guess? Can't say how much of a perf difference it is in having the known symbols not participate in const re-allocation and ref counting

@Veykril
Copy link
Member Author

Veykril commented Jul 12, 2024

I also just wanted to try myself at a bit of unsafe again as it has been a while :) Though I am quite confused as to why this is failing here.

@Veykril
Copy link
Member Author

Veykril commented Jul 12, 2024

Okay found out where I was being stupid. Ugh, though the next problem is const item / promoteds not having a stable address. So the convenience is now gone since the only option I see is having static + cloning out of them on use... (as const items nor const fn can access statics)

@Veykril Veykril force-pushed the landing-page branch 2 times, most recently from 70073af to c18d25c Compare July 14, 2024 11:32
@Veykril
Copy link
Member Author

Veykril commented Jul 14, 2024

So this saves ~50mb of memory on analysis-stats . --query-sysroot-metadata for me, and that is with only Name changed to use Symbol (shrinking it down to 8 bytes, will be 12 16 when we get hygiene into this). I expect another chunk of savings by replacing SmolStr within tt::Leaf with Symbol as well

@Veykril
Copy link
Member Author

Veykril commented Jul 15, 2024

This revealed a few places where we relying on iteration order of hashmaps in tests, which is now very much apparent given the hashes rely on pointer values. (also I just realized I forgot switch branches when creating the PR)

@Veykril
Copy link
Member Author

Veykril commented Jul 15, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 15, 2024

📌 Commit cde0f69 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 15, 2024

⌛ Testing commit cde0f69 with merge 5784915...

@Veykril
Copy link
Member Author

Veykril commented Jul 15, 2024

Will tackle tt after #17559 to reduce conflicts

@bors
Copy link
Contributor

bors commented Jul 15, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 5784915 to master...

@bors bors merged commit 5784915 into rust-lang:master Jul 15, 2024
11 checks passed
@Veykril Veykril deleted the landing-page branch July 15, 2024 09:54
@@ -1348,6 +1348,7 @@ fn proc_attr(a: TokenStream, b: TokenStream) -> TokenStream { a }
.keys()
.map(|name| name.display(&db).to_string())
.sorted()
.sorted()
Copy link
Member

@lnicola lnicola Jul 15, 2024

Choose a reason for hiding this comment

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

@Veykril typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proper name interning
4 participants