Skip to content
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

Monomorphize code via --monomorphize #568

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

N1ark
Copy link
Contributor

@N1ark N1ark commented Feb 21, 2025

Not anywhere near done, but I'll probably work on this in parallel as I need to cover more code -- for now I'm doing the bare minimum, and opening the draft PR to give some visibility.

Add monomorphisation, by applying an algorithm similar to what rustc does:

  1. Find roots (public monomorphic functions)
  2. Generate monomorphic items:
    1. Find uses of other items within the item (e.g. the function's body, the struct's fields...)
    2. For all used items that are polymorphic, make a monomorphic copy with the generic arguments substituted, if one doesn't exist already.
    3. Substitute these uses with the monomorphic version, which is added to the discovered items.
  3. Remove all polymorphic items; if they were used anywhere, they have already been monomorphized and substituted.

Note a consequence of this algorithm is that it does dead code removal of polymorphic items; any unused polymorphic item will have 0 monomorphic items created, and will thus be removed.

Added a --monomorphize flag to do this.

@msprotz
Copy link
Contributor

msprotz commented Feb 26, 2025

This is super great and something that I will need at some point for Eurydice, too.

Just a heads-up that the main maintainer of Charon, @Nadrieril, will be back online on Monday to help with the review. Thank you!

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.

2 participants