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

Subsystem versioned #937

Merged
merged 21 commits into from
Jul 3, 2018
Merged

Subsystem versioned #937

merged 21 commits into from
Jul 3, 2018

Conversation

rgrinberg
Copy link
Member

Fix #909

This is still WIP because I should really be saving the syntax version rather than the Jbuild vs. Dune version in the Info files. But this PR is still useful for initial review.

One thing that I'm wondering about is we should still generate the per subsystem versions in syntax (1, 0). Seems like jbuilder will not be able to load .dune files generated by dune anyway because of that initial 2.0 language.

@rgrinberg rgrinberg requested a review from a user July 1, 2018 16:24
@ghost
Copy link

ghost commented Jul 1, 2018

One thing that I'm wdering about is we should still generate the per subsystem versions in syntax (1, 0). Seems like jbuilder will not be able to load .dune files generated by dune anyway because of that initial 2.0 language.

When the sub-system is defined in a jbuild file, dune should generate dune 1 files. Otherwise it's not going to work for the released versions of ppx_inline_test, ppx_expect, ppxlib, etc...

@ghost
Copy link

ghost commented Jul 1, 2018

Actually I see that this is what is implemented by this PR

| acc ->
begin match (Sexp.Lexer.token lexbuf : Sexp.Lexer.Token.t) with
| Eof ->
Loc.fail (Loc.in_file (Path.to_string fname)) "%s" bad_dune_file
Copy link

Choose a reason for hiding this comment

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

You can return List.rev acc, the error will be caught by the match loop [] with ....

@ghost
Copy link

ghost commented Jul 1, 2018

This is still WIP because I should really be saving the syntax version rather than the Jbuild vs. Dune version in the Info files.

That seems right.

BTW, thinking about this again, where we read:

(dune
 2
 ((inline_tests.backend
   X.Y

we could set the M.syntax value of the subsystem to version X.Y since this is what we do when we generate the file.

@ghost
Copy link

ghost commented Jul 1, 2018

And we set it to (0, 0) when the file start with (dune 1 ...

@@ -39,8 +39,9 @@ module Gen(P : Install_params) = struct
let gen_lib_dune_file lib =
SC.add_rule sctx
(Build.arr (fun () ->
let lang = Option.value_exn (Lib.defined_using_lang lib) in
Format.asprintf "%a@." (Sexp.pp Dune)
Copy link

Choose a reason for hiding this comment

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

s/Dune/lang/

in
Sexp.Of_sexp.parse of_sexp
(Univ_map.singleton (Syntax.key Stanza.syntax) syntax)
(Io.Sexp.load ~lexer ~mode:Single fname))
Copy link

Choose a reason for hiding this comment

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

We shouldn't reopen the file a second time here. We need to construct a lexer function that first return the three extracted token and then switch to the real lexer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not really sure how to do it the way you say however. Seems like we'd need to call parser with an initial set of lexemes (the 3 lexemes that we already parsed).

What should be possible is just reading the file into a string and then constructing the lexer from_string a second time. That should cut down on the sys calls.

Copy link

@ghost ghost Jul 2, 2018

Choose a reason for hiding this comment

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

There are two ways of doing it:

first one:

let pending_tokens = ref ... in
let lexer lb =
  match !pending_tokens with
  | [] -> lexer lb
  | x :: l -> pending_tokens := l; x
in
...

second one, which implements all the logic in one function:

let state = ref 0 in
let lexer = ref !Sexp.Lexer.token in
let lexer lb =
  let token = !lexer lb in
  (match !state, token with
   | 0, Lparen -> state := 1
   | 1, Atom (A "dune") -> state := 2
   | 2, Atom (A "1") -> state := 3; lexer := Sexp.Lexer.jbuild_token
   | 2, Atom (A "2") -> state := 3;
   | 2, Atom (A s) -> error ()
   | 3, _ -> ()
   | _ -> error ());
  token
in

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. I went for the first approach. Did not it was allowed to reuse the same state between possibly different lexer functions like this.

Copy link

Choose a reason for hiding this comment

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

Ok. After reading this again, it seemed to me that the second version was clearer as all the logic is more self-contained, so I rewrote it using the second version.

@rgrinberg
Copy link
Member Author

rgrinberg commented Jul 2, 2018 via email

@ghost
Copy link

ghost commented Jul 2, 2018

BTW, should we just save the whole parsing context in libraries?

@rgrinberg
Copy link
Member Author

Do you see other uses for it? I'd rather have Jbuild.Library.t abstract away the parsing related details kind of like Lib.Info.t abstracts away the source of libraries when making a Lib.t.

@rgrinberg
Copy link
Member Author

we could set the M.syntax value of the subsystem to version X.Y since this is what we do when we generate the file.

Sorry, this might be obtuse but isn't this done already? The X.Y in your example is a sub system version.

@ghost
Copy link

ghost commented Jul 2, 2018

Do you see other uses for it? I'd rather have Jbuild.Library.t abstract away the parsing related details kind of like Lib.Info.t abstracts away the source of libraries when making a Lib.t.

Maybe when we switch to dune-package, but not for now. Happy to leave it as it for now.

Sorry, this might be obtuse but isn't this done already? The X.Y in your example is a sub system version.

If I read the code correctly, currently we set only Stanza.syntax to either (0, 0) or (1, 0). I suggest that we additionally set M.syntax to X.Y when parsing (dune 2 files.

@rgrinberg
Copy link
Member Author

I see, thanks for clarifiyng. Why only for dune 2 files however? We don't hide the syntax version when parsing other sexps that comes from jbuild files.

@ghost
Copy link

ghost commented Jul 2, 2018

I see, thanks for clarifiyng. Why only for dune 2 files however? We don't hide the syntax version when parsing other sexps that comes from jbuild files.

Because in dune 1 files the version of sub-systems is set to 1.0, and M.syntax is Stanza.syntax for the inline tests and ppx driver subsystems, so we'd be setting Stanza.syntax to 1.0 instead of 0.0.

@rgrinberg
Copy link
Member Author

@diml I tried doing this in my last commit. I admit that I'm not fully confident about my change however.

@ghost
Copy link

ghost commented Jul 2, 2018

That looks fine, we just a comment in the code explaining why we do this

@rgrinberg
Copy link
Member Author

@diml added a comment

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This will be necessary for some manual parsing

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
We read the first 3 tokens of a dune file and use it recognize if the file was
generated using jbuilder or dune

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This field is necessary to know how to generate .dune files for a particular
library.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Reuse the same lexer by pushing back some tokens manually

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
…tems

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
(match dune_version with
| (0, 0) -> "1"
| (1, 0) -> "2"
| _ ->
Copy link

Choose a reason for hiding this comment

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

Not sure we should be that strict. In practice, it's likely that we'll be increasing the version of the dune language often. In version 2 files, the exact version is saved in each sub-system, so we can accept any version >= 1.0 here.

src/stanza.ml Outdated
type t = Sexp.syntax = Jbuild | Dune

let of_syntax = function
| (0, 0) -> Jbuild
Copy link

Choose a reason for hiding this comment

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

Even though we are not going to release another version of jbuilder, we should write (0, _) here (it's slightly clearer IMO)

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
in
Sexp.Of_sexp.parse of_sexp
(Univ_map.singleton (Syntax.key Stanza.syntax) syntax)
Sexp.Of_sexp.parse of_sexp Univ_map.empty
Copy link
Member Author

Choose a reason for hiding this comment

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

How come you aren't passing the version in the parsing context?

Copy link

Choose a reason for hiding this comment

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

It is passed in of_sexp

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@rgrinberg
Copy link
Member Author

@diml the last commit relax the version checks I had before.

@rgrinberg rgrinberg merged commit 9a605b9 into ocaml:master Jul 3, 2018
@rgrinberg rgrinberg deleted the subsystem-versioned branch July 3, 2018 11:59
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