Skip to content

Commit

Permalink
Remove module-name-override as per review comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfallin committed Feb 8, 2022
1 parent efb1d2d commit a31b1f8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
38 changes: 3 additions & 35 deletions crates/wasmtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,10 @@ impl Module {
#[cfg(compiler)]
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
pub fn new(engine: &Engine, bytes: impl AsRef<[u8]>) -> Result<Module> {
Self::new_impl(engine, bytes, None)
}

/// Creates a new WebAssembly `Module` from the given in-memory `binary`
/// data. The provided `name` will be used in traps/backtrace details.
///
/// See [`Module::new`] for other details.
#[cfg(compiler)]
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
pub fn new_with_name(engine: &Engine, bytes: impl AsRef<[u8]>, name: &str) -> Result<Module> {
Self::new_impl(engine, bytes, Some(name.to_string()))
}

#[cfg(compiler)]
fn new_impl(engine: &Engine, bytes: impl AsRef<[u8]>, name: Option<String>) -> Result<Module> {
let bytes = bytes.as_ref();
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes)?;
Self::from_binary_with_name(engine, &bytes, name)
Self::from_binary(engine, &bytes)
}

/// Creates a new WebAssembly `Module` from the contents of the given
Expand Down Expand Up @@ -294,15 +279,6 @@ impl Module {
#[cfg(compiler)]
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
pub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module> {
Self::from_binary_with_name(engine, binary, None)
}

#[cfg(compiler)]
fn from_binary_with_name(
engine: &Engine,
binary: &[u8],
name: Option<String>,
) -> Result<Module> {
// Check to see that the config's target matches the host
let target = engine.compiler().triple();
if *target != target_lexicon::Triple::host() {
Expand Down Expand Up @@ -363,7 +339,7 @@ impl Module {
)
})?;

Self::from_parts(engine, modules, main_module, Arc::new(types), &[], name)
Self::from_parts(engine, modules, main_module, Arc::new(types), &[])
}

/// Converts an input binary-encoded WebAssembly module to compilation
Expand Down Expand Up @@ -518,7 +494,6 @@ impl Module {
main_module: usize,
types: Arc<TypeTables>,
module_upvars: &[serialization::SerializedModuleUpvar],
name: Option<String>,
) -> Result<Self> {
// Validate the module can be used with the current allocator
engine.allocator().validate(modules[main_module].module())?;
Expand All @@ -531,14 +506,7 @@ impl Module {
.flat_map(|m| m.trampolines().map(|(idx, f, _)| (idx, f))),
));

let mut module = modules.remove(main_module);
if let Some(name) = name {
Arc::get_mut(&mut module)
.expect("should be only Arc ref to CompiledModule")
.module_mut()
.expect("should be only Arc ref to Module")
.name = Some(name);
}
let module = modules.remove(main_module);

let shared_signatures = SharedSignatures::Table(signatures.as_module_map().clone());
let runtime_info = Arc::new(ModuleRuntimeInfo::new(&module, shared_signatures));
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/module/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'a> SerializedModule<'a> {
)
})?;

Module::from_parts(engine, modules, main_module, Arc::new(types), &upvars, None)
Module::from_parts(engine, modules, main_module, Arc::new(types), &upvars)
}

pub fn into_parts(
Expand Down
3 changes: 0 additions & 3 deletions tests/all/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ fn test_module_name() -> anyhow::Result<()> {
let module = Module::new(&engine, wat)?;
assert_eq!(module.name(), Some("from_name_section"));

let module = Module::new_with_name(&engine, wat, "override")?;
assert_eq!(module.name(), Some("override"));

Ok(())
}

0 comments on commit a31b1f8

Please sign in to comment.