Remove dependency on TargetIsa from Wasmtime crates (#3178)

This commit started off by deleting the `cranelift_codegen::settings`
reexport in the `wasmtime-environ` crate and then basically played
whack-a-mole until everything compiled again. The main result of this is
that the `wasmtime-*` family of crates have generally less of a
dependency on the `TargetIsa` trait and type from Cranelift. While the
dependency isn't entirely severed yet this is at least a significant
start.

This commit is intended to be largely refactorings, no functional
changes are intended here. The refactorings are:

* A `CompilerBuilder` trait has been added to `wasmtime_environ` which
  server as an abstraction used to create compilers and configure them
  in a uniform fashion. The `wasmtime::Config` type now uses this
  instead of cranelift-specific settings. The `wasmtime-jit` crate
  exports the ability to create a compiler builder from a
  `CompilationStrategy`, which only works for Cranelift right now. In a
  cranelift-less build of Wasmtime this is expected to return a trait
  object that fails all requests to compile.

* The `Compiler` trait in the `wasmtime_environ` crate has been souped
  up with a number of methods that Wasmtime and other crates needed.

* The `wasmtime-debug` crate is now moved entirely behind the
  `wasmtime-cranelift` crate.

* The `wasmtime-cranelift` crate is now only depended on by the
  `wasmtime-jit` crate.

* Wasm types in `cranelift-wasm` no longer contain their IR type,
  instead they only contain the `WasmType`. This is required to get
  everything to align correctly but will also be required in a future
  refactoring where the types used by `cranelift-wasm` will be extracted
  to a separate crate.

* I moved around a fair bit of code in `wasmtime-cranelift`.

* Some gdb-specific jit-specific code has moved from `wasmtime-debug` to
  `wasmtime-jit`.
This commit is contained in:
Alex Crichton
2021-08-16 09:55:39 -05:00
committed by GitHub
parent 7c0948fe0b
commit 0313e30d76
47 changed files with 1529 additions and 1384 deletions

View File

@@ -1,9 +1,11 @@
//! The module that implements the `wasmtime settings` command.
use anyhow::{anyhow, Result};
use std::collections::BTreeMap;
use std::str::FromStr;
use structopt::StructOpt;
use wasmtime_environ::settings::{self, Setting, SettingKind};
use wasmtime_environ::{FlagValue, Setting, SettingKind};
use wasmtime_jit::Compiler;
/// Displays available Cranelift settings for a target.
#[derive(StructOpt)]
@@ -17,19 +19,18 @@ pub struct SettingsCommand {
impl SettingsCommand {
/// Executes the command.
pub fn execute(self) -> Result<()> {
let settings = match &self.target {
Some(target) => wasmtime_environ::isa::lookup(
target_lexicon::Triple::from_str(target).map_err(|e| anyhow!(e))?,
)?,
None => cranelift_native::builder().unwrap(),
};
let mut builder = Compiler::builder(wasmtime_jit::CompilationStrategy::Auto);
if let Some(target) = &self.target {
let target = target_lexicon::Triple::from_str(target).map_err(|e| anyhow!(e))?;
builder.target(target)?;
}
let mut enums = (Vec::new(), 0, "Enum settings:");
let mut nums = (Vec::new(), 0, "Numerical settings:");
let mut bools = (Vec::new(), 0, "Boolean settings:");
let mut presets = (Vec::new(), 0, "Presets:");
for setting in settings.iter() {
for setting in builder.settings() {
let (collection, max, _) = match setting.kind {
SettingKind::Enum => &mut enums,
SettingKind::Num => &mut nums,
@@ -45,11 +46,11 @@ impl SettingsCommand {
}
if enums.0.is_empty() && nums.0.is_empty() && bools.0.is_empty() && presets.0.is_empty() {
println!("Target '{}' has no settings.", settings.triple());
println!("Target '{}' has no settings.", builder.triple());
return Ok(());
}
println!("Cranelift settings for target '{}':", settings.triple());
println!("Cranelift settings for target '{}':", builder.triple());
for (collection, max, header) in &mut [enums, nums, bools, presets] {
if collection.is_empty() {
@@ -62,16 +63,15 @@ impl SettingsCommand {
}
if self.target.is_none() {
let isa = settings.finish(settings::Flags::new(settings::builder()));
let compiler = builder.build();
println!();
println!("Settings inferred for the current host:");
let mut values = isa.isa_flags();
values.sort_by_key(|k| k.name);
let values = compiler.isa_flags().into_iter().collect::<BTreeMap<_, _>>();
for value in values {
if value.as_bool().unwrap_or(false) {
println!(" {}", value.name);
for (name, value) in values {
if let FlagValue::Bool(true) = value {
println!(" {}", name);
}
}
}