Fix lazy-func expansion error in borrow-avoidance strategy
This commit is contained in:
parent
5b4279f517
commit
eaa1f76ba0
|
@ -1,5 +1,5 @@
|
||||||
use super::{Func, FuncDecl, Global, Memory, ModuleDisplay, Signature, Table, Type};
|
use super::{Func, FuncDecl, Global, Memory, ModuleDisplay, Signature, Table, Type};
|
||||||
use crate::entity::EntityVec;
|
use crate::entity::{EntityRef, EntityVec};
|
||||||
use crate::ir::FunctionBody;
|
use crate::ir::FunctionBody;
|
||||||
use crate::{backend, frontend};
|
use crate::{backend, frontend};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -237,20 +237,21 @@ impl<'a> Module<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b FuncDecl<'a>> {
|
pub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b FuncDecl<'a>> {
|
||||||
let mut funcs = std::mem::take(&mut self.funcs);
|
if let FuncDecl::Lazy(..) = self.funcs[id] {
|
||||||
let ret = funcs[id].parse(self);
|
// End the borrow. This is cheap (a slice copy).
|
||||||
self.funcs = funcs;
|
let mut func = self.funcs[id].clone();
|
||||||
ret.and(Ok(&self.funcs[id]))
|
func.parse(self)?;
|
||||||
|
self.funcs[id] = func;
|
||||||
|
}
|
||||||
|
Ok(&self.funcs[id])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_all_funcs(&mut self) -> Result<()> {
|
pub fn expand_all_funcs(&mut self) -> Result<()> {
|
||||||
let mut funcs = std::mem::take(&mut self.funcs);
|
for id in 0..self.funcs.len() {
|
||||||
let mut ret = Ok(());
|
let id = Func::new(id);
|
||||||
for func_decl in funcs.values_mut() {
|
self.expand_func(id)?;
|
||||||
ret = ret.and_then(|_| func_decl.parse(self));
|
|
||||||
}
|
}
|
||||||
self.funcs = funcs;
|
Ok(())
|
||||||
ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn optimize(&mut self) {
|
pub fn optimize(&mut self) {
|
||||||
|
|
Loading…
Reference in a new issue