Unverified Commit 158a7400 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

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

### What?

For calls with self argument, we also need to flag a task a transient when the self argument is transient.
parent 4b4fd800
...@@ -324,6 +324,18 @@ impl TurboFn { ...@@ -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> { fn converted_this(&self) -> Option<Expr> {
self.this.as_ref().map(|Input { ty: _, ident }| { self.this.as_ref().map(|Input { ty: _, ident }| {
parse_quote! { parse_quote! {
...@@ -361,17 +373,18 @@ impl TurboFn { ...@@ -361,17 +373,18 @@ impl TurboFn {
let output = &self.output; let output = &self.output;
let assertions = self.get_assertions(); let assertions = self.get_assertions();
let inputs = self.input_idents(); let inputs = self.input_idents();
let persistence = self.persistence(); let persistence = self.persistence_with_this();
parse_quote! { parse_quote! {
{ {
#assertions #assertions
let inputs = std::boxed::Box::new((#(#inputs,)*)); let inputs = std::boxed::Box::new((#(#inputs,)*));
let this = #converted_this;
let persistence = #persistence; let persistence = #persistence;
<#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc( <#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc(
turbo_tasks::trait_call( turbo_tasks::trait_call(
*#trait_type_id_ident, *#trait_type_id_ident,
std::borrow::Cow::Borrowed(stringify!(#ident)), std::borrow::Cow::Borrowed(stringify!(#ident)),
#converted_this, this,
inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>, inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>,
persistence, persistence,
) )
...@@ -385,18 +398,19 @@ impl TurboFn { ...@@ -385,18 +398,19 @@ impl TurboFn {
pub fn static_block(&self, native_function_id_ident: &Ident) -> Block { pub fn static_block(&self, native_function_id_ident: &Ident) -> Block {
let output = &self.output; let output = &self.output;
let inputs = self.input_idents(); let inputs = self.input_idents();
let persistence = self.persistence();
let assertions = self.get_assertions(); let assertions = self.get_assertions();
if let Some(converted_this) = self.converted_this() { if let Some(converted_this) = self.converted_this() {
let persistence = self.persistence_with_this();
parse_quote! { parse_quote! {
{ {
#assertions #assertions
let inputs = std::boxed::Box::new((#(#inputs,)*)); let inputs = std::boxed::Box::new((#(#inputs,)*));
let this = #converted_this;
let persistence = #persistence; let persistence = #persistence;
<#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc( <#output as turbo_tasks::task::TaskOutput>::try_from_raw_vc(
turbo_tasks::dynamic_this_call( turbo_tasks::dynamic_this_call(
*#native_function_id_ident, *#native_function_id_ident,
#converted_this, this,
inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>, inputs as std::boxed::Box<dyn turbo_tasks::MagicAny>,
persistence, persistence,
) )
...@@ -404,6 +418,7 @@ impl TurboFn { ...@@ -404,6 +418,7 @@ impl TurboFn {
} }
} }
} else { } else {
let persistence = self.persistence();
parse_quote! { parse_quote! {
{ {
#assertions #assertions
......
...@@ -9,7 +9,8 @@ pub use super::{ ...@@ -9,7 +9,8 @@ pub use super::{
manager::{find_cell_by_type, notify_scheduled_tasks, spawn_detached_for_testing}, manager::{find_cell_by_type, notify_scheduled_tasks, spawn_detached_for_testing},
}; };
use crate::{ use crate::{
debug::ValueDebugFormatString, task::TaskOutput, ResolvedValue, TaskInput, TaskPersistence, Vc, debug::ValueDebugFormatString, task::TaskOutput, RawVc, ResolvedValue, TaskInput,
TaskPersistence, Vc,
}; };
#[inline(never)] #[inline(never)]
...@@ -31,6 +32,17 @@ pub fn get_non_local_persistence_from_inputs(inputs: &impl TaskInput) -> TaskPer ...@@ -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>() pub fn assert_returns_resolved_value<ReturnType, Rv>()
where where
ReturnType: TaskOutput<Return = Vc<Rv>>, ReturnType: TaskOutput<Return = Vc<Rv>>,
......
...@@ -79,6 +79,13 @@ impl RawVc { ...@@ -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 { pub(crate) fn into_read(self) -> ReadRawVcFuture {
// returns a custom future to have something concrete and sized // returns a custom future to have something concrete and sized
// this avoids boxing in IntoFuture // this avoids boxing in IntoFuture
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment