-
Notifications
You must be signed in to change notification settings - Fork 25
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
Debug button to show Datalog AST #16
base: main
Are you sure you want to change the base?
Conversation
This seems interesting, I like my tools to be introspectable. It might be nice to have a 'view debug output' button somewhere on each cell to enable it without having to reload the page and lose edits. But first things first... I tried to run locally, but
|
|
That makes sense. How necessary is using the generated AST bindings to the functionality of the viewer? Personally, from a project simplicity perspective I would prefer to delay adding complex Makefiles (or any makefiles) as long as possible, and if not for this no changes to the project build would be required at all. |
I can move those commands into package.json scripts if you find that more palatable. |
I was able to get it working (with the old build system) and it looks pretty neat: It seems reasonable to merge, but I have some concerns. ekzhang may have a different view.
I can make these changes on your branch if you prefer. |
One of my eventual goals (per #18) is to publish the compiler to NPM; for that it would be good to provide typings for the AST. |
Very happy to have assistance placing a debug button somewhere and cleaning up the code formatting issues. Probably can't get to any fixes myself until next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I like the idea of having other kinds of code generation. I also learned something new today about generating TypeScript stubs from Rust types, that's interesting.
I think showing the AST is a cool idea but am not personally too keen on the patching and type generation magic. If the goal is to just be able to print show the Datalog AST in JavaScript code, I think it would make sense to add an ast()
method to the wasm component, but I'm less certain about the other parts:
- "Codegen JSON" seems like not really a necessary codegen module? It's just printing out the AST.
- Nothing prevents
codegen
->codegen_js
from happening in the future when it's necessary if there's ever a future codegen. - The type generation from Rust types, while nice, I don't think is immediately useful to this PR and is a bit complex.
I also think the AST view could just be a setting in the actual interface, not necessarily requiring you to set ?debug
in the URL.
…utton; remove Makefile; document how to generate TS types in ast.rs
I made a couple changes at @justjake's request:
I made a bit of a mess of the commits, but after getting my act together I squashed my changes down to just one. This does not address @ekzhang's design question wrt codegen in rust. |
src/lib/runtime.ts
Outdated
@@ -13,7 +12,7 @@ type CompilerResultOk = { | |||
evaluate: (deps: Record<string, object[]>) => EvalPromise; | |||
deps: string[]; | |||
results: string[]; | |||
ast: Program | undefined; | |||
ast: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably better as object | undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
This might be better as a separate PR so we can focus on the functionality here, but what do we think about orienting the buttons vertically, and only showing delete and debug buttons when input is shown? This prevents the addition of the bug icon from shifting the other buttons around and accommodates more buttons in the future. I like how the chevron is in the corner of the sidebar button. But it's not perfect, if you have a section with no content then the buttons look weird: |
Agree that the changes to the codegen files are unnecessary here. I'm happy to undo those changes and remove the type generation feature until it's being used. I added the Makefile to encode the build process to produce the Why include types in |
Alright, I think this is ready for another look from you @ekzhang. |
src/lib/runtime.ts
Outdated
@@ -13,7 +12,7 @@ type CompilerResultOk = { | |||
evaluate: (deps: Record<string, object[]>) => EvalPromise; | |||
deps: string[]; | |||
results: string[]; | |||
ast: Program | undefined; | |||
ast: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
Hello 👋🏻
what's going on in here?
I'm interested in compiling Percival's Datalog language to SQLite (sql.js) queries. But as a newcomer to both relational calculus and Rust, it's quite difficult for me to "think" down at the Rust level. To make the challenge more approachable, I want to expose the Percival AST into the notebook environment, which makes it much easier to explore and substantially tightens the experimentation loop.
what?
To that end, this PR makes the following changes:
codegen.rs
->codegen_js.rs
to allow for multiple code generators. Introducecodegen_json
, which is about as basic as it gets - it just serializes the AST. In the future, we could add a codegen_sql or whatever else here.--emit js | json
flag for percival-cli. This allows easy piping of the AST to ~wherever it's needed during developmentresult.ast()
method to percival-wasm. There's some Makefile shenanigans (😱) to patch up the wasm-pack typedefs with the typesafe defs generated in (3). Happy to hear feedback about this?debug
is present in the URLfuture plans?
I hope the changes in this PR are useful enough to stand on their own. If I have enough time, this is how I want to approach the SQL lowering challenge:
I have some other ideas for how to extend Percival's reach, inspired by twitter.com/tomlarkworthy but I'll save those for a stand-alone Github issue.
code quality?