Refactor where results of compilation are stored (#2086)
* Refactor where results of compilation are stored This commit refactors the internals of compilation in Wasmtime to change where results of individual function compilation are stored. Previously compilation resulted in many maps being returned, and compilation results generally held all these maps together. This commit instead switches this to have all metadata stored in a `CompiledFunction` instead of having a separate map for each item that can be stored. The motivation for this is primarily to help out with future module-linking-related PRs. What exactly "module level" is depends on how we interpret modules and how many modules are in play, so it's a bit easier for operations in wasmtime to work at the function level where possible. This means that we don't have to pass around multiple different maps and a function index, but instead just one map or just one entry representing a compiled function. Additionally this change updates where the parallelism of compilation happens, pushing it into `wasmtime-jit` instead of `wasmtime-environ`. This is another goal where `wasmtime-jit` will have more knowledge about module-level pieces with module linking in play. User-facing-wise this should be the same in terms of parallel compilation, though. The ultimate goal of this refactoring is to make it easier for the results of compilation to actually be a set of wasm modules. This means we won't be able to have a map-per-metadata where the primary key is the function index, because there will be many modules within one "object file". * Don't clear out fields, just don't store them Persist a smaller set of fields in `CompilationArtifacts` instead of trying to clear fields out and dynamically not accessing them.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! A double-ended iterator over entity references and entities.
|
||||
|
||||
use crate::EntityRef;
|
||||
use alloc::vec;
|
||||
use core::iter::Enumerate;
|
||||
use core::marker::PhantomData;
|
||||
use core::slice;
|
||||
@@ -84,3 +85,40 @@ impl<'a, K: EntityRef, V> DoubleEndedIterator for IterMut<'a, K, V> {
|
||||
}
|
||||
|
||||
impl<'a, K: EntityRef, V> ExactSizeIterator for IterMut<'a, K, V> {}
|
||||
|
||||
/// Iterate over all keys in order.
|
||||
pub struct IntoIter<K: EntityRef, V> {
|
||||
enumerate: Enumerate<vec::IntoIter<V>>,
|
||||
unused: PhantomData<K>,
|
||||
}
|
||||
|
||||
impl<K: EntityRef, V> IntoIter<K, V> {
|
||||
/// Create an `IntoIter` iterator that visits the `PrimaryMap` keys and values
|
||||
/// of `iter`.
|
||||
pub fn new(iter: vec::IntoIter<V>) -> Self {
|
||||
Self {
|
||||
enumerate: iter.enumerate(),
|
||||
unused: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: EntityRef, V> Iterator for IntoIter<K, V> {
|
||||
type Item = (K, V);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.enumerate.next().map(|(i, v)| (K::new(i), v))
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.enumerate.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: EntityRef, V> DoubleEndedIterator for IntoIter<K, V> {
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
self.enumerate.next_back().map(|(i, v)| (K::new(i), v))
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: EntityRef, V> ExactSizeIterator for IntoIter<K, V> {}
|
||||
|
||||
@@ -131,6 +131,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Default for SecondaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
V: Clone + Default,
|
||||
{
|
||||
fn default() -> SecondaryMap<K, V> {
|
||||
SecondaryMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Immutable indexing into an `SecondaryMap`.
|
||||
///
|
||||
/// All keys are permitted. Untouched entries have the default value.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Densely numbered entity references as mapping keys.
|
||||
use crate::boxed_slice::BoxedSlice;
|
||||
use crate::iter::{Iter, IterMut};
|
||||
use crate::iter::{IntoIter, Iter, IterMut};
|
||||
use crate::keys::Keys;
|
||||
use crate::EntityRef;
|
||||
use alloc::boxed::Box;
|
||||
@@ -150,6 +150,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Default for PrimaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
{
|
||||
fn default() -> PrimaryMap<K, V> {
|
||||
PrimaryMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Immutable indexing into an `PrimaryMap`.
|
||||
/// The indexed value must be in the map.
|
||||
impl<K, V> Index<K> for PrimaryMap<K, V>
|
||||
@@ -173,6 +182,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> IntoIterator for PrimaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
{
|
||||
type Item = (K, V);
|
||||
type IntoIter = IntoIter<K, V>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
IntoIter::new(self.elems.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
|
||||
Reference in New Issue
Block a user