wasmtime: Pass around more contexts instead of fields (#1486)

* wasmtime: Pass around more contexts instead of fields

This commit refactors some wasmtime internals to pass around more
context-style structures rather than individual fields of each
structure. The intention here is to make the addition of fields to a
structure easier to plumb throughout the internals of wasmtime.
Currently you need to edit lots of functions to pass lots of parameters,
but ideally after this you'll only need to edit one or two struct fields
and then relevant locations have access to the information already.

Updates in this commit are:

* `debug_info` configuration is now folded into `Tunables`. Additionally
  a `wasmtime::Config` now holds a `Tunables` directly and is passed
  into an internal `Compiler`. Eventually this should allow for direct
  configuration of the `Tunables` attributes from the `wasmtime` API,
  but no new configuration is exposed at this time.

* `ModuleTranslation` is now passed around as a whole rather than
  passing individual components to allow access to all the fields,
  including `Tunables`.

This was motivated by investigating what it would take to optionally
allow loops and such to get interrupted, but that sort of codegen
setting was currently relatively difficult to plumb all the way through
and now it's hoped to be largely just an addition to `Tunables`.

* Fix lightbeam compile
This commit is contained in:
Alex Crichton
2020-04-08 19:02:49 -05:00
committed by GitHub
parent e29c224f24
commit c4e90f729c
14 changed files with 112 additions and 180 deletions

View File

@@ -3,15 +3,13 @@
use crate::cache::ModuleCacheDataTupleType;
use crate::compilation::{Compilation, CompileError, Traps};
use crate::func_environ::FuncEnvironment;
use crate::module::Module;
use crate::module_environ::FunctionBodyData;
use crate::ModuleTranslation;
// TODO: Put this in `compilation`
use crate::address_map::{ModuleAddressMap, ValueLabelsRanges};
use crate::cranelift::RelocSink;
use crate::CacheConfig;
use cranelift_codegen::isa;
use cranelift_entity::{PrimaryMap, SecondaryMap};
use cranelift_wasm::{DefinedFuncIndex, ModuleTranslationState};
/// A compiler that compiles a WebAssembly module with Lightbeam, directly translating the Wasm file.
pub struct Lightbeam;
@@ -19,26 +17,22 @@ pub struct Lightbeam;
impl crate::compilation::Compiler for Lightbeam {
/// Compile the module using Lightbeam, producing a compilation result with
/// associated relocations.
fn compile_module<'data, 'module>(
module: &'module Module,
_module_translation: &ModuleTranslationState,
function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>,
fn compile_module(
translation: &ModuleTranslation,
isa: &dyn isa::TargetIsa,
// TODO
generate_debug_info: bool,
_cache_config: &CacheConfig,
) -> Result<ModuleCacheDataTupleType, CompileError> {
if generate_debug_info {
if translation.tunables.debug_info {
return Err(CompileError::DebugInfoNotSupported);
}
let env = FuncEnvironment::new(isa.frontend_config(), &module.local);
let env = FuncEnvironment::new(isa.frontend_config(), &translation.module.local);
let mut relocations = PrimaryMap::new();
let mut codegen_session: lightbeam::CodeGenSession<_> =
lightbeam::CodeGenSession::new(function_body_inputs.len() as u32, &env);
lightbeam::CodeGenSession::new(translation.function_body_inputs.len() as u32, &env);
for (i, function_body) in &function_body_inputs {
let func_index = module.local.func_index(i);
for (i, function_body) in &translation.function_body_inputs {
let func_index = translation.module.local.func_index(i);
let mut reloc_sink = RelocSink::new(func_index);
lightbeam::translate_function(