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

Match compilers dummy loc #540

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

patricoferris
Copy link
Collaborator

A fix as per #532.

I tested reverse dependencies (I think most of them, for their latest version) and they mostly installed --with-test. Any that didn't seemed unrelated.

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Looks good to me!

This probably needs a changelog entry!

@NathanReb
Copy link
Collaborator

Seems some tests need to be updated as well!

@NathanReb
Copy link
Collaborator

Also, rebasing it will reduce the diff as the quoter tests don't print out the whole AST anymore!

@patricoferris patricoferris force-pushed the match-compilers-dummy-loc branch 2 times, most recently from a4e858c to 4aad4e6 Compare November 26, 2024 14:43
@patricoferris
Copy link
Collaborator Author

Turns out this actually changed in OCaml compiler versions, so this is not the proper fix.

The fix might be fairly easy (using Cinaps) but the problem becomes all of the expect tests. And whilst we could in theory do the [%%expect_in] stuff I think our tests become less and less useful the longer they get and they're filled with none locations. It would be great to run Toploop.execute_phrase and then parse values and use Pp_ast on them... Any ideas @NathanReb ?

@NathanReb
Copy link
Collaborator

I guess we could use [%%ignore] here, similar to what I did for the Quoter tests:

let x = [%expr ...]
[%%ignore]

let () = Pp_ast.Default.expression x
[%%expect {|
...
|}]

Would that work for you?

@patricoferris patricoferris force-pushed the match-compilers-dummy-loc branch 2 times, most recently from f1bcf8d to 5936109 Compare November 28, 2024 00:22
In OCaml 4.08 the dummy position was changed to have a pos_lnum of 0
instead of 1. We need to match whatever the compiler is using.

Signed-off-by: Patrick Ferris <[email protected]>
@patricoferris
Copy link
Collaborator Author

It actually turns out I don't need that @NathanReb -- the files are only enabled for new enough compilers that it doesn't matter. But it is good to have that trick up my sleeve should we need it. Happy to make that change here to help future proof these tests (but I don't think it is likely for those bits to change too much).

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

If I understood the issue correctly, the important part is to agree with the compiler on what is Location.none right?

If so then we could probably simply stick to using the compiler's functions to build none locs.

This won't work when reading AST emitted by a different compiler (which we in theory support) but even that could be fixed by versioning the none loc.

As I'm writing this I wonder if the right fix isn't the following:

  1. Stick to having our stable Location.none and choose a convention for it
  2. Have a function that detects whether a location is a valid none loc from any version we support
  3. Use the function from 2 instead of poly = in our codebase

What do you think?

@@ -52,6 +52,10 @@ val set_input_lexbuf : Lexing.lexbuf option -> unit
val none : t
(** An arbitrary value of type [t]; describes an empty ghost range. *)

val dummy_pos : Lexing.position
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we should expose this as Astlib is supposed to represent the minimum stable API we'd need from the compiler and it seems that something like in_file would be enough here wouldn't it?

@@ -8,7 +8,7 @@ type t = location = {
}

let in_file name =
let loc = { pos_fname = name; pos_lnum = 1; pos_bol = 0; pos_cnum = -1 } in
let loc = { L.dummy_pos with pos_fname = name } in
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is equivalent to the compiler's in_file. If we used it instead, we wouldn't need the cinaps bits for dummy_pos anymore.

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.

2 participants