[tooling] Distinct uids for interfaces#13286
Conversation
5737de9 to
9f71a63
Compare
This reverts commit a493ee2.
This reverts commit a493ee2.
This reverts commit a493ee2.
|
|
||
| (** [set_from] allow changing the [from] information stored with uids | ||
| indicating if they emanate from an interface or an implementation file. *) | ||
| val set_from : intf_or_impl -> unit |
There was a problem hiding this comment.
I think it would be better to store this information in the same place we store the current unit name (i.e. in Env). Possibly it would be worth creating a current_unit type containing the name and the intf_or_impl and then have mk take one of those and then have Env.get_current_unit return one of those and replace the vast majority of Env.get_unit_names with Env.get_current_unit. (Also maybe rename Env.get_unit_name to Env.get_current_unit_name for clarity).
There was a problem hiding this comment.
It seems like a reasonable thing to do, but I am going to face circular dependencies issues if the current_unit type is defined in Env and refered to in Shape.Uid. I dug a bit more and there might be an even more appropriate place for that type definition: the Unit_info module introduced by @Octachron. Currently, the unit_name in env is set from the corresponding field of Unit_info.t:
let with_info ~native ~tool_name ~source_file ~output_prefix ~dump_ext k =
Compmisc.init_path ();
let target = Unit_info.make ~source_file output_prefix in
Env.set_unit_name (Unit_info.modname target);
let env = Compmisc.initial_env() in
let dump_file = String.concat "." [output_prefix; dump_ext] in
Compmisc.with_ppf_dump ~file_prefix:dump_file @@ fun ppf_dump ->
k {
target;
env;
ppf_dump;
tool_name;
native;
}Maybe we could simply add the impl_or_intf field to the Unit_info.t and store all this in the Env reference: Env.set_unit_info target ?
There was a problem hiding this comment.
I made changes in that direction in e05aae4
|
Ping @lpw25 : are you planning to do a second review iteration on this PR? |
0bb4209 to
e05aae4
Compare
|
I didn't really do a first pass, just looked at the part from the PR description that sounded like it could be improved. I'd be happy to review this PR but can't really commit to doing so promptly. |
|
|
||
| let with_info ~native ~tool_name ~source_file ~output_prefix ~dump_ext k = | ||
| let with_info | ||
| ~native ~tool_name ~source_file ~source_kind ~output_prefix ~dump_ext k = |
There was a problem hiding this comment.
I have a small interrogation, with the new source_kind this is the third argument that we pass to with_info which is only used to construct an Unit_info.t. Do we want to group together those arguments in a single unit_info argument.
There was a problem hiding this comment.
That seems reasonable, I will give it a go, we can always revert later if we're not satisfied.
804be40 to
6c63c83
Compare
6c63c83 to
95feea4
Compare
Octachron
left a comment
There was a problem hiding this comment.
I agree that keeping the kind of the current unit is useful information in general, even more so if it helps keeping uid unique.
The PR is ready to merge from my point of view.
Since some uids are equal between interfaces and implementations, they are missing from the results until PR ocaml#13286 is merged.
This reverts commit a493ee2.
Since some uids are equal between interfaces and implementations, they are missing from the results until PR ocaml#13286 is merged.
This actually make Uids unique accros a compilation unit made of an interface and an implementation.
5efdc1e to
eefe479
Compare
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information.
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information. sq
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information. sq
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information. sq
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information.
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information.
[tooling] Distinct uids for interfaces There should be a cleaner way to store the additional information. Upstream this info is part of a `Unit_info.t` record that is stored as the "current unit" in the environement. But here in flambda-backend it is `Compilation_unit.t` instead. This looks like conflicting refactorings that it would be useful to reconcile. Here, for the prototype, we use a tuple to add that information.
* Merge pull request ocaml#13286 from voodoos/distinct-uids-for-interfaces [tooling] Distinct uids for interfaces * Merge pull request ocaml#13308 from voodoos/link-declarations [tooling] Remember linked declarations * Store declaration dependencies in CMS files * Backport directionality fix from upstream ocaml#13956 * Undo format change
Uids are supposed to be unique inside a compilation unit. But if we consider that a compilation unit is made of an interface file and an implementation file, then this is not actually true: declarations are numbered with uids starting from 0 in both the interface and the implementation. This can be a source of confusion for external tools such as Merlin or the occurrences indexer.
This PR proposes annotating uids with their origin (Impl of Intf). To make the change less invasive I used a reference that defaults to
Impland is switched toIntfwhenTypemod.type_interfaceis called.Additionally, to make the testsuite more stable, commit 238d54f sorts the declarations in ocamlobjinfo's printing... This is a noisy commit that should make future changes less noisy. Reviewing commit-by-commit should filter the noise.
This change is important for a PR that I plan to open soon that generalizes the
cmt_format.cmt_value_dependenciesfield so that external tools can keep track of dependencies between declarations. This will allow Merlin to jump betweenmlandmlifiles, have the project-wide occurrences feature also return declarations, etc.Pinging the people who were involved in the recent indexing work: @Octachron @gasche
CC @lpw25