Repository navigation
feat(ts): type a generic type's pointer to its parameter as each instance holds it #371
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9c37c82
chore(quest): claim quest/m3/ts-generic-pointer-fields.md
kixelated 021f8a1
feat(ts): type a generic type's pointer to its parameter as each inst…
kixelated 626dcd9
docs: record generic pointer fields and follow-up quests
kixelated acf79d7
fix(ts): cast a generic type's pointer field where an instance's copy…
kixelated 5a57a3e
docs(ts): note rt.Ptr fields in MIGRATE
kixelated d2ca15b
Merge remote-tracking branch 'origin/main' into quest/m3/ts-generic-p…
kixelated a266757
fix(ts): cast a function of a generic type's pointer where an instanc…
kixelated d72faf4
Merge remote-tracking branch 'origin/main' into quest/m3/ts-generic-p…
kixelated e6009de
Merge remote-tracking branch 'origin/main' into quest/m3/ts-generic-p…
kixelated 90d7c27
Merge base and preserve both language fixture registrations
e289d16
quest land: merge tested base
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # [M] Type-check the output before success | ||
|
|
||
| ## Goal | ||
|
|
||
| [rust2-ts](/ts/README.md) fails translation, at the Rust span the source map names, on | ||
| output `tsc` rejects, so a typing gap fails loud where the consumer's crate translates | ||
| rather than in the consumer's own `tsc`, and measures what the check costs a moq-net | ||
| translation. | ||
|
|
||
| ## Plan | ||
|
|
||
| Found by [the generic pointer fields](https://github.com/moq-dev/rust2/pull/371): a | ||
| generic type's `*mut T` field translated, and only `tsc` rejected it. `just ts test` | ||
| type-checks the fixtures and the nightly `just ts moq` moq's output, but nothing checks | ||
| another consumer's. Translation already runs the flake's `tsc` on bindings, so the | ||
| output could go through the same run. A rejection is a translator bug, so the error | ||
| should say so beside the span. | ||
|
|
||
| Public API: translation fails where it succeeded on ill-typed output. | ||
|
|
||
| ## Related | ||
|
|
||
| - [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - would make the check cheaper; this needs no wait |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # [S] A generic type's bytes at u8 | ||
|
|
||
| ## Goal | ||
|
|
||
| [rust2-ts](/ts/README.md) types a `[T; N]`, `Vec<T>`, or `&[T]` field of a generic type as | ||
| its `u8` instance holds it, or refuses that instance with a span, proven by a differential | ||
| test against native Rust of one such type instantiated at `u8` and at another element. | ||
|
|
||
| ## Plan | ||
|
|
||
| Found beside [the generic pointer fields](https://github.com/moq-dev/rust2/pull/371): the | ||
| definition types each field `T[]`, but an instance at `u8` stores a `Uint8Array`, an | ||
| `rt.ByteVec`, or an `rt.ByteSlice`, so `tsc` rejects the instance's code while | ||
| translation succeeds. A field whose definition types a pointer as an `rt.Ptr` is | ||
| already read as its instance's type through a cast; a union of the element array and | ||
| the byte form, cast on read the same way, may fit, as may refusing the `u8` instance as | ||
| `generic_erasure` refuses an `Option` of a type parameter that can be `undefined`. | ||
|
|
||
| Public API: the translator's output. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # [XS] == of an Option of NonNull | ||
|
|
||
| ## Goal | ||
|
|
||
| [rust2-ts](/ts/README.md) translates `==` of an `Option<NonNull<T>>`, proven by a | ||
| differential test against native Rust for pointers to an object and to a `[u8; N]`, | ||
| equal and apart, and `None`. | ||
|
|
||
| ## Plan | ||
|
|
||
| Found writing [the generic pointer fields](https://github.com/moq-dev/rust2/pull/371)' | ||
| fixture: `a.maybe == Some(a.held)` is refused as an unsupported call to `Option`'s | ||
| `PartialEq::eq`, while `matches!(a.maybe, Some(p) if p == a.held)` translates. Pointers | ||
| to a value JS copies stay refused, as their `==` is. | ||
|
|
||
| Public API: the translator's output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Generated by rust2-ts. Do not edit. | ||
|
|
||
| import * as rt from "./rt.ts"; | ||
| import type * as To from "./pointers.To.ts"; | ||
|
|
||
| /** Pointers to `T` in each shape a field holds one, copied as Rust copies them. */ | ||
| export interface Aimed<T> { | ||
| at: rt.Ptr<T>; | ||
| seen: rt.Ptr<T>; | ||
| held: rt.Ptr<T>; | ||
| maybe: rt.Ptr<T> | undefined; | ||
| tagged: [rt.Ptr<T>, rt.u8]; | ||
| to: To.To<T>; | ||
| /** A function taking one, which JS takes as the instance's own pointer. */ | ||
| read: (a0: rt.Ptr<T>) => rt.u8; | ||
| } | ||
|
|
||
| //# sourceMappingURL=pointers.Aimed.ts.map | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Generated by rust2-ts. Do not edit. | ||
|
|
||
| import * as rt from "./rt.ts"; | ||
|
|
||
| /** References to `T`. */ | ||
| export interface Borrows<T> { | ||
| to: rt.Ptr<T>; | ||
| seen: rt.Ptr<T>; | ||
| } | ||
|
|
||
| //# sourceMappingURL=pointers.Borrows.ts.map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Generated by rust2-ts. Do not edit. | ||
|
|
||
| import type * as Aimed from "./pointers.Aimed.ts"; | ||
|
|
||
| /** A generic type holding another's instance. */ | ||
| export interface Enclosed<T> { | ||
| inner: Aimed.Aimed<T>; | ||
| } | ||
|
|
||
| //# sourceMappingURL=pointers.Enclosed.ts.map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Generated by rust2-ts. Do not edit. | ||
|
|
||
| import * as rt from "./rt.ts"; | ||
|
|
||
| /** An instance of another generic type. */ | ||
| export class Housed<T> { | ||
| _0: T; | ||
|
|
||
| constructor(_0: T) { | ||
| this._0 = _0; | ||
| } | ||
| } | ||
|
|
||
| export function made$pointers_Aim_u8(n: rt.u8): Housed<rt.u8> { | ||
| return new Housed(n ^ 153); | ||
| } | ||
|
|
||
| export function get$pointers_Aim_u8(self: Housed<rt.u8>): rt.u8 { | ||
| return self._0; | ||
| } | ||
|
|
||
| export function put$pointers_Aim_u8(self: Housed<rt.u8>, n: rt.u8): void { | ||
| self._0 = rt.u8WrappingAdd(self._0, n) ^ 16; | ||
| } | ||
|
|
||
| //# sourceMappingURL=pointers.Housed.ts.map |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Script executed:
Repository: moq-dev/rust2
Length of output: 11030
Make the emitted
readtype and its construction cast agree on the instance's pointer form.For
Aimed<u8>, thereadfield is(a0: rt.Ptr<rt.u8>) => rt.u8(ts/fixtures/lang/expected/pointers.ts:1507).rt.Ptr<rt.u8>includes a barenumber, andrt.u8accepts a plain number because its brand is optional.readThrough$u8takesrt.Place<rt.u8>and reads.v(ts/fixtures/lang/expected/pointers.ts:2129-2131). For a bare number,.visundefined, so the function passesundefinedonward.The field doc comment says JS takes "the instance's own pointer" (
pointers.Aimed.ts:14). Thefield_valuedoc ints/src/lower/mod.rssays the cast leaves no other form of pointer accepted. Itsdefined.substcall replacesTonly insidert.Ptr<T>, so the union stays and the cast still admits the other forms.A fix must change the cast and the
Aimed<T>declaration together. A cast to a narrower parameter type would fail assignment to the declaredreadtype understrictFunctionTypes. The generic declaration cannot express a per-instance form withrt.Ptr<T>. Documenting the current behavior would not resolve the mismatch, because the emitted type would still admit the other forms.