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

perf(turbopack): Use ResolvedVc for turbopack, turbopack-tests, turbopack-wasm #73196

Merged
merged 20 commits into from
Nov 26, 2024
26 changes: 13 additions & 13 deletions turbopack/crates/turbopack-tests/tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ use crate::util::REPO_ROOT;

#[turbo_tasks::value]
struct RunTestResult {
js_result: Vc<JsResult>,
path: Vc<FileSystemPath>,
js_result: ResolvedVc<JsResult>,
path: ResolvedVc<FileSystemPath>,
}

#[turbo_tasks::value]
Expand Down Expand Up @@ -190,7 +190,7 @@ async fn run_inner(
snapshot_issues(prepared_test, run_result).await?;
}

Ok(run_result.await?.js_result)
Ok(*run_result.await?.js_result)
}

#[derive(PartialEq, Eq, Debug, Default, Serialize, Deserialize, TraceRawVcs, ValueDebugFormat)]
Expand All @@ -201,9 +201,9 @@ struct TestOptions {

#[turbo_tasks::value]
struct PreparedTest {
path: Vc<FileSystemPath>,
project_path: Vc<FileSystemPath>,
tests_path: Vc<FileSystemPath>,
path: ResolvedVc<FileSystemPath>,
project_path: ResolvedVc<FileSystemPath>,
tests_path: ResolvedVc<FileSystemPath>,
project_root: ResolvedVc<FileSystemPath>,
options: TestOptions,
}
Expand Down Expand Up @@ -245,10 +245,10 @@ async fn prepare_test(resource: RcStr) -> Result<Vc<PreparedTest>> {
}

Ok(PreparedTest {
path,
project_path,
tests_path,
project_root,
path: path.to_resolved().await?,
project_path: project_path.to_resolved().await?,
tests_path: tests_path.to_resolved().await?,
project_root: project_root.to_resolved().await?,
options,
}
.cell())
Expand Down Expand Up @@ -392,7 +392,7 @@ async fn run_test(prepared_test: Vc<PreparedTest>) -> Result<Vc<RunTestResult>>

let res = evaluate(
jest_entry_asset,
path,
*path,
Vc::upcast(CommandLineProcessEnv::new()),
test_source.ident(),
asset_context,
Expand All @@ -418,14 +418,14 @@ async fn run_test(prepared_test: Vc<PreparedTest>) -> Result<Vc<RunTestResult>>
test_results: vec![],
},
}
.cell(),
.resolved_cell(),
path,
}
.cell());
};

Ok(RunTestResult {
js_result: JsResult::cell(parse_json_with_source_context(bytes.to_str()?)?),
js_result: JsResult::resolved_cell(parse_json_with_source_context(bytes.to_str()?)?),
path,
}
.cell())
Expand Down
36 changes: 18 additions & 18 deletions turbopack/crates/turbopack-wasm/src/module_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ fn modifier() -> Vc<RcStr> {
#[turbo_tasks::value]
#[derive(Clone)]
pub struct WebAssemblyModuleAsset {
source: Vc<WebAssemblySource>,
asset_context: Vc<Box<dyn AssetContext>>,
source: ResolvedVc<WebAssemblySource>,
asset_context: ResolvedVc<Box<dyn AssetContext>>,
}

#[turbo_tasks::value_impl]
impl WebAssemblyModuleAsset {
#[turbo_tasks::function]
pub fn new(
source: Vc<WebAssemblySource>,
asset_context: Vc<Box<dyn AssetContext>>,
source: ResolvedVc<WebAssemblySource>,
asset_context: ResolvedVc<Box<dyn AssetContext>>,
) -> Vc<Self> {
Self::cell(WebAssemblyModuleAsset {
source,
Expand All @@ -57,7 +57,7 @@ impl WebAssemblyModuleAsset {

#[turbo_tasks::function]
fn wasm_asset(&self, chunking_context: Vc<Box<dyn ChunkingContext>>) -> Vc<WebAssemblyAsset> {
WebAssemblyAsset::new(self.source, chunking_context)
WebAssemblyAsset::new(*self.source, chunking_context)
}

#[turbo_tasks::function]
Expand All @@ -66,15 +66,15 @@ impl WebAssemblyModuleAsset {
let query = &*this.source.ident().query().await?;

let loader_source = if query == "?module" {
compiling_loader_source(this.source)
compiling_loader_source(*this.source)
} else {
instantiating_loader_source(this.source)
instantiating_loader_source(*this.source)
};

let module = this.asset_context.process(
loader_source,
Value::new(ReferenceType::Internal(ResolvedVc::cell(fxindexmap! {
"WASM_PATH".into() => ResolvedVc::upcast(RawWebAssemblyModuleAsset::new(this.source, this.asset_context).to_resolved().await?),
"WASM_PATH".into() => ResolvedVc::upcast(RawWebAssemblyModuleAsset::new(*this.source, *this.asset_context).to_resolved().await?),
}))),
).module();

Expand Down Expand Up @@ -134,8 +134,8 @@ impl Asset for WebAssemblyModuleAsset {
impl ChunkableModule for WebAssemblyModuleAsset {
#[turbo_tasks::function]
fn as_chunk_item(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
self: ResolvedVc<Self>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> {
Vc::upcast(
ModuleChunkItem {
Expand Down Expand Up @@ -169,7 +169,7 @@ impl ResolveOrigin for WebAssemblyModuleAsset {

#[turbo_tasks::function]
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
self.asset_context
*self.asset_context
}

#[turbo_tasks::function]
Expand All @@ -180,8 +180,8 @@ impl ResolveOrigin for WebAssemblyModuleAsset {

#[turbo_tasks::value]
struct ModuleChunkItem {
module: Vc<WebAssemblyModuleAsset>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module: ResolvedVc<WebAssemblyModuleAsset>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
Expand All @@ -196,14 +196,14 @@ impl ChunkItem for ModuleChunkItem {
let loader = self
.module
.loader()
.as_chunk_item(Vc::upcast(self.chunking_context));
.as_chunk_item(Vc::upcast(*self.chunking_context));

loader.references()
}

#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
Vc::upcast(self.chunking_context)
Vc::upcast(*self.chunking_context)
}

#[turbo_tasks::function]
Expand All @@ -215,7 +215,7 @@ impl ChunkItem for ModuleChunkItem {

#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(self.module)
Vc::upcast(*self.module)
}

#[turbo_tasks::function]
Expand All @@ -228,7 +228,7 @@ impl ChunkItem for ModuleChunkItem {
impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context
*self.chunking_context
}

#[turbo_tasks::function]
Expand All @@ -242,7 +242,7 @@ impl EcmascriptChunkItem for ModuleChunkItem {
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<EcmascriptChunkItemContent>> {
let loader_asset = self.module.loader();
let item = loader_asset.as_chunk_item(Vc::upcast(self.chunking_context));
let item = loader_asset.as_chunk_item(Vc::upcast(*self.chunking_context));

let ecmascript_item = Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkItem>>(item)
.await?
Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack-wasm/src/output_asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use turbo_rcstr::RcStr;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::ChunkingContext,
Expand All @@ -19,16 +19,16 @@ fn modifier() -> Vc<RcStr> {
/// [ChunkingContext].
#[turbo_tasks::value]
pub(crate) struct WebAssemblyAsset {
source: Vc<WebAssemblySource>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
source: ResolvedVc<WebAssemblySource>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
impl WebAssemblyAsset {
#[turbo_tasks::function]
pub(crate) fn new(
source: Vc<WebAssemblySource>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
source: ResolvedVc<WebAssemblySource>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<Self> {
Self::cell(WebAssemblyAsset {
source,
Expand Down
43 changes: 23 additions & 20 deletions turbopack/crates/turbopack-wasm/src/raw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext},
Expand Down Expand Up @@ -30,16 +30,16 @@ fn modifier() -> Vc<RcStr> {
#[turbo_tasks::value]
#[derive(Clone)]
pub struct RawWebAssemblyModuleAsset {
source: Vc<WebAssemblySource>,
asset_context: Vc<Box<dyn AssetContext>>,
source: ResolvedVc<WebAssemblySource>,
asset_context: ResolvedVc<Box<dyn AssetContext>>,
}

#[turbo_tasks::value_impl]
impl RawWebAssemblyModuleAsset {
#[turbo_tasks::function]
pub fn new(
source: Vc<WebAssemblySource>,
asset_context: Vc<Box<dyn AssetContext>>,
source: ResolvedVc<WebAssemblySource>,
asset_context: ResolvedVc<Box<dyn AssetContext>>,
) -> Vc<Self> {
Self::cell(RawWebAssemblyModuleAsset {
source,
Expand All @@ -49,7 +49,7 @@ impl RawWebAssemblyModuleAsset {

#[turbo_tasks::function]
fn wasm_asset(&self, chunking_context: Vc<Box<dyn ChunkingContext>>) -> Vc<WebAssemblyAsset> {
WebAssemblyAsset::new(self.source, chunking_context)
WebAssemblyAsset::new(*self.source, chunking_context)
}
}

Expand All @@ -75,18 +75,21 @@ impl Asset for RawWebAssemblyModuleAsset {
#[turbo_tasks::value_impl]
impl ChunkableModule for RawWebAssemblyModuleAsset {
#[turbo_tasks::function]
fn as_chunk_item(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> {
Vc::upcast(
async fn as_chunk_item(
self: ResolvedVc<Self>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Result<Vc<Box<dyn turbopack_core::chunk::ChunkItem>>> {
Ok(Vc::upcast(
RawModuleChunkItem {
module: self,
chunking_context,
wasm_asset: self.wasm_asset(Vc::upcast(chunking_context)),
wasm_asset: self
.wasm_asset(Vc::upcast(*chunking_context))
.to_resolved()
.await?,
}
.cell(),
)
))
}
}

Expand All @@ -100,9 +103,9 @@ impl EcmascriptChunkPlaceable for RawWebAssemblyModuleAsset {

#[turbo_tasks::value]
struct RawModuleChunkItem {
module: Vc<RawWebAssemblyModuleAsset>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
wasm_asset: Vc<WebAssemblyAsset>,
module: ResolvedVc<RawWebAssemblyModuleAsset>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
wasm_asset: ResolvedVc<WebAssemblyAsset>,
}

#[turbo_tasks::value_impl]
Expand All @@ -115,14 +118,14 @@ impl ChunkItem for RawModuleChunkItem {
#[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![Vc::upcast(SingleOutputAssetReference::new(
Vc::upcast(self.wasm_asset),
Vc::upcast(*self.wasm_asset),
Vc::cell(format!("wasm(url) {}", self.wasm_asset.ident().to_string().await?).into()),
))]))
}

#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
Vc::upcast(self.chunking_context)
Vc::upcast(*self.chunking_context)
}

#[turbo_tasks::function]
Expand All @@ -134,15 +137,15 @@ impl ChunkItem for RawModuleChunkItem {

#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(self.module)
Vc::upcast(*self.module)
}
}

#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for RawModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context
*self.chunking_context
}

#[turbo_tasks::function]
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-wasm/src/source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, TaskInput, Vc};
use turbo_tasks::{trace::TraceRawVcs, ResolvedVc, TaskInput, Vc};
use turbo_tasks_fs::{File, FileContent};
use turbopack_core::{
asset::{Asset, AssetContent},
Expand Down Expand Up @@ -34,14 +34,14 @@ pub enum WebAssemblySourceType {
#[turbo_tasks::value]
#[derive(Clone)]
pub struct WebAssemblySource {
source: Vc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>,
source_ty: WebAssemblySourceType,
}

#[turbo_tasks::value_impl]
impl WebAssemblySource {
#[turbo_tasks::function]
pub fn new(source: Vc<Box<dyn Source>>, source_ty: WebAssemblySourceType) -> Vc<Self> {
pub fn new(source: ResolvedVc<Box<dyn Source>>, source_ty: WebAssemblySourceType) -> Vc<Self> {
Self::cell(WebAssemblySource { source, source_ty })
}
}
Expand Down
Loading
Loading