Some tests break with ppx_deriving.6.1.2 - #87
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andinclude (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.