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

Move ocaml index #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
labels:
- no changelog
4 changes: 2 additions & 2 deletions .github/workflows/emacs-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
EMACS_PACKAGE_LINT_IGNORE: ${{ matrix.package_lint_ignore }}
EMACS_BYTECOMP_WARN_IGNORE: ${{ matrix.bytecomp_warn_ignore }}
steps:
- uses: purcell/setup-emacs@master
- uses: purcell/setup-emacs@v6.0
with:
version: ${{ matrix.emacs_version }}

- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run tests
run: 'cd emacs && ./check.sh'
26 changes: 13 additions & 13 deletions .github/workflows/fuzzy-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
echo "version=$v" | tee -a $GITHUB_OUTPUT

- name: Install OCaml
uses: ocaml/setup-ocaml@v2
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ steps.compiler.outputs.version }}
dune-cache: true
Expand All @@ -105,7 +105,7 @@ jobs:
opam exec -- dune install -p merlin-lib,dot-merlin-reader,merlin

- name: Pull irmin and its deps from cache if possible
uses: actions/cache@v3
uses: actions/cache@v4
id: irmin-cache
with:
path: irmin/
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
working-directory: irmin

- name: Pull merl-an from cache if possible
uses: actions/cache@v3
uses: actions/cache@v4
id: merl-an-cache
with:
path: /usr/local/bin/merl-an
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
run: echo "name=$${{ matrix.commit }}_artifact_name" >> $GITHUB_OUTPUT

- name: Upload data
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact_name.outputs.name }}
path: ${{ env.data_dir }}
Expand All @@ -217,7 +217,7 @@ jobs:

- name: Upload diff tool
if: ${{ matrix.commit == 'merge_branch' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: diff_tool
path: create_diff
Expand All @@ -234,13 +234,13 @@ jobs:
diff_dir: diff
steps:
- name: Download base branch data
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.BASE_BRANCH_ARTIFACT_NAME }}
path: ${{ env.base_data_dir }}

- name: Download merge branch data
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.MERGE_BRANCH_ARTIFACT_NAME }}
path: ${{ env.merge_data_dir }}
Expand All @@ -249,7 +249,7 @@ jobs:
run: mkdir -p "$diff_dir"

- name: Download diff tool
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: diff_tool

Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:
| ./create_diff "--input-separator--" "--diff-cmd-separator--" "$diff_dir/$DISTILLED_DIFF_FILE"

- name: Upload diff(s)
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.DIFF_ARTIFACT_NAME }}
path: ${{ env.diff_dir }}
Expand All @@ -312,7 +312,7 @@ jobs:

- name: Download current diff(s)
if: ${{ env.current_diff_exists == 'true' }}
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.DIFF_ARTIFACT_NAME }}

Expand Down Expand Up @@ -370,7 +370,7 @@ jobs:

- name: Upload instruction to delete label
if: ${{ env.earlier_diff_was_approved == 'true' && steps.approved_diff.outputs.hash != steps.current_diff.outputs.hash }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: forwarded_instructions
path: forward/
Expand Down Expand Up @@ -453,7 +453,7 @@ jobs:

- name: Upload instruction to delete label
if: ${{ steps.diff_metadata.outputs.exists == 'false' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: forwarded_instructions
path: forward/
Expand Down Expand Up @@ -498,7 +498,7 @@ jobs:
'{instruction: $instruction, endpoint: $endpoint, artifacts_url: $artifacts_url, hash: $hash}' > ./forward/instruction.json

- name: Upload instruction to comment on PR
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: forwarded_instructions
path: forward/
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ jobs:
uses: actions/checkout@v4

- name: Set-up OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Install dependencies
run: |
opam depext conf-jq --yes # opam depext bug
opam pin menhirLib 20201216 --no-action
opam install --yes ppx_string ppx_compare
opam install . --deps-only --with-test --yes

- name: Build and test in release mode (windows)
if: matrix.os == 'windows-latest'
run: |
opam exec -- dune runtest -p merlin-lib,dot-merlin-reader,merlin
opam exec -- dune runtest -p merlin-lib,dot-merlin-reader,ocaml-index,merlin

- name: Build and test in release mode (macos/linux)
if: matrix.os != 'windows-latest'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: nix
uses: cachix/install-nix-action@v21
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- run: nix develop -c dune build @check @runtest -p merlin-lib,dot-merlin-reader,merlin
- run: nix develop -c dune build @check @runtest -p merlin-lib,dot-merlin-reader,ocaml-index,merlin
5 changes: 2 additions & 3 deletions .github/workflows/ocaml-lsp-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
uses: ocaml/setup-ocaml@v3
with:
# Version of the OCaml compiler to initialise
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Check that Merlin and OCaml-LSP are co-installable
run: |
opam depext conf-jq # opam depext bug
opam --cli=2.1 pin --with-version=dev --no-action https://github.com/voodoos/ocaml-lsp.git#5.2-preview
opam --cli=2.1 pin --with-version=5.0-502 --no-action .
opam install ocaml-lsp-server --with-test --ignore-constraints-on=ocamlformat
Expand Down
2 changes: 1 addition & 1 deletion merlin-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build: [
]
depends: [
"ocaml" {>= "5.2" & < "5.3"}
"dune" {>= "2.9.0"}
"dune" {>= "3.0.0"}
"csexp" {>= "1.5.1"}
"menhir" {dev & >= "20201216"}
"menhirLib" {dev & >= "20201216"}
Expand Down
3 changes: 0 additions & 3 deletions merlin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,3 @@ See https://github.com/OCamlPro/opam-user-setup
"
{success & !user-setup:installed}
]
pin-depends: [
["ocaml-index.1.0" "git+https://github.com/voodoos/ocaml-index#82b08987921884daeeb5dccc345a2dcb667fe113"]
]
33 changes: 33 additions & 0 deletions ocaml-index.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A tool that indexes value usages from cmt files"
description:
"ocaml-index should integrate with the build system to index codebase and allow tools such as Merlin to perform project-wide occurrences queries."
maintainer: ["[email protected]"]
authors: ["[email protected]"]
license: "MIT"
homepage: "https://github.com/ocaml/merlin/ocaml-index"
bug-reports: "https://github.com/ocaml/merlin/issues"
depends: [
"dune" {>= "3.0.0"}
"ocaml" {>= "5.2"}
"merlin-lib" {>= "5.1-502"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"--promote-install-files=false"
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
["dune" "install" "-p" name "--create-install-files" name]
]
dev-repo: "git+https://github.com/ocaml/merlin.git"
10 changes: 10 additions & 0 deletions src/ocaml-index/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1.0 (2024-06-18)
----------------

### Added

- Initial release.
- The `aggregate`` command that finishes reduction of shapes in cmt files and
store the output in a single index file.
- The `stats` command that prints information about an index file.
- The `dump` command that prints all locs of an index.
62 changes: 62 additions & 0 deletions src/ocaml-index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ocaml-index

Ocaml-index is a tool that indexes values from CMT files. Its current purpose is
to provide project-wide occurrences for OCaml codebases. The tool iterate on
given cmt's occurrences list (`cmt_ident_occurrences`) and determines the
definition of every value found in it. It then write an index to disk where
values corresponding to the same definition are grouped together. The tool can
also take multiple input files, index them and merge the results into a single
index.

# Usage

## Process cmt files and merge indexes


> ocaml-index aggregate [-o _output_file_] _cmt_file_ ... _index_file_ ... [-I _dir_] ... [--no-cmt-load-path]


- Input `cmt` files are indexed and merged into the final output
- Input index files are directly merged into the output
- If no input files is provided an empty index is created
- The default output file name is `project.ocaml-index`

### Load path:
Identifying definitions while processing `cmt` files may require loading any of
the `cmt` files of every transitive dependency of the compilation unit. By
default the `cmt_load_path` of the first input `cmt` file will be used to search
for these other units. One can add more paths to the load path using the `-I`
option. Usage of the cmt's loadpath can be disabled using the
`--no-cmt-load-path` option.

### Paths:
By default, the paths stored in the cmt's locations are relative to the
directory where the compiler was called. for build systems that do not always
call the compiler from the same root folder it might be useful to rewrite these
paths.

Using the `--root <path>` option stores the given path in the output file.
Additionally, the ` --rewrite-root` option will prepend `root` to all paths in
indexed location.

[Note: this feature is not used in the reference Dune rules, it might evolve in
the future if needed]

## Querying indexes

The tool does not provide actual queries but one can dump an entire index:

> ocaml-index dump _index_file_ ...

Or only print the number of definitions it stores:

> ocaml-index stats _index_file_ ...

```bash
$ ocaml-index stats _build/default/src/dune_rules/.dune_rules.objs/cctx.ocaml-index
Index ".../cctx.ocaml-index" contains:
- 28083 definitions
- 86850 locations
- 0 approximated definitions
- 0 compilation units shapes
```
9 changes: 9 additions & 0 deletions src/ocaml-index/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(executable
(name ocaml_index)
(public_name ocaml-index)
(package ocaml-index)
(libraries lib ocaml_typing merlin_index_format)
(flags
:standard
-open Ocaml_typing
-open Merlin_index_format))
Loading
Loading