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

chore(turbo-tasks): Remove the ability to opt-out of NonLocalValue for VcValueType and VcValueTrait #75053

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/next-api/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum Route {
Conflict,
}

#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Endpoint {
fn write_to_disk(self: Vc<Self>) -> Vc<WrittenEndpoint>;
fn server_changed(self: Vc<Self>) -> Vc<Completion>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub struct ValueTraitArguments {
/// Whether the macro should generate a `ValueDebug`-like `dbg()`
/// implementation on the trait's `Vc`.
pub debug: bool,
/// By default, traits have a `turbo_tasks::NonLocalValue` supertype. Should we skip this?
pub local: bool,
/// Should the trait have a `turbo_tasks::OperationValue` supertype?
pub operation: Option<Span>,
}
Expand All @@ -22,7 +20,6 @@ impl Default for ValueTraitArguments {
fn default() -> Self {
Self {
debug: true,
local: false,
operation: None,
}
}
Expand All @@ -41,9 +38,6 @@ impl Parse for ValueTraitArguments {
Some("no_debug") => {
result.debug = false;
}
Some("local") => {
result.local = true;
}
Some("operation") => {
result.operation = Some(meta.span());
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 6 additions & 14 deletions turbopack/crates/turbo-tasks-macros/src/value_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ struct ValueArguments {
cell_mode: CellMode,
manual_eq: bool,
transparent: bool,
/// Should we skip `#[derive(turbo_tasks::NonLocalValue)]`?
local: bool,
/// Should we `#[derive(turbo_tasks::OperationValue)]`?
operation: Option<Span>,
}
Expand All @@ -124,7 +122,6 @@ impl Parse for ValueArguments {
cell_mode: CellMode::Shared,
manual_eq: false,
transparent: false,
local: false,
operation: None,
};
let punctuated: Punctuated<Meta, Token![,]> = input.parse_terminated(Meta::parse)?;
Expand Down Expand Up @@ -180,9 +177,6 @@ impl Parse for ValueArguments {
("transparent", Meta::Path(_)) => {
result.transparent = true;
}
("local", Meta::Path(_)) => {
result.local = true;
}
("operation", Meta::Path(path)) => {
result.operation = Some(path.span());
}
Expand All @@ -191,7 +185,7 @@ impl Parse for ValueArguments {
&meta,
format!(
"unexpected {:?}, expected \"shared\", \"into\", \"serialization\", \
\"cell\", \"eq\", \"transparent\", \"non_local\", or \"operation\"",
\"cell\", \"eq\", \"transparent\", or \"operation\"",
meta
),
))
Expand All @@ -211,7 +205,6 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
cell_mode,
manual_eq,
transparent,
local,
operation,
} = parse_macro_input!(args as ValueArguments);

Expand Down Expand Up @@ -355,7 +348,11 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
};

let mut struct_attributes = vec![quote! {
#[derive(turbo_tasks::ShrinkToFit, turbo_tasks::trace::TraceRawVcs)]
#[derive(
turbo_tasks::ShrinkToFit,
turbo_tasks::trace::TraceRawVcs,
turbo_tasks::NonLocalValue,
)]
}];
match serialization_mode {
SerializationMode::Auto | SerializationMode::AutoForInput => {
Expand Down Expand Up @@ -388,11 +385,6 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
#[derive(PartialEq, Eq)]
});
}
if !local {
struct_attributes.push(quote! {
#[derive(turbo_tasks::NonLocalValue)]
});
}
if let Some(span) = operation {
struct_attributes.push(quote_spanned! {
span =>
Expand Down
17 changes: 6 additions & 11 deletions turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ use crate::func::{
};

pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
let ValueTraitArguments {
debug,
local,
operation,
} = parse_macro_input!(args as ValueTraitArguments);
let ValueTraitArguments { debug, operation } = parse_macro_input!(args as ValueTraitArguments);

let item = parse_macro_input!(input as ItemTrait);

Expand Down Expand Up @@ -197,12 +193,11 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
quote! {}
};

let mut extended_supertraits = vec![quote!(::std::marker::Send), quote!(::std::marker::Sync)];
if !local {
extended_supertraits.push(quote! {
turbo_tasks::NonLocalValue
});
}
let mut extended_supertraits = vec![
quote!(::std::marker::Send),
quote!(::std::marker::Sync),
quote!(turbo_tasks::NonLocalValue),
];
if let Some(span) = operation {
extended_supertraits.push(quote_spanned! {
span => turbo_tasks::OperationValue
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ValueDebugString {
/// ```ignore
/// dbg!(any_vc.dbg().await?);
/// ```
#[turbo_tasks::value_trait(no_debug, local)]
#[turbo_tasks::value_trait(no_debug)]
pub trait ValueDebug {
fn dbg(self: Vc<Self>) -> Vc<ValueDebugString>;

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use turbo_tasks::Vc;

use crate::{self as turbo_tasks};

#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait ValueToString {
fn to_string(self: Vc<Self>) -> Vc<RcStr>;
}
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/vc/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{self as turbo_tasks};
/// 1. Annotating with `#[turbo_tasks::value_impl]`: this will make `Vc::default()` always return
/// the same underlying value (i.e. a singleton).
/// 2. No annotations: this will make `Vc::default()` always return a different value.
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait ValueDefault {
fn value_default() -> Vc<Self>;
}
13 changes: 2 additions & 11 deletions turbopack/crates/turbo-tasks/src/vc/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,8 @@ use crate::{marker_trait::impl_auto_marker_trait, OperationVc, ResolvedVc};
/// [`negative_impls`]: https://doc.rust-lang.org/beta/unstable-book/language-features/negative-impls.html
pub unsafe trait NonLocalValue {}

// TODO(bgw): These trait implementations aren't correct, as these values `T` could contain
// references to local `Vc` values. We must also check that `T: NonLocalValue`. However, we're
// temporarily ignoring that problem, as:
//
// - We don't *currently* depend on `NonLocalValue` for safety (local tasks aren't enabled).
// - We intend to make all `VcValueType`s implement `NonLocalValue`, so implementing this for all
// values is approximating that future state.
// - Adding a `T: NonLocalValue` bound introduces a lot of noise that isn't directly actionable for
// types that include a `ResolvedVc` or `OperationVc` that is not *yet* a `NonLocalValue`.
unsafe impl<T: ?Sized> NonLocalValue for OperationVc<T> {}
unsafe impl<T: ?Sized> NonLocalValue for ResolvedVc<T> {}
unsafe impl<T: NonLocalValue + ?Sized> NonLocalValue for OperationVc<T> {}
unsafe impl<T: NonLocalValue + ?Sized> NonLocalValue for ResolvedVc<T> {}

impl_auto_marker_trait!(NonLocalValue);

Expand Down
7 changes: 4 additions & 3 deletions turbopack/crates/turbo-tasks/src/vc/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{cell_mode::VcCellMode, read::VcRead};
use crate::{ShrinkToFit, TraitTypeId, ValueTypeId};
use crate::{
vc::cell_mode::VcCellMode, NonLocalValue, ShrinkToFit, TraitTypeId, ValueTypeId, VcRead,
};

/// A trait implemented on all values types that can be put into a Value Cell
/// ([`Vc<T>`][crate::Vc]).
Expand All @@ -24,7 +25,7 @@ pub unsafe trait VcValueType: ShrinkToFit + Sized + Send + Sync + 'static {

/// A trait implemented on all values trait object references that can be put
/// into a Value Cell ([`Vc<Box<dyn Trait>>`][crate::Vc]).
pub trait VcValueTrait: Send + Sync + 'static {
pub trait VcValueTrait: NonLocalValue + Send + Sync + 'static {
fn get_trait_type_id() -> TraitTypeId;
}

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use turbo_tasks_fs::{
use crate::version::{VersionedAssetContent, VersionedContent};

/// An asset. It also forms a graph when following [Asset::references].
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Asset {
/// The content of the [Asset].
fn content(self: Vc<Self>) -> Vc<AssetContent>;
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/chunk/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
///
/// The chunking context implementation will resolve the dynamic entry to a
/// well-known value or trait object.
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait EvaluatableAsset: Asset + Module + ChunkableModule {}

pub trait EvaluatableAssetExt {
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl ModuleId {
pub struct ModuleIds(Vec<ResolvedVc<ModuleId>>);

/// A [Module] that can be converted into a [Chunk].
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait ChunkableModule: Module + Asset {
fn as_chunk_item(
self: Vc<Self>,
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/introspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type VcDynIntrospectable = ResolvedVc<Box<dyn Introspectable>>;
#[turbo_tasks::value(transparent)]
pub struct IntrospectableChildren(FxIndexSet<(ResolvedVc<RcStr>, VcDynIntrospectable)>);

#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Introspectable {
fn ty(self: Vc<Self>) -> Vc<RcStr>;
fn title(self: Vc<Self>) -> Vc<RcStr> {
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/issue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub enum StyledString {
Strong(RcStr),
}

#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Issue {
/// Severity allows the user to filter out unimportant issues, with Bug
/// being the highest priority and Info being the lowest.
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences};

/// A module. This usually represents parsed source code, which has references
/// to other modules.
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Module: Asset {
/// The identifier of the [Module]. It's expected to be unique and capture
/// all properties of the [Module].
Expand Down
Loading
Loading