-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Ast typegen #114
Ast typegen #114
Conversation
… JS/TS results to wasm-bindgen *if* --no-pack is specified).
…nce PR is merged at said crate's repo)
…eld, objectdestructuringfield
…with typedef libraries (e.g. ts-rs), best option is to manually override the base type (excluding associated type slots), override references to associated types with concrete replacements in implementing types.
Awesome, looking good! Don't have to worry about With Got a bit panicked at the diff count but realised most of it is Did you manage to get to macro_rules_attribute working? I wonder why tsify doesn't work well with associate generics? I would think it could do |
…de Marker (TODO: check serialized output, see if branding might be worthwhile)
Yeah, the Marker, WithComment and ClassDeclaration ones were the oddest thing - no matter what I did, debug builds would not pick up on typescript custom section produced in either of those three files, but release builds did 🤔 . 😛 well, the file count is still a little alarming. re macro_rules_attribute, I think I'll get the wasm_bindings types fixed up then backtrack to swapping out the simpler ones (especially now I have a type-error free benchmark to compare against). I'm circumspect re how simple the SelfRustTokenize usage will have to be for the macro to work, but we'll see.
Mm, it would have to do some kind of de-genericizing to achieve it, so for something like: struct Foo<T: KindTrait> {
pub baz: T,
pub bar: T::VariableType
}
struct Foobar {
pub inner: u32
}
impl KindTrait for Foobar {
type VariableType = u32;
}
fn main() {
let outer: Foo<Foobar> = Foo { baz: Foobar { inner: 0 }, bar: 0 };
} because you can't fully express the trait (especially the associated type) in TS, the closest you could get is: type Foo<T, T_VariableType> = {
baz: T;
bar: T_VariableType;
}
type Foobar = {
inner: number;
}
// impossible to encapsulate within the parent type
type Foobar_VariableType = number;
let instance: Foo<Foobar, Foobar_VariableType> = {
baz: { inner: 0 },
bar: 0
}; The current approaches (tsify, ts-rs, typeshare, probably bridge.rs too) usually do either of: We're quite fortunate that it's only FunctionBase and PropertyKey (with ~6 variants for FunctionBase, 2 trivially overridden variants for PropertyKey). |
… function/struct. Run cargo fmt, surface more Options structs in typedefs
One thing - is there a combination of flags/params/methods that works for .d.ts files, or is that automatic? I've played around a bit with running ezno on the generated typedefs - ignoring the For the meantime, I've added a quick tsc call to the wasm part of the CI. |
…ro) of tsify in checker (used rarely enough in that crate not to need the bundle macro), definition of bundle macro and demo usage in parser crate.
…erive triplet, restricted to only those enums/structs that do not use either of PartialEqExtras or GetFieldByType
:| it looks like the fuzz CI jobs have run afoul of the stdsimd issue that's crept into a number of dependencies (this one's in ahash) as of nightly 1.78.0 (released yesterday 😭 ). I could get them to sort of run locally (well, with SIGSEGVs on the main branch :-/), post updating to that nightly, you get the unknown feature 'stdsimd' error. |
Awesome! Don't worry about fuzzing (those tests were broken already and will hopefully be fixed in #111). In the Rust->extras workflow is it possible to use the debug profile to build? The I am assuming the "can't find type Span" issue in extras is because kaleidawave/source-map#3 needs merging and releasing first?
Interesting! Did it crash at all (could you put the output in a gist)? I think at the moment because promises and most of the standard library isn't there (e.g. Everything else looks great. I am a bit busy at the moment but at the end of the week will merge and release the source map PR and then I will update this. I think this repo will get an release next week so these type definitions will be included 🎉 |
Yep, I chipped away at the output until it parsed completely and came up with ~3-4 areas that throw parse errors. Here's the gist: https://gist.github.com/H-Plus-Time/fef7b91f2742fc0aed3dc6722756bb22 Re the release build - yeah, this one's necessary to avoid the loss of Marker, WithComment and ClassDeclaration in the debug build (there's something about the files those three are in, or how they're used in the parser crate that makes them vanish in debug, but reappear in release). Agreed it's not great that it slows down CI, though I'm still at a loss as to how the debug build drops those macro outputs (and only for those structs/enums). |
Ah interesting. I didn't know Have just updated the source-map crate. Will have a look at the PR later, update versions and merge. |
…rename derive *bundle*
I will fix and merge when my patience has regenerated 😅 I am excited to get this in the next release! |
Had an idea of how Tsify could support ADTs / the TS it could generate interface PropertyKeyAssociatedTypes extends Record<any, any> {}
interface PropertyKey_<T extends keyof PropertyKeyAssociatedTypes> {
name: PropertyKeyAssociatedTypes[T]["name"]
}
// Example 1 of what could be generated for a impl with ADTs
declare const x: unique symbol;
type PropertyKeyWithX = PropertyKey_<typeof x>;
// Override
interface PropertyKeyAssociatedTypes {
[x]: { name:string }
}
// Another example
declare const y: unique symbol;
type PropertyKeyWithY = PropertyKey_<typeof y>;
// Override
interface PropertyKeyAssociatedTypes {
[y]: { name: undefined }
}
type Example1 = PropertyKeyWithX["name"]
type Example2 = PropertyKeyWithY["name"] |
Ah, thanks for the mass-rename, and the fix for the macro incompat (it was seriously just invocation order? I really should have checked that).
You know, that might actually be it - I hadn't thought to check for similar files with only generics (just ones that had at least one generic, explicit serialize impl). |
Yeah I was trying it and looks like order has an effect. It should technically work, so must be a bug/edge-case in Rust macro expansion. That |
This is strange, somehow the I assume it is still the case from your previous comment and the declaration file is okay for the release build that is published to NPM. It seems like an external issue, do you think it is okay to merge now or do you want to do some more experimentation in this PR? I am out of ideas and I don't know a lot about how |
…ebug and release (locally, nuking cargo cache between runs). Fingers crossed for CI 😧
Yeah, I think if it works on my most recent commit in CI, we're good (I've run As for the underlying issue, yeah, agreed, it's likely some external heisenbug buried within tsify or wasm-bindgen 🤷. I reckon it's good to merge - imho, it's the basis of a useful test feedback loop (simultaneously a. predictable (as opposed to testing against one of the big, well-known public TS projects) b. sufficiently advanced c. digestible), so even a somewhat brittle version is worth it. |
Looks like it is a cache issue in CI. Clearing the CI cache has fixed the missing type declarations? Now as they are being correctly generated, the "fix" I added to debug builds now produces duplicates 😅. All this missing vs duplicate, debug vs release, local vs CI has got my head in a spin 😆 So theoretically if I remove this: Lines 269 to 293 in 15bfa43
It should work on debug (and I will add a temp test for the release build as well) As long as it works on release on the CI (which is how it is published) it should be fine for merging. While the local problems are annoying it shouldn't be important for local development for now. |
Awesome, debug passes (and although release branch didn't fire, I did test it on my GitHub actions testing repository and it worked, so it should be fine for publishing). I know about the difference so will be looking out for it appearing in CI. Will merge now! Thanks for the addition, will be included in the next blog post! 🎉 |
NB: macro-free for the moment (self-rust-tokenize was not happy).
Problematic types so far:
In general, everything that uses an associated type needs a bit of adjustment.