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:
Dan Gohman
2018-04-19 10:54:57 -07:00
parent 5bc0e0e188
commit cb37c25d3a
6 changed files with 161 additions and 77 deletions

View File

@@ -236,14 +236,14 @@ where
B: Backend,
{
/// Create a new `Module`.
pub fn new(backend: B) -> Self {
pub fn new(backend_builder: B::Builder) -> Self {
Self {
names: HashMap::new(),
contents: ModuleContents {
functions: PrimaryMap::new(),
data_objects: PrimaryMap::new(),
},
backend,
backend: B::new(backend_builder),
}
}
@@ -532,10 +532,10 @@ where
}
}
/// Consume the module and return its contained `Backend`. Some `Backend`
/// implementations have additional features not available through the
/// `Module` interface.
pub fn consume(self) -> B {
self.backend
/// Consume the module and return the resulting `Product`. Some `Backend`
/// implementations may provide additional functionality available after
/// a `Module` is complete.
pub fn finish(self) -> B::Product {
self.backend.finish()
}
}