Skip to content

Commit

Permalink
reduce prevalence of push/pop sig instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 12, 2024
1 parent 1bd403d commit 639b47c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 41 deletions.
5 changes: 1 addition & 4 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,10 +1619,7 @@ code:
BindingKind::Func(f) if self.inlinable(f.instrs(&self.asm)) => {
if call {
// Inline instructions
self.push_instr(Instr::PushSig(f.signature()));
let instrs = EcoVec::from(f.instrs(&self.asm));
self.push_all_instrs(instrs);
self.push_instr(Instr::PopSig);
self.push_all_instrs(EcoVec::from(f.instrs(&self.asm)));
} else {
self.push_instr(Instr::PushFunc(f));
}
Expand Down
24 changes: 1 addition & 23 deletions src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,7 @@ impl Compiler {
instrs.extend(a_instrs);
let sig = Signature::new(a_sig.args.max(b_sig.args), a_sig.outputs + b_sig.outputs);
if call {
self.push_instr(Instr::PushSig(sig));
self.push_all_instrs(instrs);
self.push_instr(Instr::PopSig);
} else {
let func =
self.make_function(modified.modifier.span.clone().into(), sig, instrs);
Expand All @@ -627,9 +625,7 @@ impl Compiler {
instrs.extend(a_instrs);
let sig = Signature::new(a_sig.args + b_sig.args, a_sig.outputs + b_sig.outputs);
if call {
self.push_instr(Instr::PushSig(sig));
self.push_all_instrs(instrs);
self.push_instr(Instr::PopSig);
} else {
let func = self.make_function(
FunctionId::Anonymous(modified.modifier.span.clone()),
Expand Down Expand Up @@ -682,25 +678,9 @@ impl Compiler {
}

if let Some((f_before, f_after)) = under_instrs(&f_instrs, g_sig, self) {
let before_sig = self.sig_of(&f_before, &f_span)?;
let after_sig = self.sig_of(&f_after, &f_span)?;
let mut instrs = if call {
eco_vec![Instr::PushSig(before_sig)]
} else {
EcoVec::new()
};
instrs.extend(f_before);
if call {
instrs.push(Instr::PopSig);
}
let mut instrs = f_before;
instrs.extend(g_instrs);
if call {
instrs.push(Instr::PushSig(after_sig));
}
instrs.extend(f_after);
if call {
instrs.push(Instr::PopSig);
}
if call {
self.push_all_instrs(instrs);
} else {
Expand Down Expand Up @@ -837,9 +817,7 @@ impl Compiler {
}
let sig = Signature::new(sig.args * 2, sig.outputs * 2);
if call {
self.push_instr(Instr::PushSig(sig));
self.push_all_instrs(instrs);
self.push_instr(Instr::PopSig);
} else {
let func =
self.make_function(modified.modifier.span.clone().into(), sig, instrs);
Expand Down
15 changes: 1 addition & 14 deletions src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt;

use ecow::EcoVec;

use crate::{check::instrs_all_signatures, Assembly, ImplPrimitive, Instr, Primitive};
use crate::{Assembly, ImplPrimitive, Instr, Primitive};

pub(crate) fn optimize_instrs_mut(
instrs: &mut EcoVec<Instr>,
Expand Down Expand Up @@ -276,19 +276,6 @@ pub(crate) fn optimize_instrs_mut(
instrs.pop();
}
}
// Redundant identity
(ins, Instr::Prim(Identity, span)) if !ins.is_empty() => {
for i in (0..ins.len()).rev() {
let Ok((sig, temp_sigs)) = instrs_all_signatures(&ins[i..]) else {
continue;
};
if temp_sigs.iter().all(|&sig| sig == (0, 0)) && sig.outputs >= 1 {
println!("{:?}", &ins[i..]);
return;
}
}
instrs.push(Instr::Prim(Identity, span));
}
(_, instr) => instrs.push(instr),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ impl Value {
Self::Box(_) => env.box_scalar_fill().map(Into::into),
}
}
#[allow(dead_code)]
pub(crate) fn fill_row(&self, env: &Uiua) -> Result<Self, &'static str> {
if self.rank() == 0 {
return self.fill_scalar(env);
Expand Down

0 comments on commit 639b47c

Please sign in to comment.