Skip to content

Resilience to preprocessing #40

@fantazio

Description

@fantazio

Given a simple project architecture :

.
├── bin
│   ├── dune
│   └── main.ml
├── dune-project
├── lib
│   ├── bar.ml
│   ├── bar.mli
│   ├── dune
│   ├── foo.ml
│   └── foo.mli

with

$ cat lib/dune 
(library
 (name preprocessed)
 (preprocess (pps ppx_deriving.eq)))

$ cat lib/foo.ml 
type t = int
let x : t = 42
let y : t = 42

$ cat lib/foo.mli
type t = int
val x : t
val y : t

$ cat lib/bar.ml 
type t = int [@@deriving eq]
let x : t = 42
let y : t = 42

$ cat lib/bar.mli
type t = int [@@deriving eq]
val x : t
val y : t

$ cat bin/dune 
(executable
 (public_name preprocessed)
 (name main)
 (libraries preprocessed))

$ cat bin/main.ml 
let () =
  let open Preprocessed in
  if Bar.equal Bar.x Bar.x then
    print_int Preprocessed.Foo.x

The filenames found in locations in the signature (resp. structure) of .cmi (resp. .cmt) files point to lib/foo.mli and lib/bar.mli (resp. <filepath>.ml). The filenames found in the cmt_infos.cmt_sourcefile of the .cmti (and .cmt) file point to lib/foo.pp.mli and lib/bar.pp.mli (and <filepath>.pp.ml).

Using the .cmti files instead of .cmi files (as in #38), creates an incoherence when comparing the compilation units of the file being analyzed (foo.pp and bar.pp) and the locations found in the signature (foo or bar). Those inconsistencies lead to the not registering the declarations correctly (in DeadCommon.export), and, thus, to not reporting them.

Suggested solution

Fix Utils.unit to also remove the .pp extension. Use Utils.unit in File_infos.get_sourceunit. This way, the compilation unit will always be consistent and match the unpreprocessed one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions