Skip to content

Commit

Permalink
refactor(turbopack/next-api): Implement NonLocalValue for TracedDiGra…
Browse files Browse the repository at this point in the history
…ph and SingleModuleGraph
  • Loading branch information
bgw committed Jan 10, 2025
1 parent d737cef commit 7d58974
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions turbopack/crates/turbopack-core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
#[derive(Clone, Debug)]
pub struct ModuleSet(pub HashSet<ResolvedVc<Box<dyn Module>>>);

#[turbo_tasks::value(cell = "new", eq = "manual", into = "new", local)]
#[turbo_tasks::value(cell = "new", eq = "manual", into = "new")]
#[derive(Clone, Default)]
pub struct SingleModuleGraph {
graph: TracedDiGraph<SingleModuleGraphNode, ChunkingType>,
Expand Down Expand Up @@ -349,13 +349,18 @@ impl SingleModuleGraphNode {
}

#[derive(Clone, Debug, ValueDebugFormat, Serialize, Deserialize)]
struct TracedDiGraph<N: TraceRawVcs, E: TraceRawVcs>(DiGraph<N, E>);
impl<N: TraceRawVcs, E: TraceRawVcs> Default for TracedDiGraph<N, E> {
struct TracedDiGraph<N, E>(DiGraph<N, E>);
impl<N, E> Default for TracedDiGraph<N, E> {
fn default() -> Self {
Self(Default::default())
}
}
impl<N: TraceRawVcs, E: TraceRawVcs> TraceRawVcs for TracedDiGraph<N, E> {

impl<N, E> TraceRawVcs for TracedDiGraph<N, E>
where
N: TraceRawVcs,
E: TraceRawVcs,
{
fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) {
for node in self.0.node_weights() {
node.trace_raw_vcs(trace_context);
Expand All @@ -365,13 +370,21 @@ impl<N: TraceRawVcs, E: TraceRawVcs> TraceRawVcs for TracedDiGraph<N, E> {
}
}
}
impl<N: TraceRawVcs, E: TraceRawVcs> Deref for TracedDiGraph<N, E> {

impl<N, E> Deref for TracedDiGraph<N, E> {
type Target = DiGraph<N, E>;
fn deref(&self) -> &Self::Target {
&self.0
}
}

unsafe impl<N, E> NonLocalValue for TracedDiGraph<N, E>
where
N: NonLocalValue,
E: NonLocalValue,
{
}

#[derive(PartialEq, Eq, Debug)]
pub enum GraphTraversalAction {
/// Continue visiting children
Expand Down

0 comments on commit 7d58974

Please sign in to comment.