Skip to content

Conversation

@jberdine
Copy link
Contributor

src/ppx_blob.ml Outdated
Comment on lines 4 to 9
let dirname =
let loc_fname = loc.Location.loc_start.pos_fname in
if Filename.is_relative loc_fname then
Filename.dirname (Filename.concat (Sys.getcwd ()) loc_fname)
else Filename.dirname loc_fname
in
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremiedimino, is there a better replacement for Location.absolute_path that is exposed by Ppxlib?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked in details, but Location.absolute_path might be a good candidate for addition in ppxlib. Could you open a ticket on github.com/ocaml-ppx/ppxlib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

Copy link
Contributor

@kit-ty-kate kit-ty-kate Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let dirname =
let loc_fname = loc.Location.loc_start.pos_fname in
if Filename.is_relative loc_fname then
Filename.dirname (Filename.concat (Sys.getcwd ()) loc_fname)
else Filename.dirname loc_fname
in
let dirname = Ocaml_common.Location.absolute_path loc.Ocaml_common.Location.loc_start.pos_fname |> Filename.dirname in

Would using Ocaml_common temporarily solve the issue?

@bbc2
Copy link
Collaborator

bbc2 commented Sep 14, 2020

Thank your for your work on the migration. Is it supposed to supersede your other PR (#19)?

One problem I've found is that with this new code, a file that's not found by ppx_blob leads to an uncaught exception ("Fatal error" with stack trace), whereas it used to trigger a regular compilation error.

@jberdine
Copy link
Contributor Author

@bbc2, this could supercede #19, but this is a larger change and perhaps there are other uses which need a less abrupt migration, in which case #19 is maybe useful. In particular, it is a minimal change to unblock some uses of new features in code bases using ppx_blob, while this port is less pressing.

I was not anticipating the change in exception behavior. Do you have a backtrace you could share here?

@bbc2 bbc2 self-assigned this Sep 15, 2020
@bbc2
Copy link
Collaborator

bbc2 commented Sep 15, 2020

Here's a backtrace:

> dune build @check
         ppx blob_error.pp.ml (exit 2)
(cd _build/default && .ppx/c3461e88ae1503d575d582eb5874e916/ppx.exe -o blob_error.pp.ml --impl blob_error.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
Fatal error: exception [%blob] could not find or load file data.txt
Raised at file "src/ppx_blob.ml", line 21, characters 4-135
Called from file "src/ppx_blob.ml", line 28, characters 35-60
Called from file "src/ast_pattern_generated.ml", line 612, characters 27-42
Called from file "src/ast_pattern_generated.ml", line 2659, characters 27-42
Called from file "src/ast_pattern.ml", line 73, characters 14-29
Called from file "src/ast_pattern.ml", line 133, characters 53-71
Called from file "src/ast_pattern.ml", line 11, characters 6-31
Called from file "src/extension.ml", line 181, characters 12-66
Called from file "src/context_free.ml", line 236, characters 10-44
Called from file "src/context_free.ml", line 460, characters 10-81
Called from file "src/context_free.ml", line 511, characters 59-74
Called from file "src/list.ml", line 387, characters 13-17
Called from file "src/list.ml" (inlined), line 418, characters 15-31
Called from file "src/context_free.ml", line 511, characters 17-90
Called from file "src/ast_traverse.ml", line 117, characters 19-34
Called from file "list.ml", line 92, characters 20-23
Called from file "ast/ast.ml", line 5521, characters 22-31
Called from file "ast/ast.ml", line 5508, characters 26-50
Called from file "src/context_free.ml", line 636, characters 23-42
Called from file "src/driver.ml", line 185, characters 17-30
Called from file "src/driver.ml", line 395, characters 16-19
Called from file "list.ml", line 121, characters 24-34
Called from file "src/list0.ml" (inlined), line 21, characters 22-52
Called from file "src/driver.ml", line 385, characters 2-642
Called from file "src/driver.ml", line 482, characters 4-244
Called from file "src/migrate_parsetree_driver.ml", line 249, characters 21-60
Called from file "src/migrate_parsetree_driver.ml", line 255, characters 4-82
Called from file "src/driver.ml", line 893, characters 53-82
Called from file "src/driver.ml", line 1292, characters 6-24
Re-raised at file "parsing/location.ml", line 925, characters 14-25
Called from file "src/driver.ml", line 1295, characters 4-59
Called from file ".ppx/c3461e88ae1503d575d582eb5874e916/_ppx.ml", line 1, characters 9-36
Done: 5/10 (jobs: 1)⏎                                                                                                                   
let () = print_string ([%blob "data.txt"])
  • Dune 2.7.0
  • OCaml 4.10.0

@kit-ty-kate
Copy link
Contributor

Any news on this? This would be really nice to have with the upcoming OCaml 4.12 release, as OCaml 4.13 will probably not support ocaml-migrate-parsetree < 2.0 and this complicates package compatibility between opam packages otherwise.

@kit-ty-kate
Copy link
Contributor

I fixed the uncaught exception issue and opened a PR on @jberdine's fork here: jberdine#1
With this fix, the code now works the same way as previously when encountering non-existing files:

$ dune build @runtest @check
File "example/quine.ml", line 1, characters 13-30:
1 | print_string [%blob "quine.m"]
                 ^^^^^^^^^^^^^^^^^
Error: [%blob] could not find or load file quine.m

@bbc2
Copy link
Collaborator

bbc2 commented Nov 24, 2020

Thank you all for all the help! I've rebased the commits and removed the intermediate merge commit. I've added CI tests to make it easier to detect potential issues. I'll merge and release a new version as soon as CI is green.

@bbc2 bbc2 merged commit e2f4534 into johnwhitington:master Nov 24, 2020
bbc2 added a commit to bbc2/opam-repository that referenced this pull request Nov 24, 2020
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 this pull request may close these issues.

Port ppx_blob to ppxlib

3 participants