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

detect missing trait methods at compile time #3657

Merged
merged 5 commits into from Feb 7, 2023

Conversation

ForsakenHarmony
Copy link
Member

@ForsakenHarmony ForsakenHarmony commented Feb 6, 2023

Leaves the default implementations of a trait "in place" and implements the "cross-trait" resolving differently

we get back the normal rust error messages when you don't have every method implemented 🎉

Fixes WEB-569

@ForsakenHarmony ForsakenHarmony requested a review from a team as a code owner February 6, 2023 20:16
@ForsakenHarmony
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

#ref_ident: turbo_tasks::FromSubTrait<T>,
turbo_tasks::TaskInput: for<'a> std::convert::From<&'a T>
#(, #supertrait_refs: turbo_tasks::FromSubTrait<T>)* {
#(#trait_fns)*
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change with the new turbo_tasks::FromSubTrait (just a copy paste of std::convert::From)

no more default fn impls

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

@@ -233,8 +243,6 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
let raw_vc: turbo_tasks::RawVc = super_trait_vc.into();
#ref_ident { node: raw_vc }
}

#(pub #trait_fns)*
Copy link
Member Author

Choose a reason for hiding this comment

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

Could probably add this back to reduce the imports, though this is more "rusty" now

@@ -138,6 +138,10 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
});

*sig = external_sig;
*default = Some(parse_quote! {{
Copy link
Member Author

Choose a reason for hiding this comment

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

We also keep the default methods around, unsure if this needs to be trait call or not

@@ -51,6 +51,41 @@ pub trait ValueTraitVc:
fn get_trait_type_id() -> TraitTypeId;
}

pub trait IntoSuperTrait<T>: ValueTraitVc
Copy link
Member Author

Choose a reason for hiding this comment

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

here are the definitions for the new traits

Copy link
Member

Choose a reason for hiding this comment

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

Why ain't the normal From and Into traits working for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I like having the separation here. The semantics are clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the reason the default fn was needed because non trait types already implement Into<TraitVc> which was the reason it never complained about missing functions

Comment on lines +78 to +81
#[turbo_tasks::function]
fn related_path(&self) -> FileSystemPathVc {
self.manifest.path()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this was missing

Comment on lines +246 to +249
#[turbo_tasks::function]
fn related_path(&self) -> FileSystemPathVc {
self.manifest.path()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

and this

Comment on lines +72 to +75
#[turbo_tasks::function]
fn get_exports(&self) -> EcmascriptExportsVc {
EcmascriptExports::Value.cell()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

and this

Comment on lines +130 to +133
#[turbo_tasks::function]
fn get_exports(&self) -> EcmascriptExportsVc {
EcmascriptExports::Value.cell()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

and this

@ForsakenHarmony ForsakenHarmony changed the title detect missing trait methods Detect missing trait methods at compile time Feb 6, 2023
@ForsakenHarmony ForsakenHarmony changed the title Detect missing trait methods at compile time detect missing trait methods at compile time Feb 6, 2023
@ForsakenHarmony ForsakenHarmony force-pushed the hrmny/detect-missing-trait-methods branch from 6eb4320 to bbf4c76 Compare February 6, 2023 20:31
@ForsakenHarmony ForsakenHarmony requested a review from a team as a code owner February 6, 2023 20:31
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2023

Benchmark for fcded0d

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 10.05ms ± 0.10ms 9950.59µs ± 86.52µs -0.96%
bench_hmr_to_commit/Turbopack RCC/1000 modules 10.31ms ± 0.09ms 10.21ms ± 0.08ms -0.95%
bench_hmr_to_commit/Turbopack RSC/1000 modules 506.05ms ± 1.49ms 508.73ms ± 2.75ms +0.53%
bench_hmr_to_commit/Turbopack SSR/1000 modules 10.19ms ± 0.09ms 10.10ms ± 0.10ms -0.90%
bench_hmr_to_eval/Turbopack CSR/1000 modules 8954.98µs ± 134.70µs 9123.45µs ± 87.90µs +1.88%
bench_hmr_to_eval/Turbopack RCC/1000 modules 9210.66µs ± 86.94µs 9237.92µs ± 103.60µs +0.30%
bench_hmr_to_eval/Turbopack SSR/1000 modules 9083.23µs ± 74.42µs 9054.24µs ± 83.08µs -0.32%
bench_hydration/Turbopack RCC/1000 modules 4317.31ms ± 9.60ms 4336.33ms ± 18.16ms +0.44%
bench_hydration/Turbopack RSC/1000 modules 3890.78ms ± 15.94ms 3915.26ms ± 11.81ms +0.63%
bench_hydration/Turbopack SSR/1000 modules 3818.57ms ± 15.65ms 3786.79ms ± 9.40ms -0.83%
bench_startup/Turbopack CSR/1000 modules 2826.30ms ± 11.47ms 2798.25ms ± 11.11ms -0.99%
bench_startup/Turbopack RCC/1000 modules 2624.54ms ± 8.11ms 2610.61ms ± 7.92ms -0.53%
bench_startup/Turbopack RSC/1000 modules 2495.92ms ± 8.70ms 2516.36ms ± 8.05ms +0.82%
bench_startup/Turbopack SSR/1000 modules 2148.89ms ± 2.89ms 2143.87ms ± 2.55ms -0.23%

Copy link
Contributor

@alexkirsz alexkirsz left a comment

Choose a reason for hiding this comment

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

This is great.

@@ -265,6 +278,12 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
}
}

impl turbo_tasks::FromSubTrait<#ref_ident> for #supertrait_refs {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my Vc<T> work, I called this trait Upcast (for both the Vc<dyn Sub> -> Vc<dyn Super> and the Vc<Val> -> Vc<dyn Trait> cases).

@@ -51,6 +51,41 @@ pub trait ValueTraitVc:
fn get_trait_type_id() -> TraitTypeId;
}

pub trait IntoSuperTrait<T>: ValueTraitVc
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I like having the separation here. The semantics are clearer.

kodiakhq bot pushed a commit that referenced this pull request Feb 7, 2023
That's extracted from @ForsakenHarmony's PR #3657 and fixes the workspace members
@vercel vercel deleted a comment from vercel bot Feb 7, 2023
@ForsakenHarmony ForsakenHarmony merged commit bf0980e into main Feb 7, 2023
@ForsakenHarmony ForsakenHarmony deleted the hrmny/detect-missing-trait-methods branch February 7, 2023 16:06
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

Benchmark for 153f62c

Test Base PR % Significant %
bench_hydration/Turbopack SSR/1000 modules 3893.93ms ± 9.60ms 3816.66ms ± 24.47ms -1.98% -0.24%
bench_startup/Turbopack RCC/1000 modules 2662.29ms ± 10.78ms 2712.89ms ± 10.52ms +1.90% +0.30%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 10.10ms ± 0.10ms 10.27ms ± 0.09ms +1.70%
bench_hmr_to_commit/Turbopack RCC/1000 modules 10.35ms ± 0.07ms 10.33ms ± 0.08ms -0.21%
bench_hmr_to_commit/Turbopack RSC/1000 modules 518.44ms ± 2.18ms 520.71ms ± 3.42ms +0.44%
bench_hmr_to_commit/Turbopack SSR/1000 modules 10.41ms ± 0.09ms 10.23ms ± 0.09ms -1.75%
bench_hmr_to_eval/Turbopack CSR/1000 modules 9360.17µs ± 121.69µs 9236.25µs ± 42.73µs -1.32%
bench_hmr_to_eval/Turbopack RCC/1000 modules 9283.16µs ± 93.71µs 9346.54µs ± 106.45µs +0.68%
bench_hmr_to_eval/Turbopack SSR/1000 modules 9397.31µs ± 101.35µs 9238.58µs ± 68.79µs -1.69%
bench_hydration/Turbopack RCC/1000 modules 4394.88ms ± 20.69ms 4426.63ms ± 15.27ms +0.72%
bench_hydration/Turbopack RSC/1000 modules 4022.77ms ± 12.56ms 4018.95ms ± 24.65ms -0.09%
bench_hydration/Turbopack SSR/1000 modules 3893.93ms ± 9.60ms 3816.66ms ± 24.47ms -1.98% -0.24%
bench_startup/Turbopack CSR/1000 modules 2869.35ms ± 10.10ms 2879.03ms ± 17.09ms +0.34%
bench_startup/Turbopack RCC/1000 modules 2662.29ms ± 10.78ms 2712.89ms ± 10.52ms +1.90% +0.30%
bench_startup/Turbopack RSC/1000 modules 2588.71ms ± 9.13ms 2591.74ms ± 10.03ms +0.12%
bench_startup/Turbopack SSR/1000 modules 2218.85ms ± 3.81ms 2200.52ms ± 8.37ms -0.83%

jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
Leaves the default implementations of a trait "in place" and implements
the "cross-trait" resolving differently

we get back the normal rust error messages when you don't have every
method implemented 🎉
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
Leaves the default implementations of a trait "in place" and implements
the "cross-trait" resolving differently

we get back the normal rust error messages when you don't have every
method implemented 🎉
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.

None yet

3 participants