struct DrainState<'cfg> {
Show 20 fields total_units: usize, queue: DependencyQueue<Unit, Artifact, Job>, messages: Arc<Queue<Message>>, diag_dedupe: DiagDedupe<'cfg>, warning_count: HashMap<JobId, WarningCount>, active: HashMap<JobId, Unit>, compiled: HashSet<PackageId>, documented: HashSet<PackageId>, scraped: HashSet<PackageId>, counts: HashMap<PackageId, usize>, progress: Progress<'cfg>, next_id: u32, timings: Timings<'cfg>, tokens: Vec<Acquired>, rustc_tokens: HashMap<JobId, Vec<Acquired>>, to_send_clients: BTreeMap<JobId, Vec<Client>>, pending_queue: Vec<(Unit, Job, usize)>, print: DiagnosticPrinter<'cfg>, finished: usize, per_package_future_incompat_reports: Vec<FutureIncompatReportPackage>,
}
Expand description

This structure is backed by the DependencyQueue type and manages the actual compilation step of each package. Packages enqueue units of work and then later on the entire graph is processed and compiled.

It is created from JobQueue when we have fully assembled the crate graph (i.e., all package dependencies are known).

Message queue

Each thread running a process uses the message queue to send messages back to the main thread. The main thread coordinates everything, and handles printing output.

It is important to be careful which messages use push vs push_bounded. push is for priority messages (like tokens, or “finished”) where the sender shouldn’t block. We want to handle those so real work can proceed ASAP.

push_bounded is only for messages being printed to stdout/stderr. Being bounded prevents a flood of messages causing a large amount of memory being used.

push also avoids blocking which helps avoid deadlocks. For example, when the diagnostic server thread is dropped, it waits for the thread to exit. But if the thread is blocked on a full queue, and there is a critical error, the drop will deadlock. This should be fixed at some point in the future. The jobserver thread has a similar problem, though it will time out after 1 second.

Fields§

§total_units: usize§queue: DependencyQueue<Unit, Artifact, Job>§messages: Arc<Queue<Message>>§diag_dedupe: DiagDedupe<'cfg>

Diagnostic deduplication support.

§warning_count: HashMap<JobId, WarningCount>

Count of warnings, used to print a summary after the job succeeds

§active: HashMap<JobId, Unit>§compiled: HashSet<PackageId>§documented: HashSet<PackageId>§scraped: HashSet<PackageId>§counts: HashMap<PackageId, usize>§progress: Progress<'cfg>§next_id: u32§timings: Timings<'cfg>§tokens: Vec<Acquired>

Tokens that are currently owned by this Cargo, and may be “associated” with a rustc process. They may also be unused, though if so will be dropped on the next loop iteration.

Note that the length of this may be zero, but we will still spawn work, as we share the implicit token given to this Cargo process with a single rustc process.

§rustc_tokens: HashMap<JobId, Vec<Acquired>>

rustc per-thread tokens, when in jobserver-per-rustc mode.

§to_send_clients: BTreeMap<JobId, Vec<Client>>

This represents the list of rustc jobs (processes) and associated clients that are interested in receiving a token.

§pending_queue: Vec<(Unit, Job, usize)>

The list of jobs that we have not yet started executing, but have retrieved from the queue. We eagerly pull jobs off the main queue to allow us to request jobserver tokens pretty early.

§print: DiagnosticPrinter<'cfg>§finished: usize

How many jobs we’ve finished

§per_package_future_incompat_reports: Vec<FutureIncompatReportPackage>

Implementations§

This is the “main” loop, where Cargo does all work to run the compiler.

This returns an Option to prevent the use of ? on Result types because it is important for the loop to carefully handle errors.

Executes a job.

Fresh jobs block until finished (which should be very fast!), Dirty jobs will spawn a thread in the background and return immediately.

Displays a final report of the warnings emitted by a particular job.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 1240 bytes