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 {
}
}
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! {
......@@ -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,
)
......@@ -385,18 +398,19 @@ 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,
)
......@@ -404,6 +418,7 @@ impl TurboFn {
}
}
} else {
let persistence = self.persistence();
parse_quote! {
{
#assertions
......
......@@ -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)]
......@@ -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>>,
......
......@@ -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
......
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