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

Are there size limits on the binary ast as produced by --dump-ast? #39

Closed
rleonid opened this issue Feb 13, 2018 · 6 comments
Closed

Are there size limits on the binary ast as produced by --dump-ast? #39

rleonid opened this issue Feb 13, 2018 · 6 comments

Comments

@rleonid
Copy link

rleonid commented Feb 13, 2018

I'm running to a weird bug that is resolved by removing that argument and compiling from the generated source.

@rleonid rleonid changed the title Are there size limits on the binary ast Are there size limits on the binary ast as produced by --dump-ast? Feb 13, 2018
@ghost
Copy link

ghost commented Feb 13, 2018

I think it's quite large, what error are you getting?

@rleonid
Copy link
Author

rleonid commented Feb 13, 2018

The concrete error is

File "_none_", line 1:
Error: Unbound value Nativeint
Hint: Did you mean nativeint?

when compiling the branch in this PR. For context I'm using a ppx and cppo to generate [mono|di]morphic higher level functions (ex. fold_left, map ...) for Bigarrays (Array1.t's in the current work). I've manually compiled the code successfully without that flag against the generated code (it is 47700 lines) that I grabbed with -dsource so something seems fishy.

Maybe this should be filed under dune but is there a way to have dune omit this flag and go the slower text route? I'm fine with special casing a custom pp'ing rule?

@ghost
Copy link

ghost commented Feb 13, 2018

The error doesn't look right, it should be something like Unbound constructor Nativeint or Unbound module Native, but not Unbound value since it is syntactically not possible to write an identifier starting with a capital letter.

My guess is that the generated AST is wrong, however when pretty printed, the printer prints something that ends up being valid OCaml code.

--dump-ast is necessary, it is the default mode for ppx rewriters. It means the the output will be a marshaled Parsetree.structure/signature value rather than source code. This has two advantages:

  • it should be faster since you don't do the parsing twice
  • locations are preserved, so errors and backtraces point to the right place in the original code rather than somewhere in the generated code that the user cannot see

@rleonid
Copy link
Author

rleonid commented Feb 13, 2018

You were right, I was initially deceived into thinking that the ppx was correct because it worked for many other kinds and then started breaking with Nativeint. Thank you.

@rleonid rleonid closed this as completed Feb 13, 2018
@ghost
Copy link

ghost commented Feb 13, 2018

No problem. One way to make it easier to debug such errors would be to extend the invariants checks that are performed by the compiler to also check identifiers:

https://github.com/ocaml/ocaml/blob/trunk/parsing/ast_invariants.mli

@rleonid
Copy link
Author

rleonid commented Feb 13, 2018

Thanks again, that's super helpful. I did not know about them.

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

No branches or pull requests

1 participant