-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Refactor CTFE and const-prop machines to share common code #71129
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
Comments
I propose I wonder if there is a way to also share the |
Hi, I am interested in working on this issue. |
@samrat Perfect! If you have any questions, just post them here. |
@samrat I would suggest for you to work on top of |
Hi, I don't have things working quite yet. But wanted to ask a few questions and get some feedback on what I have so far(samrat@1f1820c). (I have called the common trait ConstMachine as @RalfJung suggested) This is my understanding of what needs to be done as part of the refactoring:
Questions:
It seems with my change, the interpreter now thinks the |
Also,
I have not anticipated that we can achieve only so little reuse here; sorry, I should have checked this before opening the issue. One alternative maybe would be to put all shared code into the
This looks really weird. I do not see how your changes could have led to this. However, you could use the approaches described here for figuring out what is being done to the |
Thanks a lot @samrat for giving this a shot!
I don't think we can do that -- that code only works for particular values of these associated consts. IIRC we already have all assoc-type-independent code that can be shared in the But I also did not expect this much duplication, this is helping much less than I expected. :/ I wonder if there is a way to use specialization to have less duplication here? |
I think your current patch can be improved, but even with that, there is a lot of extra duplication of signatures, when avoiding signature duplication was the entire point of this exercise. Maybe it's just not worth it, at least with the techniques Rust currently offers. |
That's okay, thanks for trying! |
One rather crude but definitely working approach (suggested by @hanna-kruppe) would be to use a macro to share this code... not sure if @oli-obk would like that though.^^ |
Let the record show that I am also skeptical whether this is a good idea, despite pointing out the possibility. I'm not very confident since I'm not familiar with any of the code in question, but this seems like one of those cases where LOC reduction is "penny-wise, pound-foolish" -- it does not seem to help prevent future bugs (only trivial logic and compiler-checked signatures are duplicated), while maintenance becomes harder if some previously-common code has to change in one impl but not in the other. |
This issue is actually motivated by the maintenance burden that we currently have when changing the signatures of methods that are shared by both instances of the trait. Specifically, anything to do with pointers typically has a trivial implementation we want to use everywhere in the compiler, but because pointers might be tagged, we cannot just share that code. So specifically for this I feel like the macro would help reduce maintenance burden. But I might be underestimating how annoying it would be to maintain that macro. |
Miri, CTFE, and const-prop are implemented by using a MIR interpreter that can be customized by implementing the
Machine
trait. Currently, the CTFE and const-prop machines have quite a bit of common code that is duplicated. It would be nice to reduce the code duplication.One idea that could be used to reduce the code duplication would be to add a new trait
CommonMachine
and put all the common implementation into it:The text was updated successfully, but these errors were encountered: