Skip to content

Commit

Permalink
draft(turbo-tasks): Make State require OperationValue
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Dec 16, 2024
1 parent 069afc7 commit d2b9792
Show file tree
Hide file tree
Showing 35 changed files with 542 additions and 249 deletions.
19 changes: 9 additions & 10 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,6 @@ impl AppEndpoint {
Ok(app_entry)
}

#[turbo_tasks::function]
fn output_assets(self: Vc<Self>) -> Vc<OutputAssets> {
self.output().output_assets()
}

#[turbo_tasks::function]
async fn output(self: Vc<Self>) -> Result<Vc<AppEndpointOutput>> {
let this = self.await?;
Expand Down Expand Up @@ -1577,7 +1572,7 @@ async fn create_app_paths_manifest(
#[turbo_tasks::value_impl]
impl Endpoint for AppEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
async fn write_to_disk(self: ResolvedVc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let page_name = this.page.to_string();
let span = match this.ty {
Expand All @@ -1602,9 +1597,8 @@ impl Endpoint for AppEndpoint {
};
async move {
let output = self.output().await?;
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let output_assets_op = output_assets_operation(self);
let output_assets = output_assets_op.connect();

let node_root = this.app_project.project().node_root();

Expand All @@ -1613,7 +1607,7 @@ impl Endpoint for AppEndpoint {
let _ = this
.app_project
.project()
.emit_all_output_assets(Vc::cell(output_assets));
.emit_all_output_assets(output_assets_op);

let (server_paths, client_paths) = if this
.app_project
Expand Down Expand Up @@ -1684,6 +1678,11 @@ impl Endpoint for AppEndpoint {
}
}

#[turbo_tasks::function(operation)]
fn output_assets_operation(endpoint: ResolvedVc<AppEndpoint>) -> Vc<OutputAssets> {
endpoint.output().output_assets()
}

#[turbo_tasks::value]
enum AppEndpointOutput {
NodeJs {
Expand Down
12 changes: 9 additions & 3 deletions crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,16 @@ struct InstrumentationCoreModules {
#[turbo_tasks::value_impl]
impl Endpoint for InstrumentationEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
async fn write_to_disk(self: ResolvedVc<Self>) -> Result<Vc<WrittenEndpoint>> {
let span = tracing::info_span!("instrumentation endpoint");
async move {
let this = self.await?;
let output_assets = self.output_assets();
let output_assets_op = output_assets_operation(self);
let output_assets = output_assets_op.connect();
let _ = output_assets.resolve().await?;
let _ = this
.project
.emit_all_output_assets(Vc::cell(output_assets))
.emit_all_output_assets(output_assets_op)
.resolve()
.await?;

Expand Down Expand Up @@ -294,3 +295,8 @@ impl Endpoint for InstrumentationEndpoint {
]))
}
}

#[turbo_tasks::function(operation)]
fn output_assets_operation(endpoint: ResolvedVc<InstrumentationEndpoint>) -> Vc<OutputAssets> {
endpoint.output_assets()
}
12 changes: 9 additions & 3 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,16 @@ impl MiddlewareEndpoint {
#[turbo_tasks::value_impl]
impl Endpoint for MiddlewareEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
async fn write_to_disk(self: ResolvedVc<Self>) -> Result<Vc<WrittenEndpoint>> {
let span = tracing::info_span!("middleware endpoint");
async move {
let this = self.await?;
let output_assets = self.output_assets();
let output_assets_op = output_assets_operation(self);
let output_assets = output_assets_op.connect();
let _ = output_assets.resolve().await?;
let _ = this
.project
.emit_all_output_assets(Vc::cell(output_assets))
.emit_all_output_assets(output_assets_op)
.resolve()
.await?;

Expand Down Expand Up @@ -324,3 +325,8 @@ impl Endpoint for MiddlewareEndpoint {
Ok(Vc::cell(vec![self.userland_module().to_resolved().await?]))
}
}

#[turbo_tasks::function(operation)]
fn output_assets_operation(endpoint: ResolvedVc<MiddlewareEndpoint>) -> Vc<OutputAssets> {
endpoint.output_assets()
}
19 changes: 9 additions & 10 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,6 @@ impl PageEndpoint {
))
}

#[turbo_tasks::function]
fn output_assets(self: Vc<Self>) -> Vc<OutputAssets> {
self.output().output_assets()
}

#[turbo_tasks::function]
async fn output(self: Vc<Self>) -> Result<Vc<PageEndpointOutput>> {
let this = self.await?;
Expand Down Expand Up @@ -1298,7 +1293,7 @@ pub struct InternalSsrChunkModule {
#[turbo_tasks::value_impl]
impl Endpoint for PageEndpoint {
#[turbo_tasks::function]
async fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
async fn write_to_disk(self: ResolvedVc<Self>) -> Result<Vc<WrittenEndpoint>> {
let this = self.await?;
let original_name = this.original_name.await?;
let span = {
Expand All @@ -1319,14 +1314,13 @@ impl Endpoint for PageEndpoint {
};
async move {
let output = self.output().await?;
// Must use self.output_assets() instead of output.output_assets() to make it a
// single operation
let output_assets = self.output_assets();
let output_assets_op = output_assets_operation(self);
let output_assets = output_assets_op.connect();

let _ = this
.pages_project
.project()
.emit_all_output_assets(Vc::cell(output_assets))
.emit_all_output_assets(output_assets_op)
.resolve()
.await?;

Expand Down Expand Up @@ -1411,6 +1405,11 @@ impl Endpoint for PageEndpoint {
}
}

#[turbo_tasks::function(operation)]
fn output_assets_operation(endpoint: ResolvedVc<PageEndpoint>) -> Vc<OutputAssets> {
endpoint.output().output_assets()
}

#[turbo_tasks::value]
enum PageEndpointOutput {
NodeJs {
Expand Down
64 changes: 44 additions & 20 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use turbo_tasks::{
fxindexmap,
graph::{AdjacencyMap, GraphTraversal},
trace::TraceRawVcs,
Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, ReadRef, ResolvedVc, State,
TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc,
Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, OperationValue, OperationVc,
ReadRef, ResolvedVc, State, TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc,
};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem};
Expand Down Expand Up @@ -69,11 +69,21 @@ use crate::{
middleware::MiddlewareEndpoint,
pages::PagesProject,
route::{AppPageRoute, Endpoint, Route},
versioned_content_map::{OutputAssetsOperation, VersionedContentMap},
versioned_content_map::VersionedContentMap,
};

#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct DraftModeOptions {
Expand All @@ -95,6 +105,7 @@ pub struct DraftModeOptions {
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct WatchOptions {
Expand All @@ -107,7 +118,17 @@ pub struct WatchOptions {
}

#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct ProjectOptions {
Expand Down Expand Up @@ -192,7 +213,17 @@ pub struct PartialProjectOptions {
}

#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct DefineEnv {
Expand Down Expand Up @@ -228,7 +259,7 @@ impl ProjectContainer {
// we only need to enable versioning in dev mode, since build
// is assumed to be operating over a static snapshot
versioned_content_map: if dev {
Some(VersionedContentMap::new().to_resolved().await?)
Some(VersionedContentMap::new())
} else {
None
},
Expand Down Expand Up @@ -1269,7 +1300,7 @@ impl Project {
#[turbo_tasks::function]
pub async fn emit_all_output_assets(
self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>,
output_assets: OperationVc<OutputAssets>,
) -> Result<()> {
let span = tracing::info_span!("emitting");
async move {
Expand All @@ -1292,7 +1323,7 @@ impl Project {
Ok(())
} else {
let _ = emit_assets(
*all_output_assets.await?,
all_output_assets.connect(),
node_root,
client_relative_path,
node_root,
Expand Down Expand Up @@ -1469,21 +1500,14 @@ async fn get_referenced_output_assets(
Ok(parent.references().await?.clone_value().into_iter())
}

#[turbo_tasks::function]
async fn all_assets_from_entries_operation_inner(
operation: Vc<OutputAssetsOperation>,
#[turbo_tasks::function(operation)]
async fn all_assets_from_entries_operation(
operation: OperationVc<OutputAssets>,
) -> Result<Vc<OutputAssets>> {
let assets = *operation.await?;
Vc::connect(assets);
let assets = operation.connect();
Ok(all_assets_from_entries(assets))
}

fn all_assets_from_entries_operation(
operation: Vc<OutputAssetsOperation>,
) -> Vc<OutputAssetsOperation> {
Vc::cell(all_assets_from_entries_operation_inner(operation))
}

#[turbo_tasks::function]
fn stable_endpoint(endpoint: Vc<Box<dyn Endpoint>>) -> Vc<Box<dyn Endpoint>> {
endpoint
Expand Down
Loading

0 comments on commit d2b9792

Please sign in to comment.