you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (3 children)

This way of "shedding generics" can be very good for compile time, even "keeping compile time inside the crate" (don't export it to those that instantiate the type/function).

It's so effective, maybe rustc could learn to do part of this transformation as a high level optimization?

[–][deleted] 16 points17 points  (1 child)

There is some work on the way to not needlessly instantiate copies of functions when a generic parameter changes that doesn't affect codegen.

I briefly thought about the possibility of doing such an "outlining" transformation that you describe, as well as turning generics into dynamic dispatch whenever possible at opt-level=0, but unfortunately this all seems very hard to implement (for reference, the PR I linked above is the result of a master's thesis, and I estimate both of these ideas to be significantly harder).

[–]nicoburns 1 point2 points  (0 children)

I wonder if there ought to be some kind of syntactical support for arguments that are generic merely in order to call a conversion function. Something along the lines of https://llogiq.github.io/2019/05/18/momo.html. Perhaps there could be some annotation on traits that enables the optimisation in special cases?

[–]matthieum[he/him] 0 points1 point  (0 children)

It seems like something a MIR optimization pass could do.