Skip to main content

BuildGraph

Struct BuildGraph 

Source
pub struct BuildGraph { /* private fields */ }
Expand description

A validated, acyclic build graph.

Construct one with GraphBuilder. Once built, a graph is immutable and known to be acyclic, so traversals need no cycle guard.

use critpath_core::{EdgeKind, GraphBuilder, Millis, Unit, UnitKind};

let mut builder = GraphBuilder::new();
let lib = builder.add_unit(Unit {
    package: "leaf".to_owned(),
    version: "1.0.0".to_owned(),
    target: "leaf".to_owned(),
    kind: UnitKind::Lib,
    total: Millis::new(800),
    metadata_at: Some(Millis::new(600)),
    requires_full_closure: false,
})?;
let bin = builder.add_unit(Unit {
    package: "app".to_owned(),
    version: "1.0.0".to_owned(),
    target: "app".to_owned(),
    kind: UnitKind::Bin,
    total: Millis::new(200),
    metadata_at: None,
    requires_full_closure: true,
})?;
builder.add_edge(lib, bin, EdgeKind::Full)?;

let graph = builder.build()?;
assert_eq!(graph.len(), 2);
assert_eq!(graph.total_work(), Millis::new(1_000));

Implementations§

Source§

impl BuildGraph

Source

pub fn len(&self) -> usize

How many units the graph holds.

Source

pub fn is_empty(&self) -> bool

Whether the graph holds no units.

Source

pub fn edge_count(&self) -> usize

How many edges the graph holds, after duplicates have been merged.

Examples found in repository?
examples/scaling.rs (line 100)
78fn main() -> Result<(), Box<dyn Error>> {
79    let executors = NonZeroU32::new(16).ok_or("16 is not zero")?;
80    println!(
81        "{:>7}  {:>8}  {:>10}  {:>10}  {:>10}",
82        "units", "edges", "construct", "analyse", "simulate"
83    );
84    for &(units, fan_in) in &[(1_000, 4), (5_000, 4), (20_000, 6), (50_000, 6)] {
85        let start = Instant::now();
86        let graph = build(units, fan_in)?;
87        let constructed = start.elapsed();
88
89        let start = Instant::now();
90        let analysis = analyze(&graph);
91        let analysed = start.elapsed();
92
93        let start = Instant::now();
94        let schedule = simulate(&graph, executors, Policy::CargoLike);
95        let simulated = start.elapsed();
96
97        println!(
98            "{:>7}  {:>8}  {:>10.1?}  {:>10.1?}  {:>10.1?}   critical path {}, makespan {}",
99            units,
100            graph.edge_count(),
101            constructed,
102            analysed,
103            simulated,
104            analysis.critical_path_len(),
105            schedule.makespan(),
106        );
107    }
108    Ok(())
109}
Source

pub fn total_work(&self) -> Millis

The sum of every unit’s duration, which is the total work a build must perform.

Source

pub fn unit(&self, id: UnitId) -> Option<&Unit>

The unit id refers to, or None if the index is outside this graph.

An identifier belonging to a different graph is not detected: identifiers are dense indices, so a foreign one reads as None only when it points past the end, and otherwise names a different unit. Do not mix identifiers between graphs.

Source

pub fn units(&self) -> impl ExactSizeIterator<Item = (UnitId, &Unit)> + '_

Every unit, in identifier order.

Source

pub fn dependencies(&self, id: UnitId) -> Option<&[Dep]>

The units id depends on, or None if the index is outside this graph.

Source

pub fn dependents(&self, id: UnitId) -> Option<&[Dep]>

The units that depend on id, or None if the index is outside this graph.

Source

pub fn topological_order(&self) -> &[UnitId]

Every unit in an order that places each dependency before its dependents.

Trait Implementations§

Source§

impl Clone for BuildGraph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BuildGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.