-
Notifications
You must be signed in to change notification settings - Fork 120
POC: Add language java #239
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
base: main
Are you sure you want to change the base?
Conversation
|
Definitely keep this draft open so that the source can stay available, but be aware that in an effort to reduce the maintenance burden on the typeshare owners, we're pausing accepting PRs for new languages while we work on a major refactor (being worked on in the |
@Lucretiel thanks for the info! This is very exciting 🙂 Coincidentally, I actually did some work along the same lines on my local. My motivation for this exploratory work was three-fold:
For this reason, my POC focused on implementing 3rd party language plugins using WASM. It ended up looking something like this: struct MyLanguagePlugin;
#[typeshare::plugin]
impl typeshare::Language for MyLanugagePlugin {
// ...
}Which generates extern functions for My vision for this was that you could then run: typeshare --lang https://.../my_language.wasm ...
typeshare --lang file:///path/to/my_language.wasm ...The main advantage of executing WASM, rather than native code, is that it's sandboxed. This means consumers only need to audit the code which the plugin outputs, rather than the source code of the plugin. If you'd like, I'd be happy to share my code for reference if you're interested 🙂 |
|
Hey! Excited to report that the new crates for 2.0 are published and ready to use. I'm working this week on an announcement and a set of tutorials and so on, but all of the new crates for independent typeshare implementations are published and documented. In particular:
I also wanted to address the plugin model you proposed; thank you for the idea! We explored something very similar back in November when this project was first being workshopped. While we understood the appeal of a plugin model, our conclusion was that because the amount of maintenance burden on the language author is the same (either way they have to produce a compiled artifact with |
|
I'll also throw in some thoughts about one-type-per-file mode. Currently, typeshare has two mode: single-file (all output to a single large file) and multi-file (one output file per CRATE). Probably the sensible thing to do is rename that to file-per-crate mode, and introduce a third file-per-type mode. The logic looks largely the same in both cases, where typeshare calls
|
|
Hey @Lucretiel, that's really exciting news! I've been working from my half baked PoC branch for a little while now so I can't wait to tidy up the code and publish it for others to use :) Regarding the file-per-type mode, it's no longer a huge priority for me since namespacing works well enough: public class MyCrateName {
public record MyTypeName(...) {}
}However, I'd love to support both namespacing and file-per-type mode in |
|
I would, but I'd ask to hold off for now. I'm primarily in the midst of taking care of all of the work actually releasing and publicizing all of this work, and really don't have the space to already be field large new feature work before the current thing has formally released. If possible I'd focus on the namespacing solution for now. |
|
Of course 🙂 let me know when you'd be ready for that PR and I'll be happy to put the work in |
|
@Lucretiel in case you're interested, I published https://crates.io/crates/typeshare-java (excuse the lack of README - I'll fix this!). It was quite straight forward to port the code from this PR and the new I know it's probably too early for feedback but I found 2 limitations of the new
Once you're ready for contributions, I'd be happy to look into either or both of these :) |
|
|
Hey @Lucretiel, I've been thinking about the doc comments. Although I did find some crates which implement reflection via macros, I wasn't able to find any which expose doc comments at runtime. Unless I missed something, I think you're right that a from-scratch solution may be needed (unless ... see point 3). Here's some thoughts on how that could work: 1.
|
Since posting the above comment, I have become aware of facet: use facet::Facet;
#[derive(Facet)]
struct FooBar {
/// Hello world
test_field: u32,
}
fn main() {
let facet::Type::User(facet::UserType::Struct(ty)) = FooBar::SHAPE.ty else {
unreachable!()
};
println!("{:?}", ty.fields[0].doc);
}$ cargo run
[" Hello world"] |
This is a POC to accompany RFC #238
Important
This PR is not up to date with the RFC.