-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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)* | ||
} |
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.
This is the main change with the new turbo_tasks::FromSubTrait
(just a copy paste of std::convert::From
)
no more default fn
impls
|
@@ -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)* |
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.
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! {{ |
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.
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 |
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.
here are the definitions for the new traits
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.
Why ain't the normal From and Into traits working for that?
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.
FWIW I like having the separation here. The semantics are clearer.
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.
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
#[turbo_tasks::function] | ||
fn related_path(&self) -> FileSystemPathVc { | ||
self.manifest.path() | ||
} |
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.
this was missing
#[turbo_tasks::function] | ||
fn related_path(&self) -> FileSystemPathVc { | ||
self.manifest.path() | ||
} |
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.
and this
#[turbo_tasks::function] | ||
fn get_exports(&self) -> EcmascriptExportsVc { | ||
EcmascriptExports::Value.cell() | ||
} |
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.
and this
#[turbo_tasks::function] | ||
fn get_exports(&self) -> EcmascriptExportsVc { | ||
EcmascriptExports::Value.cell() | ||
} |
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.
and this
6eb4320
to
bbf4c76
Compare
Benchmark for fcded0dClick to view benchmark
|
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.
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 { |
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.
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 |
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.
FWIW I like having the separation here. The semantics are clearer.
That's extracted from @ForsakenHarmony's PR #3657 and fixes the workspace members
bbf4c76
to
2c25b89
Compare
Benchmark for 153f62c
Click to view full benchmark
|
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 🎉
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 🎉
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