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

Library-izing brilift #312

Merged
merged 19 commits into from
Mar 20, 2024
Merged

Library-izing brilift #312

merged 19 commits into from
Mar 20, 2024

Conversation

Alex-Fischman
Copy link
Contributor

This PR:

  • Moves code from main.rs to new file translator.rs
  • Adds lib.rs
  • Adds full bril-rs feature set to both brilirs and brilift to allow users to depend on both
  • Resolves issues with adding those features in translator.rs

Note: I don't think it makes sense for the compiler to support the speculate and ssa features, so I marked them as unimplemented!(). In contrast, I think that it does make sense to support char, but I'm not confident in my ability to write C without memory leaks, so I marked that as todo!().

@@ -31,7 +31,7 @@ itoa = "1.0"
[dependencies.bril-rs]
version = "0.1.0"
path = "../bril-rs"
features = ["ssa", "memory", "float", "speculate", "char"]
features = ["memory", "float", "ssa", "speculate", "position", "import", "char"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I was surprised that these features weren't added since brilirs supports most of these. I realized that they probably get pulled in during feature resolution with bril2json which does list these features.

Copy link
Owner

Choose a reason for hiding this comment

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

That'd do it, I guess!

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Overall looks good! And the unimplemented! approach seems perfectly good for those features we're not covering.

I have a couple of very minor organizational suggestions—let me know what you think.

brilift/src/lib.rs Outdated Show resolved Hide resolved
brilift/src/translator.rs Outdated Show resolved Hide resolved
@Alex-Fischman
Copy link
Contributor Author

I've changed Args to RunArgs and added a CompileArgs struct to improve the API. I've also moved RunArgs into main.rs and made main call into compile.

@sampsyo
Copy link
Owner

sampsyo commented Mar 17, 2024

Awesome; looking good! It looks like Clippy has one somewhat weird but OK suggestion:
https://github.com/sampsyo/bril/actions/runs/8311293204/job/22745133930?pr=312#step:7:28

Something also seems to be up with the tests… simple stuff like br.bril seems to be hitting the todo!()s?
https://github.com/sampsyo/bril/actions/runs/8311293204/job/22745134011?pr=312#step:11:195

I can try to take a closer look, since I don't see an obvious reason why this would be triggering.

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looking into it a little closer, it seems like compilation crashes when trying to add the runtime functions! I've marked the place where this happens. It seems like maybe we should add a _bril_print_char function, which shouldn't be too complex? Or, we could just remove PrintChar from the relevant enum.

brilift/src/translator.rs Outdated Show resolved Hide resolved
Self::PrintInt => "_bril_print_int",
Self::PrintBool => "_bril_print_bool",
Self::PrintFloat => "_bril_print_float",
Self::PrintChar => todo!(),
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is the trouble with the tests! Probably the easiest thing here is just to implement the runtime function, which should be straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't do this because I don't know how to print Unicode characters from printf.

@Alex-Fischman
Copy link
Contributor Author

How do I run the CI?

@sampsyo
Copy link
Owner

sampsyo commented Mar 20, 2024

Unfortunately, the CI has to be manually triggered by a maintainer when the PR comes from a first-time contributor. It's a really annoying feature in GitHub that is sadly necessary to prevent widespread crypto scams:
https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks

Anyway, looking green from here! Thanks! I'll check things out more closely and then hit the button.

The `CompileArgs` struct wasn't very helpful, so I made these actual
arguments to the function. The `OptLevel` enum was also sort of in the
wrong place: this is about command-line parsing rather than being about
an actual useful interface (since we will pass this as a string to
Cranelift anyway).
For symmetry with the `compile` interface.
@sampsyo
Copy link
Owner

sampsyo commented Mar 20, 2024

OK, we're all set! Thanks again for getting this going!!!

I changed things around just a tiny bit: most prominently, making a jit_run interface in lib.rs that acts as a symmetric pair alongside compile.

@sampsyo sampsyo merged commit ea3293b into sampsyo:main Mar 20, 2024
16 checks passed
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.

3 participants