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

Pexp_constraint expression locations are ghost #10554

Closed
aantron opened this issue Aug 5, 2021 · 1 comment · Fixed by #10555
Closed

Pexp_constraint expression locations are ghost #10554

aantron opened this issue Aug 5, 2021 · 1 comment · Fixed by #10555

Comments

@aantron
Copy link
Contributor

aantron commented Aug 5, 2021

Essentially, why are they ghost? Is this a bug?

This appears to be affecting Bisect_ppx (the coverage tool) in aantron/bisect_ppx#377 (comment). Here is a smaller example than in the issue:

let () =
  if true then
    (() : unit)
  else
    ()

with OCaml 4.12.0 and Bisect_ppx master (or any recent version), this gets instrumented as

Снимок

Note the lack of point on the expression in the then branch, which is suppressed by having () wrapped in a constraint expression. This is because Bisect currently deliberately avoids instrumenting expressions with ghost locations. If the contraint expression is removed, the remaining () will be instrumented, as expected by users, and as shown by the else branch.

The uninstrumented AST for this program:

[
  structure_item (foo.ml[1,0+0]..[5,47+6])
    Pstr_value Nonrec
    [
      <def>
        pattern (foo.ml[1,0+4]..[1,0+6])
          Ppat_construct "()" (foo.ml[1,0+4]..[1,0+6])
          None
        expression (foo.ml[2,9+2]..[5,47+6])
          Pexp_ifthenelse
          expression (foo.ml[2,9+5]..[2,9+9])
            Pexp_construct "true" (foo.ml[2,9+5]..[2,9+9])
            None
          expression (foo.ml[3,24+4]..[3,24+15]) ghost
            Pexp_constraint
            expression (foo.ml[3,24+5]..[3,24+7])
              Pexp_construct "()" (foo.ml[3,24+5]..[3,24+7])
              None
            core_type (foo.ml[3,24+10]..[3,24+14])
              Ptyp_constr "unit" (foo.ml[3,24+10]..[3,24+14])
              []
          Some
            expression (foo.ml[5,47+4]..[5,47+6])
              Pexp_construct "()" (foo.ml[5,47+4]..[5,47+6])
              None
    ]
]

The ghost on the location of the Pexp_constraint is in question in this issue.

I see a potentially related discussion in #1850.

cc @gkaracha @dorranh

@nojb
Copy link
Contributor

nojb commented Aug 5, 2021

Thanks for the report, this looks like a bug at first sight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants