Introduce Builder and Product types to the Module workflow.
This eliminates API confusion and surface area with respect to what state the `Backend` needs to be in at different points. Now, API users will construct a `Builder`, and pass it into the `Module` which uses it to constrct a `Backend`. The `Backend` instance only lives inside the `Module`. And when finished, the `Module` can return a `Product` back to the user providing any outputs it has.
This commit is contained in:
@@ -14,6 +14,9 @@ pub trait Backend
|
||||
where
|
||||
Self: marker::Sized,
|
||||
{
|
||||
/// A builder for constructing `Backend` instances.
|
||||
type Builder;
|
||||
|
||||
/// The results of compiling a function.
|
||||
type CompiledFunction;
|
||||
|
||||
@@ -21,13 +24,21 @@ where
|
||||
type CompiledData;
|
||||
|
||||
/// The completed output artifact for a function, if this is meaningful for
|
||||
/// the Backend.
|
||||
/// the `Backend`.
|
||||
type FinalizedFunction;
|
||||
|
||||
/// The completed output artifact for a data object, if this is meaningful for
|
||||
/// the Backend.
|
||||
/// the `Backend`.
|
||||
type FinalizedData;
|
||||
|
||||
/// This is an object returned by `Module`'s
|
||||
/// [`finish`](struct.Module.html#method.finish) function,
|
||||
/// if the `Backend` has a purpose for this.
|
||||
type Product;
|
||||
|
||||
/// Create a new `Backend` instance.
|
||||
fn new(Self::Builder) -> Self;
|
||||
|
||||
/// Return the `TargetIsa` to compile for.
|
||||
fn isa(&self) -> &TargetIsa;
|
||||
|
||||
@@ -94,4 +105,8 @@ where
|
||||
data: &Self::CompiledData,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
) -> Self::FinalizedData;
|
||||
|
||||
/// Consume this `Backend` and return a result. Some implementations may
|
||||
/// provide additional functionality through this result.
|
||||
fn finish(self) -> Self::Product;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user