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 4, 2025
1 parent 131f830 commit b8abe7b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crates/next-api/src/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,21 @@ impl SingleModuleGraphNode {
}
}

/// A wrapper of [`DiGraph`] that implements [`TraceRawVcs`] (and [`NonLocalValue`]) when the nodes
/// and edges do.
#[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 @@ -89,14 +96,22 @@ 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
}
}

#[turbo_tasks::value(cell = "new", eq = "manual", into = "new", local)]
unsafe impl<N, E> NonLocalValue for TracedDiGraph<N, E>
where
N: NonLocalValue,
E: NonLocalValue,
{
}

#[turbo_tasks::value(cell = "new", eq = "manual", into = "new")]
#[derive(Clone, Default)]
pub struct SingleModuleGraph {
graph: TracedDiGraph<SingleModuleGraphNode, ChunkingType>,
Expand Down

0 comments on commit b8abe7b

Please sign in to comment.