Skip to content

Make ModuleId a tracked struct #20001

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Jun 14, 2025

This is in part an experiment. I am partially hoping for this to have a positive memory impact (as it shrinks ModuleId from 12 to 4 bytes) it did not sadge. Funnily enough I also revealed 2 bugs with this (and fixed them).

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2025
@Veykril Veykril force-pushed the push-wkvlouswwywy branch from 52a4e61 to 77894b3 Compare June 14, 2025 11:08
@Veykril Veykril marked this pull request as draft June 14, 2025 11:09
@@ -474,7 +521,6 @@ fn outer() {
tests: t

block scope::tests
name: _
Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of the bugs. name is not visible from here

@Veykril Veykril force-pushed the push-wkvlouswwywy branch from 77894b3 to 0f33ae9 Compare June 14, 2025 11:16
@flodiebold
Copy link
Member

What's the second bug?

@Veykril Veykril force-pushed the push-wkvlouswwywy branch from 0f33ae9 to 2e64e8f Compare June 14, 2025 12:34
@@ -4437,7 +4436,7 @@ impl Impl {
MacroCallKind::Derive { ast_id, derive_attr_index, derive_index, .. } => {
let module_id = self.id.lookup(db).container;
(
crate_def_map(db, module_id.krate())[module_id.local_id]
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah sorry. This is the second one. We were potentially using a local id of a block def map for the crate def map here.

@Veykril Veykril force-pushed the push-wkvlouswwywy branch from 2e64e8f to caefec5 Compare June 14, 2025 13:01
@Veykril Veykril force-pushed the push-wkvlouswwywy branch from caefec5 to 623b670 Compare June 14, 2025 13:04
@@ -53,7 +53,7 @@
<span class="macro public">foo</span><span class="macro_bang">!</span><span class="parenthesis">(</span><span class="struct declaration macro public">Bar</span><span class="parenthesis">)</span><span class="semicolon">;</span>
<span class="keyword">fn</span> <span class="function declaration">func</span><span class="parenthesis">(</span><span class="punctuation">_</span><span class="colon">:</span> <span class="module">y</span><span class="operator">::</span><span class="struct public">Bar</span><span class="parenthesis">)</span> <span class="brace">{</span>
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span>
<span class="keyword">struct</span> <span class="struct declaration">Innerest</span><span class="angle">&lt;</span><span class="keyword const">const</span> <span class="const_param const declaration">C</span><span class="colon">:</span> <span class="unresolved_reference">usize</span><span class="angle">&gt;</span> <span class="brace">{</span> <span class="field declaration">field</span><span class="colon">:</span> <span class="bracket">[</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> <span class="brace">{</span><span class="const_param const">C</span><span class="brace">}</span><span class="bracket">]</span> <span class="brace">}</span>
<span class="keyword">struct</span> <span class="struct declaration">Innerest</span><span class="angle">&lt;</span><span class="keyword const">const</span> <span class="const_param const declaration">C</span><span class="colon">:</span> <span class="unresolved_reference">usize</span><span class="angle">&gt;</span> <span class="brace">{</span> <span class="field declaration">field</span><span class="colon">:</span> <span class="bracket">[</span><span class="unresolved_reference">u32</span><span class="semicolon">;</span> <span class="brace">{</span><span class="const_param const">C</span><span class="brace">}</span><span class="bracket">]</span><span class="comma">,</span> <span class="field declaration">field2</span><span class="colon">:</span> <span class="punctuation">&</span><span class="struct">Innerest</span> <span class="brace">}</span>
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a bug here, primtiives don't resolve correctly in modules within blocks

@Veykril Veykril force-pushed the push-wkvlouswwywy branch 2 times, most recently from 8c1ea13 to eae79c3 Compare June 14, 2025 13:56
@Veykril Veykril force-pushed the push-wkvlouswwywy branch from eae79c3 to 362ef27 Compare June 14, 2025 13:58
@Veykril
Copy link
Member Author

Veykril commented Jun 14, 2025

So this does increase memory usage by ~30mb 😕 I am not entirely sure why though I guess we have a lot of block def map queries, and us recording tracked structs in those now makes their memo's allocate the extra slot which is what is observable here? IO would've expected the ModuleId shrinking to balance that out at least. It might be better with the new salsa.

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.

3 participants