Skip to content

Commit

Permalink
Merge wasmtime-types into wasmtime-environ
Browse files Browse the repository at this point in the history
The only reason that this was originally split out was because
`cranelift-wasm` depended on `wasmtime-types`. Now that `cranelift-wasm`
has been merged into `wasmtime-cranelift` there's no need any longer to
maintain this split. This commit merges the `wasmtime-types` crate back
into `wasmtime-environ`.
  • Loading branch information
alexcrichton committed Oct 1, 2024
1 parent 7cc466a commit c91e07a
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 357 deletions.
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ wasmtime-winch = { path = "crates/winch", version = "=26.0.0" }
wasmtime-environ = { path = "crates/environ", version = "=26.0.0" }
wasmtime-explorer = { path = "crates/explorer", version = "=26.0.0" }
wasmtime-fiber = { path = "crates/fiber", version = "=26.0.0" }
wasmtime-types = { path = "crates/types", version = "26.0.0" }
wasmtime-jit-debug = { path = "crates/jit-debug", version = "=26.0.0" }
wasmtime-wast = { path = "crates/wast", version = "=26.0.0" }
wasmtime-wasi = { path = "crates/wasi", version = "26.0.0", default-features = false }
Expand Down
5 changes: 2 additions & 3 deletions crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ all-features = true
anyhow = { workspace = true }
postcard = { workspace = true }
cpp_demangle = { version = "0.4.3", optional = true }
cranelift-entity = { workspace = true }
cranelift-entity = { workspace = true, features = ['enable-serde'] }
cranelift-bitset = { workspace = true, features = ['enable-serde'] }
wasmtime-types = { workspace = true }
wasmparser = { workspace = true, features = ['validate', 'serde', 'features'] }
indexmap = { workspace = true, features = ["serde"] }
serde = { workspace = true }
Expand All @@ -37,6 +36,7 @@ wasm-encoder = { workspace = true, optional = true }
wasmprinter = { workspace = true, optional = true }
wasmtime-component-util = { workspace = true, optional = true }
semver = { workspace = true, optional = true, features = ['serde'] }
smallvec = { workspace = true, features = ['serde'] }

[dev-dependencies]
clap = { workspace = true, features = ['default'] }
Expand All @@ -61,7 +61,6 @@ compile = [
threads = ['std']
wmemcheck = ['std']
std = [
'wasmtime-types/std',
'anyhow/std',
'object/std',
'wasmparser/std',
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/compile/module_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
use crate::prelude::*;
use crate::{
obj, CompiledFunctionInfo, CompiledModuleInfo, DebugInfoData, DefinedFuncIndex, FunctionLoc,
FunctionName, MemoryInitialization, Metadata, ModuleTranslation, PrimaryMap, Tunables,
FunctionName, MemoryInitialization, Metadata, ModuleInternedTypeIndex, ModuleTranslation,
PrimaryMap, Tunables,
};
use anyhow::{bail, Result};
use object::write::{Object, SectionId, StandardSegment, WritableBuffer};
use object::SectionKind;
use std::ops::Range;
use wasmtime_types::ModuleInternedTypeIndex;

/// Helper structure to create an ELF file as a compilation artifact.
///
Expand Down
21 changes: 7 additions & 14 deletions crates/environ/src/compile/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::module::{
};
use crate::prelude::*;
use crate::{
DataIndex, DefinedFuncIndex, ElemIndex, EntityIndex, EntityType, FuncIndex, GlobalIndex,
InitMemory, MemoryIndex, ModuleTypesBuilder, PrimaryMap, StaticMemoryInitializer, TableIndex,
TableInitialValue, Tunables, TypeConvert, TypeIndex, Unsigned, WasmError, WasmHeapType,
WasmResult, WasmValType, WasmparserTypeConverter,
ConstExpr, ConstOp, DataIndex, DefinedFuncIndex, ElemIndex, EngineOrModuleTypeIndex,
EntityIndex, EntityType, FuncIndex, GlobalIndex, IndexType, InitMemory, MemoryIndex,
ModuleInternedTypeIndex, ModuleTypesBuilder, PrimaryMap, SizeOverflow, StaticMemoryInitializer,
TableIndex, TableInitialValue, Tunables, TypeConvert, TypeIndex, Unsigned, WasmError,
WasmHeapTopType, WasmHeapType, WasmResult, WasmValType, WasmparserTypeConverter,
};
use anyhow::{bail, Result};
use cranelift_entity::packed_option::ReservedValue;
Expand All @@ -21,9 +22,6 @@ use wasmparser::{
FuncToValidate, FunctionBody, KnownCustom, NameSectionReader, Naming, Parser, Payload, TypeRef,
Validator, ValidatorResources,
};
use wasmtime_types::{
ConstExpr, ConstOp, IndexType, ModuleInternedTypeIndex, SizeOverflow, WasmHeapTopType,
};

/// Object containing the standalone environment information.
pub struct ModuleEnvironment<'a, 'data> {
Expand Down Expand Up @@ -307,9 +305,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
let interned_index = self.result.module.types[index];
self.result.module.num_imported_funcs += 1;
self.result.debuginfo.wasm_file.imported_func_count += 1;
EntityType::Function(wasmtime_types::EngineOrModuleTypeIndex::Module(
interned_index,
))
EntityType::Function(EngineOrModuleTypeIndex::Module(interned_index))
}
TypeRef::Memory(ty) => {
self.result.module.num_imported_memories += 1;
Expand Down Expand Up @@ -872,10 +868,7 @@ impl TypeConvert for ModuleEnvironment<'_, '_> {
WasmparserTypeConverter::new(&self.types, &self.result.module).lookup_heap_type(index)
}

fn lookup_type_index(
&self,
index: wasmparser::UnpackedIndex,
) -> wasmtime_types::EngineOrModuleTypeIndex {
fn lookup_type_index(&self, index: wasmparser::UnpackedIndex) -> EngineOrModuleTypeIndex {
WasmparserTypeConverter::new(&self.types, &self.result.module).lookup_type_index(index)
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/environ/src/compile/module_types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{EntityRef, Module, ModuleTypes, TypeConvert};
use crate::{
EngineOrModuleTypeIndex, EntityRef, Module, ModuleInternedRecGroupIndex,
ModuleInternedTypeIndex, ModuleTypes, TypeConvert, TypeIndex, WasmCompositeType, WasmFuncType,
WasmHeapType, WasmResult, WasmSubType,
};
use std::{borrow::Cow, collections::HashMap, ops::Index};
use wasmparser::{UnpackedIndex, Validator, ValidatorId};
use wasmtime_types::{
EngineOrModuleTypeIndex, ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, TypeIndex,
WasmCompositeType, WasmFuncType, WasmHeapType, WasmResult, WasmSubType,
};

/// A type marking the start of a recursion group's definition.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@

use crate::component::*;
use crate::prelude::*;
use crate::{EntityIndex, EntityRef, PrimaryMap, WasmValType};
use crate::{EntityIndex, EntityRef, ModuleInternedTypeIndex, PrimaryMap, WasmValType};
use anyhow::Result;
use indexmap::IndexMap;
use std::collections::HashMap;
use std::hash::Hash;
use std::ops::Index;
use wasmparser::types::ComponentCoreModuleTypeId;
use wasmtime_types::ModuleInternedTypeIndex;

#[derive(Default)]
#[allow(missing_docs)]
Expand Down
3 changes: 1 addition & 2 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@

use crate::component::*;
use crate::prelude::*;
use crate::{EntityIndex, PrimaryMap, WasmValType};
use crate::{EntityIndex, ModuleInternedTypeIndex, PrimaryMap, WasmValType};
use serde_derive::{Deserialize, Serialize};
use wasmtime_types::ModuleInternedTypeIndex;

/// Metadata as a result of compiling a component.
pub struct ComponentTranslation {
Expand Down
12 changes: 4 additions & 8 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::prelude::*;
use crate::Module;
use crate::ScopeVec;
use crate::{
EntityIndex, ModuleEnvironment, ModuleTranslation, ModuleTypesBuilder, PrimaryMap, Tunables,
TypeConvert, WasmHeapType, WasmValType,
EngineOrModuleTypeIndex, EntityIndex, ModuleEnvironment, ModuleInternedTypeIndex,
ModuleTranslation, ModuleTypesBuilder, PrimaryMap, Tunables, TypeConvert, WasmHeapType,
WasmResult, WasmValType,
};
use anyhow::anyhow;
use anyhow::{bail, Result};
Expand All @@ -16,8 +17,6 @@ use wasmparser::types::{
ComponentInstanceTypeId, Types,
};
use wasmparser::{Chunk, ComponentImportName, Encoding, Parser, Payload, Validator};
use wasmtime_types::ModuleInternedTypeIndex;
use wasmtime_types::WasmResult;

mod adapt;
pub use self::adapt::*;
Expand Down Expand Up @@ -987,10 +986,7 @@ mod pre_inlining {
self.types.lookup_heap_type(index)
}

fn lookup_type_index(
&self,
index: wasmparser::UnpackedIndex,
) -> wasmtime_types::EngineOrModuleTypeIndex {
fn lookup_type_index(&self, index: wasmparser::UnpackedIndex) -> EngineOrModuleTypeIndex {
self.types.lookup_type_index(index)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
//! final `Component`.

use crate::component::translate::*;
use crate::{EntityType, IndexType};
use std::borrow::Cow;
use wasmparser::types::{ComponentAnyTypeId, ComponentCoreModuleTypeId};
use wasmtime_types::IndexType;

pub(super) fn run(
types: &mut ComponentTypesBuilder,
Expand Down Expand Up @@ -976,7 +976,7 @@ impl<'a> Inliner<'a> {
},
InstanceModule::Import(ty) => match &memory.item {
ExportItem::Name(name) => match types[*ty].exports[name] {
wasmtime_types::EntityType::Memory(m) => match m.idx_type {
EntityType::Memory(m) => match m.idx_type {
IndexType::I32 => false,
IndexType::I64 => true,
},
Expand Down
5 changes: 2 additions & 3 deletions crates/environ/src/component/types.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::component::{MAX_FLAT_PARAMS, MAX_FLAT_RESULTS};
use crate::prelude::*;
use crate::{EntityType, ModuleTypes, PrimaryMap};
use crate::{EntityType, ModuleInternedTypeIndex, ModuleTypes, PrimaryMap};
use core::hash::{Hash, Hasher};
use core::ops::Index;
use serde_derive::{Deserialize, Serialize};
use wasmparser::types;
use wasmtime_component_util::{DiscriminantSize, FlagsSize};
use wasmtime_types::ModuleInternedTypeIndex;

pub use wasmtime_types::StaticModuleIndex;
pub use crate::StaticModuleIndex;

macro_rules! indices {
($(
Expand Down
10 changes: 3 additions & 7 deletions crates/environ/src/component/types_builder.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::component::*;
use crate::prelude::*;
use crate::{
EntityType, Module, ModuleTypes, ModuleTypesBuilder, PrimaryMap, TypeConvert, WasmHeapType,
WasmValType,
EngineOrModuleTypeIndex, EntityType, Module, ModuleInternedTypeIndex, ModuleTypes,
ModuleTypesBuilder, PrimaryMap, TypeConvert, WasmHeapType, WasmValType,
};
use anyhow::{bail, Result};
use cranelift_entity::EntityRef;
Expand All @@ -12,7 +12,6 @@ use std::ops::Index;
use wasmparser::names::KebabString;
use wasmparser::{types, Validator};
use wasmtime_component_util::FlagsSize;
use wasmtime_types::ModuleInternedTypeIndex;

mod resources;
pub use resources::ResourcesBuilder;
Expand Down Expand Up @@ -676,10 +675,7 @@ impl TypeConvert for ComponentTypesBuilder {
panic!("heap types are not supported yet")
}

fn lookup_type_index(
&self,
_index: wasmparser::UnpackedIndex,
) -> wasmtime_types::EngineOrModuleTypeIndex {
fn lookup_type_index(&self, _index: wasmparser::UnpackedIndex) -> EngineOrModuleTypeIndex {
panic!("typed references are not supported yet")
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/types/src/error.rs → crates/environ/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum WasmError {
macro_rules! wasm_unsupported {
($($arg:tt)*) => { $crate::WasmError::Unsupported($crate::__format!($($arg)*)) }
}
#[doc(hidden)]
pub use alloc::format as __format;

impl From<wasmparser::BinaryReaderError> for WasmError {
/// Convert from a `BinaryReaderError` to a `WasmError`.
Expand Down
4 changes: 1 addition & 3 deletions crates/environ/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
pub mod drc;

use crate::prelude::*;
use crate::{WasmArrayType, WasmCompositeType, WasmStorageType, WasmStructType, WasmValType};
use core::alloc::Layout;
use wasmtime_types::{
WasmArrayType, WasmCompositeType, WasmStorageType, WasmStructType, WasmValType,
};

/// Discriminant to check whether GC reference is an `i31ref` or not.
pub const I31_DISCRIMINANT: u64 = 1;
Expand Down
7 changes: 5 additions & 2 deletions crates/environ/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
extern crate std;
extern crate alloc;

pub use wasmtime_types::prelude;
pub mod prelude;

mod address_map;
mod builtin;
mod demangling;
mod error;
mod gc;
mod module;
mod module_artifacts;
Expand All @@ -27,11 +28,13 @@ mod scopevec;
mod stack_map;
mod trap_encoding;
mod tunables;
mod types;
mod vmoffsets;

pub use crate::address_map::*;
pub use crate::builtin::*;
pub use crate::demangling::*;
pub use crate::error::*;
pub use crate::gc::*;
pub use crate::module::*;
pub use crate::module_artifacts::*;
Expand All @@ -41,6 +44,7 @@ pub use crate::scopevec::ScopeVec;
pub use crate::stack_map::StackMap;
pub use crate::trap_encoding::*;
pub use crate::tunables::*;
pub use crate::types::*;
pub use crate::vmoffsets::*;
pub use object;

Expand All @@ -58,7 +62,6 @@ pub mod fact;
// much easier to refer to everything through one crate rather than importing
// one of three and making sure you're using the right one.
pub use cranelift_entity::*;
pub use wasmtime_types::*;

/// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
3 changes: 1 addition & 2 deletions crates/environ/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! Data structures for representing decoded wasm modules.

use crate::prelude::*;
use crate::{PrimaryMap, Tunables};
use crate::*;
use alloc::collections::BTreeMap;
use core::ops::Range;
use cranelift_entity::{packed_option::ReservedValue, EntityRef};
use serde_derive::{Deserialize, Serialize};
use wasmtime_types::*;

/// Implementation styles for WebAssembly linear memory.
#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
Expand Down
5 changes: 3 additions & 2 deletions crates/environ/src/module_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
//! with `bincode` as part of a module's compilation process.

use crate::prelude::*;
use crate::{DefinedFuncIndex, FilePos, FuncIndex, Module, PrimaryMap, StackMap};
use crate::{
DefinedFuncIndex, FilePos, FuncIndex, Module, ModuleInternedTypeIndex, PrimaryMap, StackMap,
};
use core::fmt;
use core::ops::Range;
use core::str;
use serde_derive::{Deserialize, Serialize};
use wasmtime_types::ModuleInternedTypeIndex;

/// Secondary in-memory results of function compilation.
#[derive(Serialize, Deserialize)]
Expand Down
3 changes: 1 addition & 2 deletions crates/environ/src/module_types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::PrimaryMap;
use crate::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PrimaryMap, WasmSubType};
use core::ops::{Index, Range};
use cranelift_entity::{packed_option::PackedOption, SecondaryMap};
use serde_derive::{Deserialize, Serialize};
use wasmtime_types::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, WasmSubType};

/// All types used in a core wasm module.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/prelude.rs → crates/environ/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//! use crate::*;
//! ```
//!
//! Externally for crates that depend on `wasmtime-types` they should have this
//! Externally for crates that depend on `wasmtime-environ` they should have this
//! in the root of the crate:
//!
//! ```rust,ignore
//! use wasmtime_types::prelude;
//! use wasmtime_environ::prelude;
//! ```
//!
//! and then `use crate::*` works as usual.
Expand Down
Loading

0 comments on commit c91e07a

Please sign in to comment.