Skip to content

Index all paths components - #13848

Merged
Octachron merged 5 commits into
ocaml:trunkfrom
voodoos:index-path-components
Mar 11, 2025
Merged

Octachron merged 5 commits into
ocaml:trunkfrom
voodoos:index-path-components

Conversation

@voodoos

@voodoos voodoos commented Mar 4, 2025 •

Copy link
Copy Markdown
Contributor

Now that we have comprehensive locations stored in longidents, we can add all occurences of modules appearing in paths to the cmt's index.

This will enable external tools to provide full support for modules in project-wide features such as listing occurrences and renaming. Right now, these are restricted to direct module usages.

This PR simply adds a loop during the indexing that iterats on longidents to reduce all associated sub-path's shapes. This process is not as expensive as it appears due to the global memoization of shape reduction in the compiler. In fact, I found no meaningful difference when timing the build of the compiler:

Edit: I just realised that my benchmarks are actually meaningless since the feature is not activated in the compiler builds, I will do new ones.

Edit2: Again, in the new benches, no remarkable performance impact:

Branch Command Mean [s] Min [s] Max [s] Relative
trunk make world.opt --jobs 16 && (cd testsuite && make all-shape-index) 54.181 ± 0.156 53.934 54.446 1.00
this pr make world.opt --jobs 16 && (cd testsuite && make all-shape-index) 54.255 ± 0.133 54.018 54.494 1.00

Cmt sizes increase from 51004 (bytes?) to 51272.

voodoos added 2 commits March 4, 2025 15:09
Now that we have locations for all longident components, we can add these to the index for tools to be able to provide project-wide occurrences and renaming of these modules.
@voodoos voodoos changed the title Index modules in paths Index all paths componnents Mar 4, 2025
@voodoos
voodoos force-pushed the index-path-components branch from 636bbb0 to 82f255c Compare March 4, 2025 16:33
@voodoos voodoos changed the title Index all paths componnents Index all paths components Mar 4, 2025
Approximated: Index_aliases.22 :
X.F (File "index_aliases.ml", line 48, characters 14-17)
Alias: Index_aliases.24 -> Alias: Index_aliases.23 -> Approximated: Index_aliases.22
:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That looks like a flaw in the printer.

Comment thread file_formats/cmt_format.ml Outdated
| Longident.Lapply (lid', lid''), Path.Papply (path', path'') ->
index_components module_ lid'' path'';
index_components module_ lid' path'
| _, _ ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would propose to keep the Lident _ case explicit to make the cases commutative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is 5384b57 what you had in mind ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not exactly, but I agree that expanding the non-diagonal case might be a mouthful, so I am fine with either this version or the previous one.

@Octachron Octachron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that extending the occurrence table to track all components of Longindent.t is reasonable. Moreover, since this is only enabled with the -bin-annot-occurences flag, the quick benchmark in the PR is enough as a performance sanity check.

Comment thread Changes Resolved
Comment thread file_formats/cmt_format.ml Outdated
| Longident.Lapply (lid', lid''), Path.Papply (path', path'') ->
index_components module_ lid'' path'';
index_components module_ lid' path'
| _, _ ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not exactly, but I agree that expanding the non-diagonal case might be a mouthful, so I am fine with either this version or the previous one.

@Octachron
Octachron merged commit e610c44 into ocaml:trunk Mar 11, 2025
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