Skip to content

Commit

Permalink
rn module_ref()
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed May 26, 2020
1 parent d47371f commit d4e4ade
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/jit/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl CompiledModule {
}

/// Return a reference to a module.
pub fn module_ref(&self) -> &Module {
pub fn module(&self) -> &Module {
&self.module
}

Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/debug_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub unsafe extern "C" fn resolve_vmctx_memory_ptr(p: *const u32) -> *const u8 {
);
let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
assert!(
VMCTX_AND_MEMORY.1 < handle.module_ref().local.memory_plans.len(),
VMCTX_AND_MEMORY.1 < handle.module().local.memory_plans.len(),
"memory index for debugger is out of bounds"
);
let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
Expand Down
21 changes: 9 additions & 12 deletions crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Instance {
unsafe { *self.signature_ids_ptr().add(index) }
}

pub(crate) fn module_ref(&self) -> &Module {
pub(crate) fn module(&self) -> &Module {
&self.module
}

Expand Down Expand Up @@ -782,10 +782,8 @@ impl InstanceHandle {
host_state: Box<dyn Any>,
interrupts: Arc<VMInterrupts>,
) -> Result<Self, InstantiationError> {
let module_ref = &*module;
let tables = create_tables(module_ref);
let memories =
create_memories(module_ref, mem_creator.unwrap_or(&DefaultMemoryCreator {}))?;
let tables = create_tables(&module);
let memories = create_memories(&module, mem_creator.unwrap_or(&DefaultMemoryCreator {}))?;

let vmctx_tables = tables
.values()
Expand All @@ -799,11 +797,11 @@ impl InstanceHandle {
.collect::<PrimaryMap<DefinedMemoryIndex, _>>()
.into_boxed_slice();

let vmctx_globals = create_globals(module_ref);
let vmctx_globals = create_globals(&module);

let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module.local);

let passive_data = RefCell::new(module_ref.passive_data.clone());
let passive_data = RefCell::new(module.passive_data.clone());

let handle = {
let instance = Instance {
Expand Down Expand Up @@ -934,8 +932,8 @@ impl InstanceHandle {
}

/// Return a reference to a module.
pub fn module_ref(&self) -> &Module {
self.instance().module_ref()
pub fn module(&self) -> &Module {
self.instance().module()
}

/// Lookup an export with the given name.
Expand Down Expand Up @@ -1053,7 +1051,7 @@ impl InstanceHandle {

fn check_table_init_bounds(instance: &Instance) -> Result<(), InstantiationError> {
let module = Arc::clone(&instance.module);
for init in &module.as_ref().table_elements {
for init in &module.table_elements {
let start = get_table_init_start(init, instance);
let table = instance.get_table(init.table_index);

Expand Down Expand Up @@ -1157,7 +1155,7 @@ fn get_table_init_start(init: &TableElements, instance: &Instance) -> usize {

/// Initialize the table memory from the provided initializers.
fn initialize_tables(instance: &Instance) -> Result<(), InstantiationError> {
let module = instance.module.as_ref();
let module = &instance.module;
for init in &module.table_elements {
let start = get_table_init_start(init, instance);
let table = instance.get_table(init.table_index);
Expand Down Expand Up @@ -1195,7 +1193,6 @@ fn initialize_passive_elements(instance: &Instance) {
passive_elements.extend(
instance
.module
.as_ref()
.passive_elements
.iter()
.filter(|(_, segments)| !segments.is_empty())
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ fn instantiate(
}
}

if imports.len() != compiled_module.module_ref().imports.len() {
if imports.len() != compiled_module.module().imports.len() {
bail!(
"wrong number of imports provided, {} != {}",
imports.len(),
compiled_module.module_ref().imports.len()
compiled_module.module().imports.len()
);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ fn instantiate(
instance
};

let start_func = instance.handle.module_ref().start_func;
let start_func = instance.handle.module().start_func;

// If a start function is present, invoke it. Make sure we use all the
// trap-handling configuration in `store` as well.
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl Module {
pub fn imports<'module>(
&'module self,
) -> impl ExactSizeIterator<Item = ImportType<'module>> + 'module {
let module = self.inner.compiled.module_ref();
let module = self.inner.compiled.module();
module
.imports
.iter()
Expand Down Expand Up @@ -484,7 +484,7 @@ impl Module {
pub fn exports<'module>(
&'module self,
) -> impl ExactSizeIterator<Item = ExportType<'module>> + 'module {
let module = self.inner.compiled.module_ref();
let module = self.inner.compiled.module();
module.exports.iter().map(move |(name, entity_index)| {
let r#type = EntityType::new(entity_index, module);
ExportType::new(name, r#type)
Expand Down Expand Up @@ -535,7 +535,7 @@ impl Module {
/// # }
/// ```
pub fn get_export<'module>(&'module self, name: &'module str) -> Option<ExternType> {
let module = self.inner.compiled.module_ref();
let module = self.inner.compiled.module();
let entity_index = module.exports.get(name)?;
Some(EntityType::new(entity_index, module).extern_type())
}
Expand Down

0 comments on commit d4e4ade

Please sign in to comment.