telltale_language/compiler/projection/
merge_eq.rs1use super::*;
2
3impl PartialEq for LocalType {
4 #[allow(clippy::too_many_lines)]
5 fn eq(&self, other: &Self) -> bool {
6 match (self, other) {
7 (LocalType::End, LocalType::End) => true,
8 (LocalType::Var(a), LocalType::Var(b)) => a == b,
9 (
10 LocalType::Send {
11 to: to1,
12 message: msg1,
13 continuation: cont1,
14 },
15 LocalType::Send {
16 to: to2,
17 message: msg2,
18 continuation: cont2,
19 },
20 ) => to1 == to2 && msg1.name == msg2.name && cont1 == cont2,
21 (
22 LocalType::Receive {
23 from: from1,
24 message: msg1,
25 continuation: cont1,
26 },
27 LocalType::Receive {
28 from: from2,
29 message: msg2,
30 continuation: cont2,
31 },
32 ) => from1 == from2 && msg1.name == msg2.name && cont1 == cont2,
33 (
34 LocalType::Select {
35 to: to1,
36 branches: br1,
37 },
38 LocalType::Select {
39 to: to2,
40 branches: br2,
41 },
42 ) => {
43 to1 == to2
44 && br1.len() == br2.len()
45 && br1
46 .iter()
47 .zip(br2.iter())
48 .all(|((l1, t1), (l2, t2))| l1 == l2 && t1 == t2)
49 }
50 (
51 LocalType::Branch {
52 from: from1,
53 branches: br1,
54 },
55 LocalType::Branch {
56 from: from2,
57 branches: br2,
58 },
59 ) => {
60 from1 == from2
61 && br1.len() == br2.len()
62 && br1
63 .iter()
64 .zip(br2.iter())
65 .all(|((l1, t1), (l2, t2))| l1 == l2 && t1 == t2)
66 }
67 (
68 LocalType::LocalChoice { branches: br1 },
69 LocalType::LocalChoice { branches: br2 },
70 ) => {
71 br1.len() == br2.len()
72 && br1
73 .iter()
74 .zip(br2.iter())
75 .all(|((l1, t1), (l2, t2))| l1 == l2 && t1 == t2)
76 }
77 (
78 LocalType::Loop {
79 condition: c1,
80 body: b1,
81 },
82 LocalType::Loop {
83 condition: c2,
84 body: b2,
85 },
86 ) => {
87 let cond_eq = match (c1, c2) {
89 (None, None) => true,
90 (
91 Some(crate::ast::protocol::Condition::Count(n1)),
92 Some(crate::ast::protocol::Condition::Count(n2)),
93 ) => n1 == n2,
94 (
95 Some(crate::ast::protocol::Condition::RoleDecides(r1)),
96 Some(crate::ast::protocol::Condition::RoleDecides(r2)),
97 ) => r1 == r2,
98 _ => false,
99 };
100 cond_eq && b1 == b2
101 }
102 (
103 LocalType::Rec {
104 label: l1,
105 body: b1,
106 },
107 LocalType::Rec {
108 label: l2,
109 body: b2,
110 },
111 ) => l1 == l2 && b1 == b2,
112 _ => false,
113 }
114 }
115}
116
117impl Eq for LocalType {}