Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Task inputs

Introduction

In Turbo-Engine, task functions are the cornerstone of the build system. To ensure efficient and correct builds, only specific types of arguments, known as TaskInputs, can be passed to these functions. This guide details the requirements and types of task inputs permissible in Turbo-Engine.

Requirements for Task Inputs

Serialization

For persistent caching to function effectively, arguments must be serializable. This ensures that the state of a task can be saved and restored without loss of fidelity. This means the implementation of Serialize and Deserialize traits is necessary for task inputs.

HashMap Key

Arguments are also used as keys in a HashMap, necessitating the implementation of PartialEq, Eq, and Hash traits.

Types of Task Inputs

Vc<T>

A Vc<T> is a pointer to a cell and serves as a "pass by reference" argument:

  • Memoization: It's important to note that Vc<T> is keyed by pointer for memoization purposes. Identical values in different cells are treated as distinct.
  • Singleton Pattern: To ensure memoization efficiency, the Singleton pattern can be employed to guarantee that identical values yield the same Vc. For more info see Singleton Pattern Guide.

Deriving TaskInput

Structs or enums can be made into task inputs by deriving TaskInput:

#![allow(unused)]
fn main() {
#[derive(TaskInput)]
struct MyStruct {
    // Fields go here...
}
}
  • Pass by Value: Derived TaskInput types are passed by value, which involves cloning the value multiple times. It's recommended to ensure that these types are inexpensive to clone.

Deprecated: Value<T>

The Value<T> type is a legacy way to define task inputs and should no longer be used.

Future Consideration: Arc<T>

The use of Arc<T> where T implements TaskInput is under consideration for future implementation.

Conclusion

Understanding and utilizing the correct task inputs is vital for the smooth operation of Turbo-Engine. By adhering to the guidelines outlined in this document, developers can ensure that their tasks are set up for success, leading to faster and more accurate builds.