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

[Turbopack] transient when the self argument is transient #69657

Merged
merged 1 commit into from
Sep 4, 2024
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
23 changes: 19 additions & 4 deletions turbopack/crates/turbo-tasks-macros/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ impl TurboFn {
}
}

pub fn persistence_with_this(&self) -> impl ToTokens {
if self.local_cells {
quote! {
turbo_tasks::TaskPersistence::LocalCells
}
} else {
quote! {
turbo_tasks::macro_helpers::get_non_local_persistence_from_inputs_and_this(this, &*inputs)
}
}
}

fn converted_this(&self) -> Option<Expr> {
self.this.as_ref().map(|Input { ty: _, ident }| {
parse_quote! {
Expand Down Expand Up @@ -361,17 +373,18 @@ impl TurboFn {
let output = &self.output;
let assertions = self.get_assertions();
let inputs = self.input_idents();
let persistence = self.persistence();
let persistence = self.persistence_with_this();
parse_quote! {
{
#assertions
let inputs = std::boxed::Box::new((#(#inputs,)*));
let this = #converted_this;
let persistence = #persistence;
<#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc(
turbo_tasks::trait_call(
*#trait_type_id_ident,
std::borrow::Cow::Borrowed(stringify!(#ident)),
#converted_this,
this,
inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>,
persistence,
)
Expand All @@ -385,25 +398,27 @@ impl TurboFn {
pub fn static_block(&self, native_function_id_ident: &Ident) -> Block {
let output = &self.output;
let inputs = self.input_idents();
let persistence = self.persistence();
let assertions = self.get_assertions();
if let Some(converted_this) = self.converted_this() {
let persistence = self.persistence_with_this();
parse_quote! {
{
#assertions
let inputs = std::boxed::Box::new((#(#inputs,)*));
let this = #converted_this;
let persistence = #persistence;
<#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc(
turbo_tasks::dynamic_this_call(
*#native_function_id_ident,
#converted_this,
this,
inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>,
persistence,
)
)
}
}
} else {
let persistence = self.persistence();
parse_quote! {
{
#assertions
Expand Down
14 changes: 13 additions & 1 deletion turbopack/crates/turbo-tasks/src/macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub use super::{
manager::{find_cell_by_type, notify_scheduled_tasks, spawn_detached_for_testing},
};
use crate::{
debug::ValueDebugFormatString, task::TaskOutput, ResolvedValue, TaskInput, TaskPersistence, Vc,
debug::ValueDebugFormatString, task::TaskOutput, RawVc, ResolvedValue, TaskInput,
TaskPersistence, Vc,
};

#[inline(never)]
Expand All @@ -31,6 +32,17 @@ pub fn get_non_local_persistence_from_inputs(inputs: &impl TaskInput) -> TaskPer
}
}

pub fn get_non_local_persistence_from_inputs_and_this(
this: RawVc,
inputs: &impl TaskInput,
) -> TaskPersistence {
if this.is_transient() || inputs.is_transient() {
TaskPersistence::Transient
} else {
TaskPersistence::Persistent
}
}

pub fn assert_returns_resolved_value<ReturnType, Rv>()
where
ReturnType: TaskOutput<Return = Vc<Rv>>,
Expand Down
7 changes: 7 additions & 0 deletions turbopack/crates/turbo-tasks/src/raw_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ impl RawVc {
}
}

pub fn is_transient(&self) -> bool {
match self {
RawVc::TaskOutput(task) | RawVc::TaskCell(task, _) => task.is_transient(),
RawVc::LocalCell(_, _) => true,
}
}

pub(crate) fn into_read(self) -> ReadRawVcFuture {
// returns a custom future to have something concrete and sized
// this avoids boxing in IntoFuture
Expand Down
Loading