RA leaks memory in code-server, switching back to desktop

This commit is contained in:
2025-07-31 14:31:26 +00:00
parent 769c6cfc9f
commit f87185ef88
4 changed files with 73 additions and 74 deletions

View File

@@ -12,7 +12,7 @@ use orchid_extension::expr::Expr;
use orchid_extension::gen_expr::GExpr;
use orchid_extension::system::SysCtx;
use crate::macros::mactree::{MacTok, MacTree};
use crate::macros::mactree::{MacTok, MacTree, map_mactree};
#[derive(Clone)]
pub struct InstantiateTplCall {
@@ -53,42 +53,12 @@ impl OwnedAtom for InstantiateTplCall {
if self.argv.len() < self.argc {
return self.to_expr();
}
instantiate_tpl(&self.tpl, &mut self.argv.into_iter(), &mut false).to_expr()
let mut args = self.argv.into_iter();
map_mactree(&self.tpl, &mut false, &mut |tpl| match &*tpl.tok {
MacTok::Ph(_) => panic!("instantiate_tpl received a placeholder"),
MacTok::Slot => Some(args.next().expect("Not enough arguments to fill all slots!")),
_ => None,
})
.to_expr()
}
}
fn instantiate_tpl(
tpl: &MacTree,
argv: &mut impl Iterator<Item = MacTree>,
changed: &mut bool,
) -> MacTree {
let tok = match &*tpl.tok {
MacTok::Slot => {
*changed = true;
return argv.next().expect("Not enough arguments to fill all slots!");
},
MacTok::Lambda(arg, body) => MacTok::Lambda(
ro(changed, |changed| instantiate_tpl(arg, argv, changed)),
instantiate_tpl_v(body, argv, changed),
),
MacTok::Name(_) | MacTok::Value(_) => return tpl.clone(),
MacTok::Ph(_) => panic!("instantiate_tpl received a placeholder"),
MacTok::S(p, body) => MacTok::S(*p, instantiate_tpl_v(body, argv, changed)),
};
if *changed { MacTree { pos: tpl.pos.clone(), tok: Rc::new(tok) } } else { tpl.clone() }
}
fn instantiate_tpl_v(
tpl: &[MacTree],
argv: &mut impl Iterator<Item = MacTree>,
changed: &mut bool,
) -> Vec<MacTree> {
tpl.iter().map(|tree| ro(changed, |changed| instantiate_tpl(tree, argv, changed))).collect_vec()
}
/// reverse "or". Inside, the flag is always false, but raising it will raise
/// the outside flag too.
fn ro<T>(flag: &mut bool, cb: impl FnOnce(&mut bool) -> T) -> T {
let mut new_flag = false;
let val = cb(&mut new_flag);
*flag |= new_flag;
val
}