Skip to content

Some tests break with ppx_deriving.6.1.2 - #87

Merged
fantazio merged 1 commit into
LexiFi:masterfrom
fantazio:ppx_deriving
Jul 11, 2026
Merged

Some tests break with ppx_deriving.6.1.2#87
fantazio merged 1 commit into
LexiFi:masterfrom
fantazio:ppx_deriving

Conversation

@fantazio

@fantazio fantazio commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

ppx_deriving generated code used to have a dummy location, which is a loc_ghost. Thus, its content was not tracked by the analyzer.
Since ocaml-ppx/ppx_deriving#297, it holds more coherent locations (the one of the ppx-ed type_decl). Because the generated code is basically an include (struct ... end) in .ml and include (sig ... end) in .mli, the included content appears inlined in cmi, and indistinguishable from user-written content at this place.

I don't think we need to worry too much about ppx generated code that gets reported (for now). I think its locations should always be loc_ghosts but it is not enforced, and, as a result, any ppx may lead to false positives. The best we can do is, when such a false positive appears, try and fix the concerned ppx to generate loc_ghosts.

ppx_deriving generated code used to have a dummy location, which is a
loc_ghost. Thus, its content was not tracked by the analyzer.
Since ocaml-ppx/ppx_deriving#297, it holds more
coherent locations (the one of the ppx-ed type_decl). Because the
generated code is basically an `include (struct ... end)` in .ml and
`include (sig ... end)` in .mli, the included content appears inlined in
cmi, and indistinguishable from user-written content at this place.

I don't think we need to worry too much about ppx generated code that
gets reported (for now). I think its locations should always be
loc_ghosts but it is not enforced, and, as a result, any ppx may lead to
false positives. The best we can do is, when such a false positive
appears, try and fix the concerned ppx to generate loc_ghosts.
@fantazio
fantazio merged commit f0787db into LexiFi:master Jul 11, 2026
5 checks passed
@fantazio fantazio added the tests label Jul 11, 2026
@fantazio
fantazio deleted the ppx_deriving branch July 15, 2026 08:46
sim642 pushed a commit to ocaml-ppx/ppx_deriving that referenced this pull request Jul 22, 2026
Following #297, some
generated code now have proper locations attached by using the
type_decl's location by default instead of a dummy one. However, because
the location is used as-is, the generated code is indistinguishable from
user code.
This leads to false positives in the dead_code_analyzer
(LexiFi/dead_code_analyzer#87).

According to [`Location`'s
documentation](https://ocaml.org/manual/5.5/api/compilerlibref/Location.html#TYPEt),
> loc_ghost=false whenever the AST described by the location can be
> parsed from the location. In all other cases, loc_ghost must be true.
> Most locations produced by the parser have loc_ghost=false.
> When loc_ghost=true, the location is usually a best effort approximation.

The dead_code_analyzer actually relies on this property to decide if an
element of code should be tracked or not.

Marking the generated code's default location with `loc_ghost=true`
fixes the false positives, without breaking the expected merlin behavior
mentioned in #297.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant