Renamed FuncType to FunctionType

This commit is contained in:
Syrus
2020-05-04 13:34:05 -07:00
parent 447939497c
commit 2997be7d88
20 changed files with 63 additions and 61 deletions

View File

@ -4,7 +4,7 @@ use crate::store::{Store, StoreObject};
use crate::types::{Val, ValAnyFunc};
use crate::Mutability;
use crate::RuntimeError;
use crate::{ExternType, FuncType, GlobalType, MemoryType, TableType, ValType};
use crate::{ExternType, FunctionType, GlobalType, MemoryType, TableType, ValType};
use std::cmp::max;
use std::slice;
use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
@ -563,7 +563,7 @@ impl Func {
}
/// Returns the underlying type of this function.
pub fn ty(&self) -> FuncType {
pub fn ty(&self) -> FunctionType {
self.store
.engine()
.lookup_signature(self.exported.signature)

View File

@ -22,7 +22,7 @@ pub use crate::ptr::{Array, Item, WasmPtr};
pub use crate::store::{Engine, Store, StoreObject};
pub use crate::tunables::Tunables;
pub use crate::types::{
AnyRef, ExportType, ExternType, FuncType, GlobalType, HostInfo, HostRef, ImportType,
AnyRef, ExportType, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
MemoryType, Mutability, TableType, Val, ValType,
};

View File

@ -4,7 +4,7 @@ use crate::RuntimeError;
use std::ptr;
use wasm_common::Value;
pub use wasm_common::{
AnyRef, ExportType, ExternType, FuncType, GlobalType, HostInfo, HostRef, ImportType,
AnyRef, ExportType, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
MemoryType, Mutability, TableType, Type as ValType,
};

View File

@ -14,7 +14,7 @@ use cranelift_codegen::{binemit, isa, Context};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
use wasm_common::{
Features, FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
Features, FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
};
use wasmer_compiler::CompileError;
use wasmer_compiler::{
@ -288,7 +288,7 @@ impl Compiler for CraneliftCompiler {
fn compile_wasm_trampolines(
&self,
signatures: &[FuncType],
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
signatures
.par_iter()

View File

@ -14,14 +14,14 @@ use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use wasm_common::FuncType;
use wasm_common::FunctionType;
use wasmer_compiler::{CompileError, CompiledFunction, CompiledFunctionFrameInfo, FunctionBody};
/// Create a trampoline for invoking a WebAssembly function.
pub fn make_wasm_trampoline(
isa: &dyn TargetIsa,
fn_builder_ctx: &mut FunctionBuilderContext,
func_type: &FuncType,
func_type: &FunctionType,
value_size: usize,
) -> Result<FunctionBody, CompileError> {
let pointer_type = isa.pointer_type();

View File

@ -7,7 +7,7 @@ use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::ir::{self, AbiParam};
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use wasm_common::{FuncType, Type};
use wasm_common::{FunctionType, Type};
use wasmer_compiler::wasm_unsupported;
use wasmer_compiler::wasmparser;
use wasmer_compiler::RelocationKind;
@ -16,7 +16,7 @@ use wasmer_runtime::libcalls::LibCall;
/// Helper function translate a Funciton signature into Cranelift Ir
pub fn signature_to_cranelift_ir(
signature: &FuncType,
signature: &FunctionType,
target_config: &TargetFrontendConfig,
) -> ir::Signature {
let mut sig = ir::Signature::new(target_config.default_call_conv);

View File

@ -8,7 +8,7 @@ use crate::translator::FuncTranslator;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
use wasm_common::Features;
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasm_common::{FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasmer_compiler::{
Compilation, CompileError, CompiledFunction, Compiler, CompilerConfig, CustomSection,
CustomSectionProtection, FunctionBody, FunctionBodyData, ModuleTranslationState, Relocation,
@ -141,7 +141,7 @@ impl Compiler for LLVMCompiler {
fn compile_wasm_trampolines(
&self,
signatures: &[FuncType],
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
signatures
.par_iter()

View File

@ -4,7 +4,7 @@ use inkwell::{
context::Context, module::Linkage, passes::PassManager, targets::FileType, types::BasicType,
values::FunctionValue, AddressSpace,
};
use wasm_common::{FuncType, Type};
use wasm_common::{FunctionType, Type};
use wasmer_compiler::{CompileError, CompiledFunctionUnwindInfo, FunctionBody};
pub struct FuncTrampoline {
@ -20,7 +20,7 @@ impl FuncTrampoline {
pub fn trampoline(
&mut self,
ty: &FuncType,
ty: &FunctionType,
config: &LLVMConfig,
) -> Result<FunctionBody, CompileError> {
let mut module = self.ctx.create_module("");
@ -104,7 +104,7 @@ impl FuncTrampoline {
fn generate_trampoline<'ctx>(
trampoline_func: FunctionValue,
func_sig: &FuncType,
func_sig: &FunctionType,
context: &'ctx Context,
intrinsics: &Intrinsics<'ctx>,
) -> Result<(), CompileError> {

View File

@ -33,7 +33,8 @@ use std::collections::HashMap;
use crate::config::LLVMConfig;
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
use wasm_common::{
FuncIndex, FuncType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex, Type,
FuncIndex, FunctionType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
Type,
};
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
use wasmer_compiler::{

View File

@ -34,8 +34,8 @@ use wasmer_runtime_core::{
*/
use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::{
FuncIndex, FuncType, GlobalIndex, MemoryIndex, Mutability, Pages, SignatureIndex, TableIndex,
Type,
FuncIndex, FunctionType as FuncType, GlobalIndex, MemoryIndex, Mutability, Pages,
SignatureIndex, TableIndex, Type,
};
use wasmer_runtime::Module as WasmerCompilerModule;
use wasmer_runtime::{MemoryPlan, MemoryStyle, VMOffsets};

View File

@ -6,7 +6,7 @@ use crate::config::SinglepassConfig;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::Features;
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasm_common::{FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasmer_compiler::FunctionBodyData;
use wasmer_compiler::TrapInformation;
use wasmer_compiler::{Compilation, CompileError, Compiler, FunctionBody};
@ -67,7 +67,7 @@ impl Compiler for SinglepassCompiler {
fn compile_wasm_trampolines(
&self,
_signatures: &[FuncType],
_signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError> {
// Note: do not implement this yet
Err(CompileError::Codegen(

View File

@ -9,7 +9,7 @@ use crate::target::Target;
use crate::FunctionBodyData;
use crate::ModuleTranslationState;
use wasm_common::entity::PrimaryMap;
use wasm_common::{Features, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasm_common::{Features, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasmer_runtime::Module;
use wasmer_runtime::{MemoryPlan, TablePlan};
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
@ -82,6 +82,6 @@ pub trait Compiler {
/// ```
fn compile_wasm_trampolines(
&self,
signatures: &[FuncType],
signatures: &[FunctionType],
) -> Result<Vec<FunctionBody>, CompileError>;
}

View File

@ -7,7 +7,7 @@ use crate::{WasmError, WasmResult};
use std::convert::TryFrom;
use std::sync::Arc;
use wasm_common::entity::PrimaryMap;
use wasm_common::FuncType;
use wasm_common::FunctionType;
use wasm_common::{
DataIndex, DataInitializer, DataInitializerLocation, ElemIndex, ExportIndex, FuncIndex,
GlobalIndex, GlobalInit, GlobalType, ImportIndex, LocalFuncIndex, MemoryIndex, MemoryType,
@ -102,7 +102,7 @@ impl<'data> ModuleEnvironment<'data> {
Ok(())
}
pub(crate) fn declare_signature(&mut self, sig: FuncType) -> WasmResult<()> {
pub(crate) fn declare_signature(&mut self, sig: FunctionType) -> WasmResult<()> {
// TODO: Deduplicate signatures.
self.result.module.signatures.push(sig);
Ok(())

View File

@ -18,15 +18,16 @@ use std::vec::Vec;
use wasm_common::entity::packed_option::ReservedValue;
use wasm_common::entity::EntityRef;
use wasm_common::{
DataIndex, ElemIndex, FuncIndex, FuncType, GlobalIndex, GlobalInit, GlobalType, MemoryIndex,
MemoryType, Pages, SignatureIndex, TableIndex, TableType, Type, V128,
DataIndex, ElemIndex, FuncIndex, FunctionType, GlobalIndex, GlobalInit, GlobalType,
MemoryIndex, MemoryType, Pages, SignatureIndex, TableIndex, TableType, Type, V128,
};
use wasmparser::{
self, CodeSectionReader, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems,
ElementKind, ElementSectionReader, Export, ExportSectionReader, ExternalKind,
FuncType as WPFuncType, FunctionSectionReader, GlobalSectionReader, GlobalType as WPGlobalType,
ImportSectionEntryType, ImportSectionReader, MemorySectionReader, MemoryType as WPMemoryType,
NameSectionReader, Naming, NamingReader, Operator, TableSectionReader, TypeSectionReader,
FuncType as WPFunctionType, FunctionSectionReader, GlobalSectionReader,
GlobalType as WPGlobalType, ImportSectionEntryType, ImportSectionReader, MemorySectionReader,
MemoryType as WPMemoryType, NameSectionReader, Naming, NamingReader, Operator,
TableSectionReader, TypeSectionReader,
};
/// Helper function translating wasmparser types to Wasm Type.
@ -57,7 +58,7 @@ pub fn parse_type_section(
for entry in types {
match entry.map_err(to_wasm_error)? {
WPFuncType {
WPFunctionType {
form: wasmparser::Type::Func,
params,
returns,
@ -76,7 +77,7 @@ pub fn parse_type_section(
.expect("only numeric types are supported in function signatures")
})
.collect();
let sig = FuncType::new(sig_params, sig_returns);
let sig = FunctionType::new(sig_params, sig_returns);
environ.declare_signature(sig)?;
module_translation_state.wasm_types.push((params, returns));
}

View File

@ -9,7 +9,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::sync::Arc;
use wasm_common::entity::PrimaryMap;
use wasm_common::{FuncType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex};
use wasm_common::{FunctionType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex};
use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target};
#[cfg(feature = "compiler")]
use wasmer_compiler::{Compiler, CompilerConfig};
@ -92,13 +92,13 @@ impl JITEngine {
}
/// Register a signature
pub fn register_signature(&self, func_type: &FuncType) -> VMSharedSignatureIndex {
pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
let compiler = self.compiler();
compiler.signatures().register(func_type)
}
/// Lookup a signature
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FuncType> {
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
let compiler = self.compiler();
compiler.signatures().lookup(sig)
}

View File

@ -9,8 +9,8 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::{
DataIndex, ElemIndex, ExportIndex, ExportType, ExternType, FuncIndex, FuncType, GlobalIndex,
GlobalInit, GlobalType, ImportIndex, ImportType, LocalFuncIndex, LocalGlobalIndex,
DataIndex, ElemIndex, ExportIndex, ExportType, ExternType, FuncIndex, FunctionType,
GlobalIndex, GlobalInit, GlobalType, ImportIndex, ImportType, LocalFuncIndex, LocalGlobalIndex,
LocalMemoryIndex, LocalTableIndex, MemoryIndex, MemoryType, Pages, SignatureIndex, TableIndex,
TableType,
};
@ -132,7 +132,7 @@ pub struct Module {
pub func_names: HashMap<FuncIndex, String>,
/// WebAssembly function signatures.
pub signatures: PrimaryMap<SignatureIndex, FuncType>,
pub signatures: PrimaryMap<SignatureIndex, FunctionType>,
/// Types of functions (imported and local).
pub functions: PrimaryMap<FuncIndex, SignatureIndex>,
@ -191,7 +191,7 @@ impl Module {
}
/// Get the exported signatures of the module
pub fn exported_signatures(&self) -> Vec<FuncType> {
pub fn exported_signatures(&self) -> Vec<FunctionType> {
self.exports
.iter()
.filter_map(|(_name, export_index)| match export_index {
@ -202,7 +202,7 @@ impl Module {
}
_ => None,
})
.collect::<Vec<FuncType>>()
.collect::<Vec<FunctionType>>()
}
/// Get the export types of the module

View File

@ -6,7 +6,7 @@ use more_asserts::{assert_lt, debug_assert_lt};
use std::collections::{hash_map, HashMap};
use std::convert::TryFrom;
use std::sync::RwLock;
use wasm_common::FuncType;
use wasm_common::FunctionType;
/// WebAssembly requires that the caller and callee signatures in an indirect
/// call must match. To implement this efficiently, keep a registry of all
@ -24,8 +24,8 @@ pub struct SignatureRegistry {
#[derive(Debug, Default)]
struct Inner {
signature2index: HashMap<FuncType, VMSharedSignatureIndex>,
index2signature: HashMap<VMSharedSignatureIndex, FuncType>,
signature2index: HashMap<FunctionType, VMSharedSignatureIndex>,
index2signature: HashMap<VMSharedSignatureIndex, FunctionType>,
}
impl SignatureRegistry {
@ -37,7 +37,7 @@ impl SignatureRegistry {
}
/// Register a signature and return its unique index.
pub fn register(&self, sig: &FuncType) -> VMSharedSignatureIndex {
pub fn register(&self, sig: &FunctionType) -> VMSharedSignatureIndex {
let mut inner = self.inner.write().unwrap();
let len = inner.signature2index.len();
match inner.signature2index.entry(sig.clone()) {
@ -62,7 +62,7 @@ impl SignatureRegistry {
///
/// Note that for this operation to be semantically correct the `idx` must
/// have previously come from a call to `register` of this same object.
pub fn lookup(&self, idx: VMSharedSignatureIndex) -> Option<FuncType> {
pub fn lookup(&self, idx: VMSharedSignatureIndex) -> Option<FunctionType> {
self.inner
.read()
.unwrap()

View File

@ -51,8 +51,8 @@ pub use crate::r#ref::{AnyRef, HostInfo, HostRef};
pub use crate::units::{Bytes, Pages};
pub use crate::values::Value;
pub use types::{
ExportType, ExternType, FuncType, GlobalInit, GlobalType, ImportType, MemoryType, Mutability,
TableType, Type, V128,
ExportType, ExternType, FunctionType, GlobalInit, GlobalType, ImportType, MemoryType,
Mutability, TableType, Type, V128,
};
/// Version number of this crate.

View File

@ -1,7 +1,7 @@
//! This module permits to create native functions
//! easily in Rust, thanks to it's advanced typing system.
use crate::types::{FuncType, Type};
use crate::types::{FunctionType, Type};
use std::convert::Infallible;
use std::marker::PhantomData;
@ -300,8 +300,8 @@ where
}
/// Get the type of the Func
pub fn ty(&self) -> FuncType {
FuncType::new(Args::wasm_types(), Rets::wasm_types())
pub fn ty(&self) -> FunctionType {
FunctionType::new(Args::wasm_types(), Rets::wasm_types())
}
/// Get the type of the Func
@ -633,30 +633,30 @@ mod test_func {
#[test]
fn test_function_types() {
assert_eq!(Func::new(func).ty(), FuncType::new(vec![], vec![]));
assert_eq!(Func::new(func).ty(), FunctionType::new(vec![], vec![]));
assert_eq!(
Func::new(func__i32).ty(),
FuncType::new(vec![], vec![Type::I32])
FunctionType::new(vec![], vec![Type::I32])
);
assert_eq!(
Func::new(func_i32).ty(),
FuncType::new(vec![Type::I32], vec![])
FunctionType::new(vec![Type::I32], vec![])
);
assert_eq!(
Func::new(func_i32__i32).ty(),
FuncType::new(vec![Type::I32], vec![Type::I32])
FunctionType::new(vec![Type::I32], vec![Type::I32])
);
assert_eq!(
Func::new(func_i32_i32__i32).ty(),
FuncType::new(vec![Type::I32, Type::I32], vec![Type::I32])
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32])
);
assert_eq!(
Func::new(func_i32_i32__i32_i32).ty(),
FuncType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32])
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32])
);
assert_eq!(
Func::new(func_f32_i32__i32_f32).ty(),
FuncType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32])
FunctionType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32])
);
}

View File

@ -100,7 +100,7 @@ impl From<&[u8]> for V128 {
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub enum ExternType {
/// This external type is the type of a WebAssembly function.
Func(FuncType),
Func(FunctionType),
/// This external type is the type of a WebAssembly global.
Global(GlobalType),
/// This external type is the type of a WebAssembly table.
@ -192,7 +192,7 @@ macro_rules! accessors {
impl ExternType {
accessors! {
(Func(FuncType) func unwrap_func)
(Func(FunctionType) func unwrap_func)
(Global(GlobalType) global unwrap_global)
(Table(TableType) table unwrap_table)
(Memory(MemoryType) memory unwrap_memory)
@ -216,14 +216,14 @@ impl ExternType {
/// WebAssembly functions can have 0 or more parameters and results.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct FuncType {
pub struct FunctionType {
/// The parameters of the function
params: Vec<Type>,
/// The return values of the function
results: Vec<Type>,
}
impl FuncType {
impl FunctionType {
/// Creates a new Function Type with the given parameter and return types.
pub fn new<Params, Returns>(params: Params, returns: Returns) -> Self
where
@ -257,7 +257,7 @@ impl FuncType {
// }
}
impl std::fmt::Display for FuncType {
impl std::fmt::Display for FunctionType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let params = self
.params