3 unstable releases

0.1.0 Apr 9, 2024
0.0.2 Mar 27, 2023
0.0.1 Mar 26, 2023

#112 in Programming languages

Download history 13/week @ 2023-12-22 6/week @ 2024-01-05 2/week @ 2024-01-19 17/week @ 2024-01-26 5/week @ 2024-02-16 24/week @ 2024-02-23 4/week @ 2024-03-01 16/week @ 2024-03-29 119/week @ 2024-04-05

135 downloads per month
Used in smart_ir

Apache-2.0 OR MIT

58KB
1K SLoC

[WIP] compiler_base_parallel

Summary

compiler_base_parallel defines the core logic for multitasking execution engine. It aims to provide reusable components and accumulate some general concurrency models for compiler developments.

The compiler_base_parallel crate consists of three main components: Task, Executor, and Reporter.

Task

Task is the smallest executable unit, anything can be considered as a Task can be executed by Executor. Therefore, we provide a trait to define a Task.

pub trait Task {
    /// [`run`] will be executed of the [[`Task`](./src/task/mod.rs)],
    /// and the result of the execution is communicated with other threads through the [`ch`] which is a [`Sender<FinishedTask>`],
    /// so [`run`] method does not need to return a value.
    fn run(&self, ch: Sender<FinishedTask>);

    /// Return the [`TaskInfo`]
    fn info(&self) -> TaskInfo;
}

To develop a concurrency mechanism for a compiler in a compiler_base_parallel-way, the first step is to create a Task.

For more information about Task, see the docs in source code in ./src/task/mod.rs.

Executor

Executor is responsible for executing the Task.

We also provide a trait to define a Executor.

pub trait Executor {
    /// [`run_all_tasks`] will execute all tasks concurrently.
    /// [`notify_what_happened`] is a notifier that receives [`TaskEvent`] to output the [[`Task`](./src/task/mod.rs)] execution status in to the log.
    fn run_all_tasks<T, F>(self, tasks: Vec<T>, notify_what_happened: F) -> Result<()>
    where
        T: Task + Sync + Send + 'static,
        F: Fn(TaskEvent) -> Result<()>;

    /// The count for threads.
    fn concurrency_capacity(&self) -> usize;
}

For more information about Executor, see docs in source code in ./src/executor/mod.rs.

TimeoutExecutor

TimeoutExecutor refers to the concurrency mechanism adopted by rustc in the rust unit testing and mainly contains the following features:

  • Tasks are executed concurrently based on the number of threads.

  • A timeout queue is used to monitor the execution of the Task has timed out. If it does, a warning will be reported, but the Task will not stop and will run until it is manually interrupted.

If you want to implement unit testing, fuzz, bench or other you want to do in parallel in your compiler using the same workflow as rustc testing, you can use the TimeoutExecutor. If this workflow is not suitable for your compiler, you can choose to implement your own Executor.

[WIP] Reporter

Dependencies

~3–13MB
~111K SLoC