/rust/registry/src/index.crates.io-6f17d22bba15001f/egg-0.6.0/src/machine.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{Analysis, EClass, EGraph, ENodeOrVar, Id, Language, PatternAst, Subst, Var}; |
2 | | use std::cmp::Ordering; |
3 | | |
4 | | struct Machine { |
5 | | reg: Vec<Id>, |
6 | | } |
7 | | |
8 | | impl Default for Machine { |
9 | 2.83M | fn default() -> Self { |
10 | 2.83M | Self { reg: vec![] } |
11 | 2.83M | } Unexecuted instantiation: <egg::machine::Machine as core::default::Default>::default <egg::machine::Machine as core::default::Default>::default Line | Count | Source | 9 | 2.83M | fn default() -> Self { | 10 | 2.83M | Self { reg: vec![] } | 11 | 2.83M | } |
|
12 | | } |
13 | | |
14 | 0 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] Unexecuted instantiation: <egg::machine::Reg as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Reg as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Reg as core::default::Default>::default Unexecuted instantiation: <egg::machine::Reg as core::default::Default>::default Unexecuted instantiation: <egg::machine::Reg as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Reg as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Reg as core::cmp::PartialEq>::eq Unexecuted instantiation: <egg::machine::Reg as core::cmp::PartialEq>::eq Unexecuted instantiation: <egg::machine::Reg as core::hash::Hash>::hash::<_> Unexecuted instantiation: <egg::machine::Reg as core::hash::Hash>::hash::<_> Unexecuted instantiation: <egg::machine::Reg as core::cmp::PartialOrd>::partial_cmp Unexecuted instantiation: <egg::machine::Reg as core::cmp::PartialOrd>::partial_cmp Unexecuted instantiation: <egg::machine::Reg as core::cmp::Ord>::cmp Unexecuted instantiation: <egg::machine::Reg as core::cmp::Ord>::cmp |
15 | | struct Reg(u32); |
16 | | |
17 | 0 | #[derive(Debug, Clone, PartialEq, Eq)] Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Program<_> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Program<_> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Program<_> as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Program<_> as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Program<_> as core::cmp::PartialEq>::eq Unexecuted instantiation: <egg::machine::Program<_> as core::cmp::PartialEq>::eq |
18 | | pub struct Program<L> { |
19 | | instructions: Vec<Instruction<L>>, |
20 | | subst: Subst, |
21 | | } |
22 | | |
23 | 0 | #[derive(Debug, Clone, PartialEq, Eq)] Unexecuted instantiation: <egg::machine::Instruction<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Instruction<_> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Instruction<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Instruction<_> as core::fmt::Debug>::fmt Unexecuted instantiation: <egg::machine::Instruction<_> as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Instruction<_> as core::clone::Clone>::clone Unexecuted instantiation: <egg::machine::Instruction<_> as core::cmp::PartialEq>::eq Unexecuted instantiation: <egg::machine::Instruction<_> as core::cmp::PartialEq>::eq |
24 | | enum Instruction<L> { |
25 | | Bind { node: L, i: Reg, out: Reg }, |
26 | | Compare { i: Reg, j: Reg }, |
27 | | } |
28 | | |
29 | | #[inline(always)] |
30 | 5.71k | fn for_each_matching_node<L, D>(eclass: &EClass<L, D>, node: &L, mut f: impl FnMut(&L)) |
31 | 5.71k | where |
32 | 5.71k | L: Language, |
33 | 5.71k | { |
34 | 5.71k | #[allow(clippy::mem_discriminant_non_enum)] |
35 | 5.71k | if eclass.nodes.len() < 50 { |
36 | 5.71k | eclass.nodes.iter().filter(|n| node.matches(n)).for_each(f) Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#0}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#0}egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#0}Line | Count | Source | 36 | 5.71k | eclass.nodes.iter().filter(|n| node.matches(n)).for_each(f) |
Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#0} |
37 | | } else { |
38 | 0 | debug_assert!(node.children().iter().all(|&id| id == Id::from(0))); Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#4}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#4}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#4}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#4} |
39 | 0 | debug_assert!(eclass.nodes.windows(2).all(|w| w[0] < w[1])); Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#5}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#5}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#5}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#5} |
40 | 0 | let mut start = eclass.nodes.binary_search(node).unwrap_or_else(|i| i); Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#1}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#1}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#1}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#1} |
41 | 0 | let discrim = std::mem::discriminant(node); |
42 | 0 | while start > 0 { |
43 | 0 | if std::mem::discriminant(&eclass.nodes[start - 1]) == discrim { |
44 | 0 | start -= 1; |
45 | 0 | } else { |
46 | 0 | break; |
47 | | } |
48 | | } |
49 | 0 | let matching = eclass.nodes[start..] |
50 | 0 | .iter() |
51 | 0 | .take_while(|&n| std::mem::discriminant(n) == discrim) Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#2}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#2}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#2}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#2} |
52 | 0 | .filter(|n| node.matches(n)); Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#3}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#3}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#3}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#3} |
53 | | debug_assert_eq!( |
54 | 0 | matching.clone().count(), |
55 | 0 | eclass.nodes.iter().filter(|n| node.matches(n)).count(), Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#6}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#6}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#6}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#6} |
56 | 0 | "matching node {:?}\nstart={}\n{:?} != {:?}\nnodes: {:?}", |
57 | 0 | node, |
58 | 0 | start, |
59 | 0 | matching.clone().collect::<indexmap::IndexSet<_>>(), |
60 | 0 | eclass |
61 | 0 | .nodes |
62 | 0 | .iter() |
63 | 0 | .filter(|n| node.matches(n)) Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#7}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#7}Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>::{closure#7}Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _>::{closure#7} |
64 | 0 | .collect::<indexmap::IndexSet<_>>(), |
65 | | eclass.nodes |
66 | | ); |
67 | 0 | matching.for_each(&mut f); |
68 | | } |
69 | 5.71k | } Unexecuted instantiation: egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _> egg::machine::for_each_matching_node::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, core::option::Option<wasm_mutate::mutators::peephole::eggsy::analysis::ClassData>, <egg::machine::Machine>::run<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}>Line | Count | Source | 30 | 5.71k | fn for_each_matching_node<L, D>(eclass: &EClass<L, D>, node: &L, mut f: impl FnMut(&L)) | 31 | 5.71k | where | 32 | 5.71k | L: Language, | 33 | 5.71k | { | 34 | 5.71k | #[allow(clippy::mem_discriminant_non_enum)] | 35 | 5.71k | if eclass.nodes.len() < 50 { | 36 | 5.71k | eclass.nodes.iter().filter(|n| node.matches(n)).for_each(f) | 37 | | } else { | 38 | 0 | debug_assert!(node.children().iter().all(|&id| id == Id::from(0))); | 39 | 0 | debug_assert!(eclass.nodes.windows(2).all(|w| w[0] < w[1])); | 40 | 0 | let mut start = eclass.nodes.binary_search(node).unwrap_or_else(|i| i); | 41 | 0 | let discrim = std::mem::discriminant(node); | 42 | 0 | while start > 0 { | 43 | 0 | if std::mem::discriminant(&eclass.nodes[start - 1]) == discrim { | 44 | 0 | start -= 1; | 45 | 0 | } else { | 46 | 0 | break; | 47 | | } | 48 | | } | 49 | 0 | let matching = eclass.nodes[start..] | 50 | 0 | .iter() | 51 | 0 | .take_while(|&n| std::mem::discriminant(n) == discrim) | 52 | 0 | .filter(|n| node.matches(n)); | 53 | | debug_assert_eq!( | 54 | 0 | matching.clone().count(), | 55 | 0 | eclass.nodes.iter().filter(|n| node.matches(n)).count(), | 56 | 0 | "matching node {:?}\nstart={}\n{:?} != {:?}\nnodes: {:?}", | 57 | 0 | node, | 58 | 0 | start, | 59 | 0 | matching.clone().collect::<indexmap::IndexSet<_>>(), | 60 | 0 | eclass | 61 | 0 | .nodes | 62 | 0 | .iter() | 63 | 0 | .filter(|n| node.matches(n)) | 64 | 0 | .collect::<indexmap::IndexSet<_>>(), | 65 | | eclass.nodes | 66 | | ); | 67 | 0 | matching.for_each(&mut f); | 68 | | } | 69 | 5.71k | } |
Unexecuted instantiation: egg::machine::for_each_matching_node::<_, _, _> |
70 | | |
71 | | impl Machine { |
72 | | #[inline(always)] |
73 | 2.84M | fn reg(&self, reg: Reg) -> Id { |
74 | 2.84M | self.reg[reg.0 as usize] |
75 | 2.84M | } Unexecuted instantiation: <egg::machine::Machine>::reg <egg::machine::Machine>::reg Line | Count | Source | 73 | 2.84M | fn reg(&self, reg: Reg) -> Id { | 74 | 2.84M | self.reg[reg.0 as usize] | 75 | 2.84M | } |
|
76 | | |
77 | 2.84M | fn run<L, N>( |
78 | 2.84M | &mut self, |
79 | 2.84M | egraph: &EGraph<L, N>, |
80 | 2.84M | instructions: &[Instruction<L>], |
81 | 2.84M | subst: &Subst, |
82 | 2.84M | yield_fn: &mut impl FnMut(&Self, &Subst), |
83 | 2.84M | ) where |
84 | 2.84M | L: Language, |
85 | 2.84M | N: Analysis<L>, |
86 | 2.84M | { |
87 | 2.84M | let mut instructions = instructions.iter(); |
88 | 2.84M | while let Some(instruction) = instructions.next() { |
89 | 6.52k | match instruction { |
90 | 5.71k | Instruction::Bind { i, out, node } => { |
91 | 5.71k | let remaining_instructions = instructions.as_slice(); |
92 | 5.71k | return for_each_matching_node(&egraph[self.reg(*i)], node, |matched| { |
93 | 4.39k | self.reg.truncate(out.0 as usize); |
94 | 4.39k | self.reg.extend_from_slice(matched.children()); |
95 | 4.39k | self.run(egraph, remaining_instructions, subst, yield_fn) |
96 | 5.71k | }); Unexecuted instantiation: <egg::machine::Machine>::run::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}Unexecuted instantiation: <egg::machine::Machine>::run::<_, _, _>::{closure#0}<egg::machine::Machine>::run::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>::{closure#0}Line | Count | Source | 92 | 4.39k | return for_each_matching_node(&egraph[self.reg(*i)], node, |matched| { | 93 | 4.39k | self.reg.truncate(out.0 as usize); | 94 | 4.39k | self.reg.extend_from_slice(matched.children()); | 95 | 4.39k | self.run(egraph, remaining_instructions, subst, yield_fn) | 96 | 4.39k | }); |
Unexecuted instantiation: <egg::machine::Machine>::run::<_, _, _>::{closure#0} |
97 | | } |
98 | 816 | Instruction::Compare { i, j } => { |
99 | 816 | if egraph.find(self.reg(*i)) != egraph.find(self.reg(*j)) { |
100 | 814 | return; |
101 | 2 | } |
102 | | } |
103 | | } |
104 | | } |
105 | | |
106 | 2.83M | yield_fn(self, subst) |
107 | 2.84M | } Unexecuted instantiation: <egg::machine::Machine>::run::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>Unexecuted instantiation: <egg::machine::Machine>::run::<_, _, _> <egg::machine::Machine>::run::<wasm_mutate::mutators::peephole::eggsy::lang::Lang, wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis, <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}>Line | Count | Source | 77 | 2.84M | fn run<L, N>( | 78 | 2.84M | &mut self, | 79 | 2.84M | egraph: &EGraph<L, N>, | 80 | 2.84M | instructions: &[Instruction<L>], | 81 | 2.84M | subst: &Subst, | 82 | 2.84M | yield_fn: &mut impl FnMut(&Self, &Subst), | 83 | 2.84M | ) where | 84 | 2.84M | L: Language, | 85 | 2.84M | N: Analysis<L>, | 86 | 2.84M | { | 87 | 2.84M | let mut instructions = instructions.iter(); | 88 | 2.84M | while let Some(instruction) = instructions.next() { | 89 | 6.52k | match instruction { | 90 | 5.71k | Instruction::Bind { i, out, node } => { | 91 | 5.71k | let remaining_instructions = instructions.as_slice(); | 92 | 5.71k | return for_each_matching_node(&egraph[self.reg(*i)], node, |matched| { | 93 | | self.reg.truncate(out.0 as usize); | 94 | | self.reg.extend_from_slice(matched.children()); | 95 | | self.run(egraph, remaining_instructions, subst, yield_fn) | 96 | 5.71k | }); | 97 | | } | 98 | 816 | Instruction::Compare { i, j } => { | 99 | 816 | if egraph.find(self.reg(*i)) != egraph.find(self.reg(*j)) { | 100 | 814 | return; | 101 | 2 | } | 102 | | } | 103 | | } | 104 | | } | 105 | | | 106 | 2.83M | yield_fn(self, subst) | 107 | 2.84M | } |
Unexecuted instantiation: <egg::machine::Machine>::run::<_, _, _> |
108 | | } |
109 | | |
110 | | type VarToReg = indexmap::IndexMap<Var, Reg>; |
111 | | type TodoList<L> = std::collections::BinaryHeap<Todo<L>>; |
112 | | |
113 | 0 | #[derive(PartialEq, Eq)] Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::PartialEq>::eq Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::PartialEq>::eq |
114 | | struct Todo<L> { |
115 | | reg: Reg, |
116 | | pat: ENodeOrVar<L>, |
117 | | } |
118 | | |
119 | | impl<L: Language> PartialOrd for Todo<L> { |
120 | 810k | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
121 | 810k | Some(self.cmp(other)) |
122 | 810k | } Unexecuted instantiation: <egg::machine::Todo<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::cmp::PartialOrd>::partial_cmp Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::PartialOrd>::partial_cmp <egg::machine::Todo<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::cmp::PartialOrd>::partial_cmp Line | Count | Source | 120 | 810k | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | 121 | 810k | Some(self.cmp(other)) | 122 | 810k | } |
Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::PartialOrd>::partial_cmp |
123 | | } |
124 | | |
125 | | impl<L: Language> Ord for Todo<L> { |
126 | | // TodoList is a max-heap, so we greater is higher priority |
127 | | fn cmp(&self, other: &Self) -> Ordering { |
128 | | use ENodeOrVar::*; |
129 | 810k | match (&self.pat, &other.pat) { |
130 | | // fewer children means higher priority |
131 | 0 | (ENode(e1), ENode(e2)) => e2.len().cmp(&e1.len()), |
132 | | // Var is higher prio than enode |
133 | 365k | (ENode(_), Var(_)) => Ordering::Less, |
134 | 74.1k | (Var(_), ENode(_)) => Ordering::Greater, |
135 | 370k | (Var(_), Var(_)) => Ordering::Equal, |
136 | | } |
137 | 810k | } Unexecuted instantiation: <egg::machine::Todo<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::cmp::Ord>::cmp Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::Ord>::cmp <egg::machine::Todo<wasm_mutate::mutators::peephole::eggsy::lang::Lang> as core::cmp::Ord>::cmp Line | Count | Source | 129 | 810k | match (&self.pat, &other.pat) { | 130 | | // fewer children means higher priority | 131 | 0 | (ENode(e1), ENode(e2)) => e2.len().cmp(&e1.len()), | 132 | | // Var is higher prio than enode | 133 | 365k | (ENode(_), Var(_)) => Ordering::Less, | 134 | 74.1k | (Var(_), ENode(_)) => Ordering::Greater, | 135 | 370k | (Var(_), Var(_)) => Ordering::Equal, | 136 | | } | 137 | 810k | } |
Unexecuted instantiation: <egg::machine::Todo<_> as core::cmp::Ord>::cmp |
138 | | } |
139 | | |
140 | | struct Compiler<'a, L> { |
141 | | pattern: &'a [ENodeOrVar<L>], |
142 | | v2r: VarToReg, |
143 | | todo: TodoList<L>, |
144 | | out: Reg, |
145 | | } |
146 | | |
147 | | impl<'a, L: Language> Compiler<'a, L> { |
148 | 1.07M | fn compile(pattern: &'a [ENodeOrVar<L>]) -> Program<L> { |
149 | 1.07M | let last = pattern.last().unwrap(); |
150 | 1.07M | let mut compiler = Self { |
151 | 1.07M | pattern, |
152 | 1.07M | v2r: Default::default(), |
153 | 1.07M | todo: Default::default(), |
154 | 1.07M | out: Reg(1), |
155 | 1.07M | }; |
156 | 1.07M | compiler.todo.push(Todo { |
157 | 1.07M | reg: Reg(0), |
158 | 1.07M | pat: last.clone(), |
159 | 1.07M | }); |
160 | 1.07M | compiler.go() |
161 | 1.07M | } Unexecuted instantiation: <egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::compile Unexecuted instantiation: <egg::machine::Compiler<_>>::compile <egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::compile Line | Count | Source | 148 | 1.07M | fn compile(pattern: &'a [ENodeOrVar<L>]) -> Program<L> { | 149 | 1.07M | let last = pattern.last().unwrap(); | 150 | 1.07M | let mut compiler = Self { | 151 | 1.07M | pattern, | 152 | 1.07M | v2r: Default::default(), | 153 | 1.07M | todo: Default::default(), | 154 | 1.07M | out: Reg(1), | 155 | 1.07M | }; | 156 | 1.07M | compiler.todo.push(Todo { | 157 | 1.07M | reg: Reg(0), | 158 | 1.07M | pat: last.clone(), | 159 | 1.07M | }); | 160 | 1.07M | compiler.go() | 161 | 1.07M | } |
Unexecuted instantiation: <egg::machine::Compiler<_>>::compile |
162 | | |
163 | 1.07M | fn go(&mut self) -> Program<L> { |
164 | 1.07M | let mut instructions = vec![]; |
165 | 3.80M | while let Some(Todo { reg: i, pat }) = self.todo.pop() { |
166 | 2.72M | match pat { |
167 | 1.48M | ENodeOrVar::Var(v) => { |
168 | 1.48M | if let Some(&j) = self.v2r.get(&v) { |
169 | 35.6k | instructions.push(Instruction::Compare { i, j }) |
170 | 1.44M | } else { |
171 | 1.44M | self.v2r.insert(v, i); |
172 | 1.44M | } |
173 | | } |
174 | 1.24M | ENodeOrVar::ENode(node) => { |
175 | 1.24M | let out = self.out; |
176 | 1.24M | self.out.0 += node.len() as u32; |
177 | | |
178 | 1.65M | for (id, &child) in node.children().iter().enumerate() { |
179 | 1.65M | let r = Reg(out.0 + id as u32); |
180 | 1.65M | self.todo.push(Todo { |
181 | 1.65M | reg: r, |
182 | 1.65M | pat: self.pattern[usize::from(child)].clone(), |
183 | 1.65M | }); |
184 | 1.65M | } |
185 | | |
186 | | // zero out the children so Bind can use it to sort |
187 | 1.65M | let node = node.map_children(|_| Id::from(0)); Unexecuted instantiation: <egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::go::{closure#0}Unexecuted instantiation: <egg::machine::Compiler<_>>::go::{closure#0}<egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::go::{closure#0}Line | Count | Source | 187 | 1.65M | let node = node.map_children(|_| Id::from(0)); |
Unexecuted instantiation: <egg::machine::Compiler<_>>::go::{closure#0} |
188 | 1.24M | instructions.push(Instruction::Bind { i, node, out }) |
189 | | } |
190 | | } |
191 | | } |
192 | | |
193 | 1.07M | let mut subst = Subst::default(); |
194 | 2.52M | for (v, r) in &self.v2r { |
195 | 1.44M | subst.insert(*v, Id::from(r.0 as usize)); |
196 | 1.44M | } |
197 | 1.07M | Program { |
198 | 1.07M | instructions, |
199 | 1.07M | subst, |
200 | 1.07M | } |
201 | 1.07M | } Unexecuted instantiation: <egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::go Unexecuted instantiation: <egg::machine::Compiler<_>>::go <egg::machine::Compiler<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::go Line | Count | Source | 163 | 1.07M | fn go(&mut self) -> Program<L> { | 164 | 1.07M | let mut instructions = vec![]; | 165 | 3.80M | while let Some(Todo { reg: i, pat }) = self.todo.pop() { | 166 | 2.72M | match pat { | 167 | 1.48M | ENodeOrVar::Var(v) => { | 168 | 1.48M | if let Some(&j) = self.v2r.get(&v) { | 169 | 35.6k | instructions.push(Instruction::Compare { i, j }) | 170 | 1.44M | } else { | 171 | 1.44M | self.v2r.insert(v, i); | 172 | 1.44M | } | 173 | | } | 174 | 1.24M | ENodeOrVar::ENode(node) => { | 175 | 1.24M | let out = self.out; | 176 | 1.24M | self.out.0 += node.len() as u32; | 177 | | | 178 | 1.65M | for (id, &child) in node.children().iter().enumerate() { | 179 | 1.65M | let r = Reg(out.0 + id as u32); | 180 | 1.65M | self.todo.push(Todo { | 181 | 1.65M | reg: r, | 182 | 1.65M | pat: self.pattern[usize::from(child)].clone(), | 183 | 1.65M | }); | 184 | 1.65M | } | 185 | | | 186 | | // zero out the children so Bind can use it to sort | 187 | 1.24M | let node = node.map_children(|_| Id::from(0)); | 188 | 1.24M | instructions.push(Instruction::Bind { i, node, out }) | 189 | | } | 190 | | } | 191 | | } | 192 | | | 193 | 1.07M | let mut subst = Subst::default(); | 194 | 2.52M | for (v, r) in &self.v2r { | 195 | 1.44M | subst.insert(*v, Id::from(r.0 as usize)); | 196 | 1.44M | } | 197 | 1.07M | Program { | 198 | 1.07M | instructions, | 199 | 1.07M | subst, | 200 | 1.07M | } | 201 | 1.07M | } |
Unexecuted instantiation: <egg::machine::Compiler<_>>::go |
202 | | } |
203 | | |
204 | | impl<L: Language> Program<L> { |
205 | 1.07M | pub(crate) fn compile_from_pat(pattern: &PatternAst<L>) -> Self { |
206 | 1.07M | let program = Compiler::compile(pattern.as_ref()); |
207 | 1.07M | log::debug!("Compiled {:?} to {:?}", pattern.as_ref(), program); |
208 | 1.07M | program |
209 | 1.07M | } Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::compile_from_pat Unexecuted instantiation: <egg::machine::Program<_>>::compile_from_pat <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::compile_from_pat Line | Count | Source | 205 | 1.07M | pub(crate) fn compile_from_pat(pattern: &PatternAst<L>) -> Self { | 206 | 1.07M | let program = Compiler::compile(pattern.as_ref()); | 207 | 1.07M | log::debug!("Compiled {:?} to {:?}", pattern.as_ref(), program); | 208 | 1.07M | program | 209 | 1.07M | } |
Unexecuted instantiation: <egg::machine::Program<_>>::compile_from_pat |
210 | | |
211 | 2.83M | pub fn run<A>(&self, egraph: &EGraph<L, A>, eclass: Id) -> Vec<Subst> |
212 | 2.83M | where |
213 | 2.83M | A: Analysis<L>, |
214 | 2.83M | { |
215 | 2.83M | let mut machine = Machine::default(); |
216 | 2.83M | |
217 | 2.83M | assert_eq!(machine.reg.len(), 0); |
218 | 2.83M | machine.reg.push(eclass); |
219 | 2.83M | |
220 | 2.83M | let mut substs = Vec::new(); |
221 | 2.83M | machine.run( |
222 | 2.83M | egraph, |
223 | 2.83M | &self.instructions, |
224 | 2.83M | &self.subst, |
225 | 2.83M | &mut |machine, subst| { |
226 | 2.83M | let subst_vec = subst |
227 | 2.83M | .vec |
228 | 2.83M | .iter() |
229 | 2.83M | // HACK we are reusing Ids here, this is bad |
230 | 2.83M | .map(|(v, reg_id)| (*v, machine.reg(Reg(usize::from(*reg_id) as u32)))) Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}::{closure#0}Unexecuted instantiation: <egg::machine::Program<_>>::run::<_>::{closure#0}::{closure#0}<egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}::{closure#0}Line | Count | Source | 230 | 2.83M | .map(|(v, reg_id)| (*v, machine.reg(Reg(usize::from(*reg_id) as u32)))) |
Unexecuted instantiation: <egg::machine::Program<_>>::run::<_>::{closure#0}::{closure#0} |
231 | 2.83M | .collect(); |
232 | 2.83M | substs.push(Subst { vec: subst_vec }) |
233 | 2.83M | }, Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}Unexecuted instantiation: <egg::machine::Program<_>>::run::<_>::{closure#0}<egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis>::{closure#0}Line | Count | Source | 225 | 2.83M | &mut |machine, subst| { | 226 | 2.83M | let subst_vec = subst | 227 | 2.83M | .vec | 228 | 2.83M | .iter() | 229 | 2.83M | // HACK we are reusing Ids here, this is bad | 230 | 2.83M | .map(|(v, reg_id)| (*v, machine.reg(Reg(usize::from(*reg_id) as u32)))) | 231 | 2.83M | .collect(); | 232 | 2.83M | substs.push(Subst { vec: subst_vec }) | 233 | 2.83M | }, |
Unexecuted instantiation: <egg::machine::Program<_>>::run::<_>::{closure#0} |
234 | 2.83M | ); |
235 | 2.83M | |
236 | 2.83M | log::trace!("Ran program, found {:?}", substs); |
237 | 2.83M | substs |
238 | 2.83M | } Unexecuted instantiation: <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis> Unexecuted instantiation: <egg::machine::Program<_>>::run::<_> <egg::machine::Program<wasm_mutate::mutators::peephole::eggsy::lang::Lang>>::run::<wasm_mutate::mutators::peephole::eggsy::analysis::PeepholeMutationAnalysis> Line | Count | Source | 211 | 2.83M | pub fn run<A>(&self, egraph: &EGraph<L, A>, eclass: Id) -> Vec<Subst> | 212 | 2.83M | where | 213 | 2.83M | A: Analysis<L>, | 214 | 2.83M | { | 215 | 2.83M | let mut machine = Machine::default(); | 216 | 2.83M | | 217 | 2.83M | assert_eq!(machine.reg.len(), 0); | 218 | 2.83M | machine.reg.push(eclass); | 219 | 2.83M | | 220 | 2.83M | let mut substs = Vec::new(); | 221 | 2.83M | machine.run( | 222 | 2.83M | egraph, | 223 | 2.83M | &self.instructions, | 224 | 2.83M | &self.subst, | 225 | 2.83M | &mut |machine, subst| { | 226 | | let subst_vec = subst | 227 | | .vec | 228 | | .iter() | 229 | | // HACK we are reusing Ids here, this is bad | 230 | | .map(|(v, reg_id)| (*v, machine.reg(Reg(usize::from(*reg_id) as u32)))) | 231 | | .collect(); | 232 | | substs.push(Subst { vec: subst_vec }) | 233 | 2.83M | }, | 234 | 2.83M | ); | 235 | 2.83M | | 236 | 2.83M | log::trace!("Ran program, found {:?}", substs); | 237 | 2.83M | substs | 238 | 2.83M | } |
Unexecuted instantiation: <egg::machine::Program<_>>::run::<_> |
239 | | } |