Skip to content

Use Unit_info.t more like upstream #3926

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lukemaurer
Copy link
Contributor

@lukemaurer lukemaurer commented Apr 24, 2025

Cleans up some of the awkwardness around Compilation_unit.t and Unit_info.t, the later of which was recently introduced upstream. This PR is meant to take on a slice of what #3828 is doing (and as such it's admittedly a little scattered).

Specifically:

Meant to be reviewed commit by commit.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This requires knowing the pack prefix wherever a `Unit_info.t` is created, but
generally we're creating a `Compilation_unit.t` and a `Unit_info.t` at the same
time so the caller already knows the pack prefix.
This makes downstream and upstream much better aligned, since upstream uses
`Unit_info.t` in this way. (Some of the changes here are just copied from
upstream, in fact.) There's a bit of awkwardness in that we often need to use
dummy unit info because (unlike upstream) our typechecker can't run without a
current `Compilation_unit.t` set.
Comment on lines +521 to +522
val set_unit_name: Unit_info.t option -> unit
val get_unit_name: unit -> Unit_info.t option
Copy link
Contributor

@voodoos voodoos Apr 24, 2025

Choose a reason for hiding this comment

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

Is there a reason here why you don't stick closer to the upstream signature ?
Having a specialized get_unit_name that returns the Compilation_unit.t directly might reduce the diff a bit?

Upstream signature is:

(* Remember the current compilation unit. *)
val set_current_unit: Unit_info.t -> unit
val get_current_unit : unit -> Unit_info.t option
val get_current_unit_name: unit -> string (* Compilation_unit.t *)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would've rippled out a bit more than I wanted—this is really just aiming to get the right information in the right places. There's at least one place that calls set_current_unit with the previous value of get_current_unit (), though, so something would have to change.

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.

None yet

2 participants