Move the Store::signature_cache field (#847)

This commit removes the `signature_cache` field from the `Store` type
and performs a few internal changes which are aimed to be a bit forward
looking towards #777, making `Store` threadsafe.

The changes made here are:

* The `SignatureRegistry` internal type now contains the reverse map
  that `signature_cache` was serving to do. This is populated on calls
  to `register` automatically and is accompanied by a `lookup` method as
  well.

* The `register_wasmtime_signature` and `lookup_wasmtime_signature`
  methods were removed from `Store` and now instead work by using the
  `Compiler::signatures` field.

* The `SignatureRegistry` type was updated to have interior mutability.
  The global `Compiler` type is highly likely to get shared across many
  threads through `Store`, so it needs some form of lock somewhere for
  mutation of the registry of signatures and this commit opts to put it
  inside `SignatureRegistry` which will eventually allow for the removal
  of most `&mut self` method on `Compiler`.
This commit is contained in:
Alex Crichton
2020-01-22 14:54:55 -06:00
committed by GitHub
parent 5953215bac
commit e5af0ae3de
7 changed files with 48 additions and 53 deletions

View File

@@ -205,7 +205,7 @@ pub(crate) fn into_checked_anyfunc(
} => (*vmctx, *address, signature),
_ => panic!("expected function export"),
};
let type_index = store.register_wasmtime_signature(signature);
let type_index = store.compiler().signatures().register(signature);
wasmtime_runtime::VMCallerCheckedAnyfunc {
func_ptr,
type_index,
@@ -224,7 +224,9 @@ pub(crate) fn from_checked_anyfunc(
return Val::AnyRef(AnyRef::Null);
}
let signature = store
.lookup_wasmtime_signature(item.type_index)
.compiler()
.signatures()
.lookup(item.type_index)
.expect("signature");
let instance_handle = unsafe { wasmtime_runtime::InstanceHandle::from_vmctx(item.vmctx) };
let export = wasmtime_runtime::Export::Function {