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

@@ -3,6 +3,7 @@ use std::fmt::Display;
use std::rc::Rc;
use futures::future::join_all;
use itertools::Itertools;
use orchid_api::Paren;
use orchid_base::format::{FmtCtx, FmtUnit, Format, Variants};
use orchid_base::interner::Tok;
@@ -18,7 +19,9 @@ pub struct MacTree {
pub pos: Pos,
pub tok: Rc<MacTok>,
}
impl MacTree {}
impl MacTree {
fn tok(&self) -> &MacTok { &*self.tok }
}
impl Atomic for MacTree {
type Data = ();
type Variant = OwnedVariant;
@@ -99,33 +102,33 @@ pub enum PhKind {
Vector { at_least_one: bool, priority: u8 },
}
pub fn map_mactree(
tpl: &MacTree,
map: &mut impl FnMut(MacTree) -> Option<MacTree>,
argv: &mut impl Iterator<Item = MacTree>,
pub fn map_mactree<F: FnMut(MacTree) -> Option<MacTree>>(
src: &MacTree,
changed: &mut bool,
map: &mut F,
) -> MacTree {
let tok = match &*tpl.tok {
MacTok::Slot => {
let tok = match map(src.clone()) {
Some(new_tok) => {
*changed = true;
return argv.next().expect("Not enough arguments to fill all slots!");
return new_tok;
},
None => match &*src.tok {
MacTok::Lambda(arg, body) => MacTok::Lambda(
ro(changed, |changed| map_mactree(arg, changed, map)),
map_mactree_v(body, changed, map),
),
MacTok::Name(_) | MacTok::Value(_) | MacTok::Slot | MacTok::Ph(_) => return src.clone(),
MacTok::S(p, body) => MacTok::S(*p, map_mactree_v(body, changed, map)),
},
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() }
if *changed { MacTree { pos: src.pos.clone(), tok: Rc::new(tok) } } else { src.clone() }
}
pub fn map_mactree_v(
tpl: &[MacTree],
argv: &mut impl Iterator<Item = MacTree>,
pub fn map_mactree_v<F: FnMut(MacTree) -> Option<MacTree>>(
src: &[MacTree],
changed: &mut bool,
map: &mut F,
) -> Vec<MacTree> {
tpl.iter().map(|tree| ro(changed, |changed| instantiate_tpl(tree, argv, changed))).collect_vec()
src.iter().map(|tree| ro(changed, |changed| map_mactree(tree, changed, map))).collect_vec()
}
/// reverse "or". Inside, the flag is always false, but raising it will raise