Dune: generated .merlin doesn't understand ppx_compare

Created on 23 Aug 2017  路  8Comments  路  Source: ocaml/dune

The generated .merlin for this jbuild produces the PKG ppx_compare.runtime-lib directive, but merlin needs PKG ppx_compare instead.

In particular, this line will generate a merlin error (Uninterpreted extension 'compare.equal'.):

let equal_foo = [%compare.equal : foo]
wontfix

All 8 comments

Note also that the FLG line in the gist contains lots of duplication:

FLG -open InferModules -g -short-paths -safe-string -principal -strict-formats -strict-sequence -bin-annot -w +3+5+6+8+10+11+12+18+19+20+21+23+26+29+27+32+33+34+35+37+38+39+50+52+57-4-9-40-41-42-45-48 -open InferStdlib -open IStd -open InferGenerated -g -short-paths -safe-string -principal -strict-formats -strict-sequence -bin-annot -w +3+5+6+8+10+11+12+18+19+20+21+23+26+29+27+32+33+34+35+37+38+39+50+52+57-4-9-40-41-42-45-48 -open InferStdlib -open IStd -open InferGenerated -open InferModules -g -short-paths -safe-string -principal -strict-formats -strict-sequence -bin-annot -w +3+5+6+8+10+11+12+18+19+20+21+23+26+29+27+32+33+34+35+37+38+39+50+52+57-4-9-40-41-42-45-48 -open InferStdlib -open IStd -open InferGenerated

Note that jbuilder will generate an appropriate FLG -ppx rather than a PKG ppx_compare directive. This is a really strange issue though, I just tried using ppx_compare in a minimal example and jbuilder generated a correct .merlin for me.

Are you able to use the generated compare functions at all? I.e. does jbuilder actually preprocess things correctly?

Yes the build is fine, the only thing going awry is the .merlin (see also #229 on the same project).

I just noticed that if I remove the last stanza from my jbuild, which is the only one without (preprocess (pps (ppx_compare))), then the .merlin does contain a FLG -ppx line:

FLG -ppx '/home/jul/infer/infer/src/_build/default/.ppx/ppx_compare/ppx.exe --as-ppx --cookie '\''library-name="InferModules"'\'''

However merlin still gives errors about extension points.

The main problem here is that the scope of a .merlin file is the whole directory. So when we have different build configurations in the same directory, jbuilder has to somehow merge them (function merge_two in src/merlin.ml). For library dependencies, it takes the union. For preprocessing specifications, it compares them and gives up if they are not equal.

However merlin still gives errors about extension points.

There were a lot of issues related to quoting, I believe it should work fine with the latest version of jbuilder and merlin.

The main problem here is that the scope of a .merlin file is the whole directory

Actually since https://github.com/ocaml/merlin/commit/cf93c20fe88006abd963c09fb7617c6ae78a61fa the scope could be the file instead of the directory.

Although generating a ton of .foo.merlin in the source directory might be a bit annoying.
However if something like https://github.com/ocaml/merlin/pull/712 ever lands (but I think merlin would have to look in <workspace-root>/_build/dir/ and not dir/_build it might actually be a decent option.

@diml , @let-def : any thoughts?

Although generating a ton of .foo.merlin in the source directory might be a bit annoying.

Yh, that doesn't seem right to me.

However if something like ocaml/merlin#712 ever lands (but I think merlin would have to look in /_build/dir/ and not dir/_build it might actually be a decent option.

Seems good, however for jbuilder it should be <workspace-root>/_build/default/dir

@trefis @let-def I suggest the following design which would shift the decision of how to organize the configuration to the user/build system: in .merlin files, allow:

GEN <command>

then to get the configuration for a file foo.ml, merlin would run <command> foo.ml which would be expected to output the merlin configuration for foo.ml.

I'm closing this as we're waiting for the obsoletion of .merlin files. It's highly unlikely that will work on this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erikmd picture erikmd  路  4Comments

Lelio-Brun picture Lelio-Brun  路  6Comments

rgrinberg picture rgrinberg  路  6Comments

bobot picture bobot  路  7Comments

inumanag picture inumanag  路  4Comments