Skip to content

Conversation

@ChayimFriedman2
Copy link
Contributor

That gives us some very nice memory gains, as I explained on Zulip.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 3, 2025
@ChayimFriedman2
Copy link
Contributor Author

Nice, besides huge memory savings this also save a nice amount of time (5s/60s on self, 30s/410s on omicron).

@ChayimFriedman2 ChayimFriedman2 force-pushed the fake-impls branch 5 times, most recently from e2c99f4 to e8e48c2 Compare December 10, 2025 08:57
@ChayimFriedman2 ChayimFriedman2 force-pushed the fake-impls branch 5 times, most recently from d17c961 to 9d90c88 Compare December 18, 2025 08:13
@ChayimFriedman2 ChayimFriedman2 marked this pull request as draft December 18, 2025 08:13
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 18, 2025
@ChayimFriedman2
Copy link
Contributor Author

Rebased on top of #21295 to save me future work, and converted to draft to signal not to merge this before #21295.

@ChayimFriedman2 ChayimFriedman2 marked this pull request as ready for review December 20, 2025 16:50
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2025
@ChayimFriedman2
Copy link
Contributor Author

This is now ready, after #21295 was merged.

@ChayimFriedman2 ChayimFriedman2 force-pushed the fake-impls branch 2 times, most recently from cfe6d56 to 6181d54 Compare December 21, 2025 06:18
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

The amount of extra code this introduces does make me sad I have to say. but I can't really argue against the memory savings here :)

Comment on lines +471 to +477

@non_lang_core_traits:
core::default, Default;
core::fmt, Debug;
core::hash, Hash;
core::cmp, Ord;
core::cmp, Eq;
Copy link
Member

@Veykril Veykril Dec 26, 2025

Choose a reason for hiding this comment

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

I am not a fan of this change. These are not lang items, so we should really not record them as lang item variants imo

Copy link
Contributor Author

@ChayimFriedman2 ChayimFriedman2 Dec 26, 2025

Choose a reason for hiding this comment

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

I can understand that, but resolving them each time will be expensive - this is a common operation (getting the TraitRef requires their ID). We can of course put them on a different query, but I don't see why. Or we can rename this module/struct, but it'll have some churn.

// FIXME: This file is commented out because due to the fast path for builtin derives,
// the macros do not really get expanded, and we cannot check their expansion.
// It's not removed because we still need to find some way to do that nevertheless.
// Maybe going through the list of registered derive calls in the def map?
Copy link
Member

Choose a reason for hiding this comment

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

We could just have a hacky test flag to toggle behavior maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, not a fan of this idea. Also then how will we test that the actual code works?

Copy link
Member

Choose a reason for hiding this comment

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

Well I mean toggling it just for this expansion test here specifically, not for the rest of the test infra.

@ChayimFriedman2
Copy link
Contributor Author

ChayimFriedman2 commented Dec 26, 2025

The amount of extra code this introduces does make me sad I have to say. but I can't really argue against the memory savings here :)

Most of the new code is when trying to expose the new impls to the IDE layer, we can not do it if we give up on the idea of making the new impls seem like regular impl to the IDE layer, which will include that navigating to their function will navigate to the trait instead of the derive.

@Veykril
Copy link
Member

Veykril commented Dec 26, 2025

Yea I get that, don't think of this comment as something we need to resolve (I don't think we can really shave any code down here), so all good.

It sees them as regular impls; the details are abstracted. It's beautiful for the IDE layer, and less beautiful for `hir`, so this is a big change.

Some small differences still exist:

 - We show builtin derives impl (to the IDE layer) as if they have had no generic parameters. It is possible to show the parameters, but that means also having to handle fake impls in `TypeParam` etc., and the benefit is questionable.
 - Getting the fn *def* type of a method of a builtin derive impl is not supported, as there is no real `FunctionId`, therefore no `CallableDefId`. The trait method is returned instead. Note: getting the fn *ptr* type of the method is supported well.
 - Builtin derive impls and their methods do not fully support `HasSource`, because, well, they have no source (at least, not in the form of `ast::Impl` and `ast::Fn`). To support them, we use the derive's `TextRange` where possible, and the trait method's source when not.

 It's important to note that the def map still records the `MacroCallId`. I have doubts over this, as this means it's very easy to create the queries we don't want to create, but it does make things more convenient. In particular, a nicety of this setup is that even "Expand macro recursively" works (it creates the macro input/output query, but given that they will only be created when the user invokes the command, that does not seem to be a problem).
Via a hack to disable their fast path.
@ChayimFriedman2
Copy link
Contributor Author

@Veykril addressed comments.

@Veykril Veykril added this pull request to the merge queue Dec 26, 2025
Merged via the queue into rust-lang:master with commit 8c5a68e Dec 26, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 26, 2025
@ChayimFriedman2 ChayimFriedman2 deleted the fake-impls branch December 27, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants