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

render runtime crates from templates dynamically #962

Conversation

OmarTawfik
Copy link
Contributor

@OmarTawfik OmarTawfik commented May 14, 2024

Closes #863

  • The entirety of "runtime" codegen is now following a strict MVC model, and the source code is rendered from the same model object. We should be able to further improve/refactor this model object in Migrate the parser to the language definition v2 #638
  • Complex model construction can be strongly-typed in Rust, while rendering is left to templates, as they are much easier to read and modify, and also have powerful macros/imports/callbacks, etc...
  • I also (partially) improved the DX when working with templates in terminal, by rendering their errors as an ariadne report, with best-guess source location in the template. A temporary workaround waiting for error locations and IDE diagnostics support Keats/tera#885
  • Now both stubs and output crates are rendered from the same source templates, removing a few internal hacks and the need for ![allow(dead_code)] and ![allow(unused)] everywhere (will follow up on this cleanup separately).
  • We no longer have to maintain explicit paths and copy files around in the code generator. All templates generate their output file relative to their location, which means we can split and refactor code into as many templates/sub-modules as needed, following standard rust idioms.

Copy link

changeset-bot bot commented May 14, 2024

⚠️ No Changeset found

Latest commit: 93e7e09

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@OmarTawfik OmarTawfik force-pushed the render-runtime-crates-from-templates-dynamically branch from f4fa57c to a448767 Compare May 14, 2024 05:21
@OmarTawfik OmarTawfik force-pushed the render-runtime-crates-from-templates-dynamically branch from a448767 to 93e7e09 Compare May 14, 2024 05:42
@OmarTawfik OmarTawfik marked this pull request as ready for review May 14, 2024 08:32
@OmarTawfik OmarTawfik requested a review from a team as a code owner May 14, 2024 08:32
@OmarTawfik OmarTawfik enabled auto-merge May 14, 2024 08:33
Copy link
Contributor

@AntonyBlakey AntonyBlakey May 14, 2024

Choose a reason for hiding this comment

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

#930 removes grammar queries, and hence this file and others like it, completely.

@OmarTawfik OmarTawfik added this pull request to the merge queue May 14, 2024
Merged via the queue into NomicFoundation:main with commit 874039b May 14, 2024
1 check passed
@OmarTawfik OmarTawfik deleted the render-runtime-crates-from-templates-dynamically branch May 14, 2024 09:57
github-merge-queue bot pushed a commit that referenced this pull request May 22, 2024
Part of #638, removes the `codegen_grammar` crate

Instead of having the definitions and the parser generation separate, we
now co-locate this and provide a parser-specific model (for MVC
rendering introduced in #962) for the code generation. This mostly moves
code around and documents a bit more what we already have.

This is fairly non-controversial and I am for #638 to be incremental, so
this is meant to progress the issue rather than fix it in one giant PR
to keep up the velocity and land it as soon as possible, accounting for
my upcoming move to Hardhat soon. If this generally makes sense, I'd
love to have a rubber stamp for it; for now, I'll work on top of this to
further migrate off DSLv1 definitions.
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.

refactor runtime crate into separate templates
2 participants