compiler_base_parallel

Crates.iocompiler_base_parallel
lib.rscompiler_base_parallel
version0.1.0
sourcesrc
created_at2023-03-26 15:54:32.542484
updated_at2024-04-09 03:16:28.198277
descriptionA common domain programming language framework.
homepagehttps://github.com/kcl-lang/kcl
repositoryhttps://github.com/kcl-lang/kcl
max_upload_size
id821344
size72,622
zongz (zong-zhe)

documentation

README

[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

Commit count: 830

cargo fmt