Skip to content

Commit ab1867e

Browse files
committed
perf(pm): share resolver placement helpers
1 parent 3dcc5f7 commit ab1867e

1 file changed

Lines changed: 101 additions & 49 deletions

File tree

crates/ruborist/src/resolver/builder.rs

Lines changed: 101 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,97 @@ pub async fn process_dependency<R: RegistryClient>(
651651
}
652652
}
653653

654+
/// Place an already-resolved registry package into the graph.
655+
///
656+
/// The demand resolver uses this after a manifest job completes; the legacy
657+
/// resolver path also goes through it so placement semantics stay shared.
658+
pub fn process_dependency_with_resolved(
659+
graph: &mut DependencyGraph,
660+
node_index: NodeIndex,
661+
edge_info: &DependencyEdgeInfo,
662+
resolved: &ResolvedPackage,
663+
config: &BuildDepsConfig,
664+
) -> ProcessResult {
665+
match graph.find_compatible_node(node_index, &edge_info.name, &edge_info.spec) {
666+
FindResult::Reuse(existing_index) => {
667+
graph.mark_dependency_resolved(edge_info.edge_id, existing_index);
668+
update_node_type_from_edge(graph, node_index, existing_index, &edge_info.edge_type);
669+
ProcessResult::Reused(existing_index)
670+
}
671+
FindResult::Conflict(conflict_parent) | FindResult::New(conflict_parent) => {
672+
let new_node = create_package_node(&edge_info.name, resolved, conflict_parent, graph);
673+
let new_index = graph.add_node(new_node);
674+
graph.add_physical_edge(conflict_parent, new_index);
675+
graph.mark_dependency_resolved(edge_info.edge_id, new_index);
676+
update_node_type_from_edge(graph, node_index, new_index, &edge_info.edge_type);
677+
add_edges_from(
678+
graph,
679+
new_index,
680+
&*resolved.manifest,
681+
&EdgeContext::new(config.peer_deps, DevDeps::Exclude),
682+
);
683+
ProcessResult::Created(new_index)
684+
}
685+
}
686+
}
687+
688+
fn chain_err<E>(
689+
graph: &DependencyGraph,
690+
parent: NodeIndex,
691+
edge: &DependencyEdgeInfo,
692+
inner: ResolveError<E>,
693+
) -> ResolveError<E> {
694+
let mut chain = graph.logical_ancestry(parent);
695+
chain.push((edge.name.clone(), edge.spec.clone()));
696+
ResolveError::WithChain {
697+
chain,
698+
source: Box::new(inner),
699+
}
700+
}
701+
702+
fn handle_processed<E: EventReceiver>(
703+
graph: &DependencyGraph,
704+
receiver: &E,
705+
parent: NodeIndex,
706+
edge: &DependencyEdgeInfo,
707+
processed: &ProcessResult,
708+
next_level: &mut Vec<NodeIndex>,
709+
) {
710+
match processed {
711+
ProcessResult::Created(idx) => {
712+
if let Some(node) = graph.get_node(*idx) {
713+
receiver.on_event(BuildEvent::Resolved {
714+
name: &edge.name,
715+
version: &node.version,
716+
});
717+
if let NodeManifest::Registry(ref manifest) = node.manifest {
718+
let parent_path = graph.get_node(parent).map(|p| p.path.as_path());
719+
receiver.on_event(BuildEvent::PackagePlaced {
720+
package: manifest.as_ref().into(),
721+
path: &node.path,
722+
parent_path,
723+
});
724+
}
725+
}
726+
next_level.push(*idx);
727+
}
728+
ProcessResult::Reused(idx) => {
729+
if let Some(node) = graph.get_node(*idx) {
730+
receiver.on_event(BuildEvent::Reused {
731+
name: &edge.name,
732+
version: &node.version,
733+
});
734+
}
735+
}
736+
ProcessResult::Skipped => {
737+
receiver.on_event(BuildEvent::Skipped {
738+
name: &edge.name,
739+
spec: &edge.spec,
740+
});
741+
}
742+
}
743+
}
744+
654745
/// Build the complete dependency tree using BFS traversal.
655746
///
656747
/// This is the main entry point for dependency resolution. It starts from
@@ -837,56 +928,17 @@ async fn run_bfs_phase<R: RegistryClient, E: EventReceiver>(
837928
receiver.on_event(BuildEvent::Resolving {
838929
name: &edge_info.name,
839930
});
840-
let result = process_dependency(graph, registry, node_index, &edge_info, config)
931+
let processed = process_dependency(graph, registry, node_index, &edge_info, config)
841932
.await
842-
.map_err(|inner| {
843-
let mut chain = graph.logical_ancestry(node_index);
844-
chain.push((edge_info.name.clone(), edge_info.spec.clone()));
845-
ResolveError::WithChain {
846-
chain,
847-
source: Box::new(inner),
848-
}
849-
});
850-
match result? {
851-
ProcessResult::Created(idx) => {
852-
// Extract node info for events
853-
if let Some(node) = graph.get_node(idx) {
854-
receiver.on_event(BuildEvent::Resolved {
855-
name: &edge_info.name,
856-
version: &node.version,
857-
});
858-
859-
// Send PackagePlaced for pipeline cloning
860-
if let NodeManifest::Registry(ref manifest) = node.manifest {
861-
// Get parent path for dependency ordering
862-
let parent_path = graph
863-
.get_node(node_index)
864-
.map(|parent| parent.path.as_path());
865-
receiver.on_event(BuildEvent::PackagePlaced {
866-
package: manifest.as_ref().into(),
867-
path: &node.path,
868-
parent_path,
869-
});
870-
}
871-
}
872-
873-
next_level.push(idx);
874-
}
875-
ProcessResult::Reused(idx) => {
876-
if let Some(node) = graph.get_node(idx) {
877-
receiver.on_event(BuildEvent::Reused {
878-
name: &edge_info.name,
879-
version: &node.version,
880-
});
881-
}
882-
}
883-
ProcessResult::Skipped => {
884-
receiver.on_event(BuildEvent::Skipped {
885-
name: &edge_info.name,
886-
spec: &edge_info.spec,
887-
});
888-
}
889-
}
933+
.map_err(|inner| chain_err(graph, node_index, &edge_info, inner))?;
934+
handle_processed(
935+
graph,
936+
receiver,
937+
node_index,
938+
&edge_info,
939+
&processed,
940+
&mut next_level,
941+
);
890942
}
891943
}
892944

0 commit comments

Comments
 (0)