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

revisit how snapshot works #348

Closed
nikomatsakis opened this issue Mar 23, 2018 · 6 comments
Closed

revisit how snapshot works #348

nikomatsakis opened this issue Mar 23, 2018 · 6 comments

Comments

@nikomatsakis
Copy link
Collaborator

nikomatsakis commented Mar 23, 2018

I was thinking about the LALRPOP snapshot. Now that we have revisions published on crates.io, it is annoying that we have to carry about lalrpop-snap. It would be nice if we could instead rely on an older, published version of lalrpop. The problem with that is that if we are not careful we quickly create a chain reaching very far back. It's also annoying that end users have to build lalrpop-snap.

I was considering an alternative:

Thoughts?

@Marwes
Copy link
Contributor

Marwes commented Mar 24, 2018

Finally, we modify build.rs so that when the generated code needs to be rebuilt, we run the lalrpop executable instead.

An alternative to this could be to make lalrpop-snap an optional dependency of lalrpop. That way it is possible to develop on LALRPOP without needing the executable installed. The downside is that one must pass --features lalrpop-snap to update the commited parser in the lalrpop crate.

@matklad
Copy link
Contributor

matklad commented Apr 2, 2018

For fall, I use a slightly more "worse as better" approach.

  1. commit generated code to the repository, so that no bootstrapping is needed for usual build.
  2. Don't have any build.rs. Instead, manually run (via shell script/justfile, or cargo run --bin bootstrap) parser generator on itself, when this is needed.
  3. As a part of test-suite, run the parser generator on itself to verify that the generated parser is fresh.

@nikomatsakis
Copy link
Collaborator Author

@matklad hmm, I could live with that.

@nikomatsakis
Copy link
Collaborator Author

Though I think it sounds maybe harder than what I suggested =)

@nikomatsakis
Copy link
Collaborator Author

@matklad but also, it seems like detecting a hash mismatch is pretty easy, so the build.rs could just look for that and error if found?

@matklad
Copy link
Contributor

matklad commented Apr 6, 2018

@nikomatsakis I am not entirely sure...

I think there's an important difference between other users of LALRPOP and LALRPOP bootstrapping process.

For other users, we need to rebuild if the hash of *.lalrpop file is changed.

For LALRPOP itself, there's an additional condition. Specifically, I think we'd love to make sure that bootstrapping has reached a fixed point: that is, if we generate code for lrgrammar.lalrpop by current LALRPOP, we should get exactly the same parser file, which is committed to the repository.

That means, we should potentially regenrate parser if either the grammar file is changed, or the code of lalrpop itself is changed.

Another thing to note is that the end users of LALRPOP don't actually need to execute LALRPOP's own build.rs script at all, because the generated code is committed to the repository. I wonder if we can add build.rs to ignored files in Cargo.toml, so that it is not uploaded to crates.io at all and is only used for local development. If this works, I think the following solution might work:

  1. commit the generated code to the repository, maintaining the invariant that it is exactly the same code that you would get by running lalrpop on itself.
  2. enforce the invariant via a test (I am not sure we can enforce it reliably implicitly, by writing a magical build.rs)
  3. write a build.rs file for LALRPOP developers, which regenrates the parser, using lalrpop from PATH or from target/debug/lalrpop, if the hash of lrgrammar.lalrpop is changed (and don't forget to println!("rerun-if-changed=src/parser/lrgramar.lalrpop") to avoid rebuilds by Cargo). This won't catch "I modified code gen" cases, but there's a test for that!
  4. exclude build.rs from Cargo.toml.

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

3 participants