Skip to content

Commit

Permalink
make with_layer return Vc<Self> (#5563)
Browse files Browse the repository at this point in the history
### Description

Using the new ability to return `Vc<Self>`

Co-authored-by: Alex Kirszenberg <alexkirsz@users.noreply.github.com>
  • Loading branch information
sokra and alexkirsz committed Jul 19, 2023
1 parent c78593b commit 229a2a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/turbopack-build/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ impl ChunkingContext for BuildChunkingContext {
}

#[turbo_tasks::function]
async fn with_layer(self: Vc<Self>, layer: String) -> Result<Vc<Box<dyn ChunkingContext>>> {
async fn with_layer(self: Vc<Self>, layer: String) -> Result<Vc<Self>> {
let mut context = self.await?.clone_value();
context.layer = (!layer.is_empty()).then(|| layer.to_string());
Ok(Vc::upcast(BuildChunkingContext::new(Value::new(context))))
Ok(BuildChunkingContext::new(Value::new(context)))
}

#[turbo_tasks::function]
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/chunk/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait ChunkingContext {
Vc::cell("".to_string())
}

fn with_layer(self: Vc<Self>, layer: String) -> Vc<Box<dyn ChunkingContext>>;
fn with_layer(self: Vc<Self>, layer: String) -> Vc<Self>;

fn chunk_group(self: Vc<Self>, entry: Vc<Box<dyn Chunk>>) -> Vc<OutputAssets>;

Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-dev/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ impl ChunkingContext for DevChunkingContext {
}

#[turbo_tasks::function]
async fn with_layer(self: Vc<Self>, layer: String) -> Result<Vc<Box<dyn ChunkingContext>>> {
async fn with_layer(self: Vc<Self>, layer: String) -> Result<Vc<Self>> {
let mut context = self.await?.clone_value();
context.layer = (!layer.is_empty()).then(|| layer.to_string());
Ok(Vc::upcast(DevChunkingContext::new(Value::new(context))))
Ok(DevChunkingContext::new(Value::new(context)))
}

#[turbo_tasks::function]
Expand Down
10 changes: 9 additions & 1 deletion crates/turbopack/src/transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use anyhow::Result;
pub use context_transition::ContextTransition;
use turbo_tasks::{Value, Vc};
use turbo_tasks::{Value, ValueDefault, Vc};
use turbopack_core::{
compile_time_info::CompileTimeInfo, module::Module, reference_type::ReferenceType,
source::Source,
Expand Down Expand Up @@ -88,3 +88,11 @@ pub trait Transition {

#[turbo_tasks::value(transparent)]
pub struct TransitionsByName(HashMap<String, Vc<Box<dyn Transition>>>);

#[turbo_tasks::value_impl]
impl ValueDefault for TransitionsByName {
#[turbo_tasks::function]
fn value_default() -> Vc<Self> {
Vc::cell(Default::default())
}
}

0 comments on commit 229a2a4

Please sign in to comment.