1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use std::borrow::Cow;
use sway_types::{state::StateIndex, Ident, Span, Spanned};
use crate::{decl_engine::*, engine_threading::*, language::ty::*, type_system::*};
#[derive(Clone, Debug)]
pub struct TyReassignment {
pub lhs_base_name: Ident,
pub lhs_type: TypeId,
pub lhs_indices: Vec<ProjectionKind>,
pub rhs: TyExpression,
}
impl EqWithEngines for TyReassignment {}
impl PartialEqWithEngines for TyReassignment {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
self.lhs_base_name == other.lhs_base_name
&& self.lhs_type == other.lhs_type
&& self.lhs_indices.eq(&other.lhs_indices, engines)
&& self.rhs.eq(&other.rhs, engines)
}
}
impl SubstTypes for TyReassignment {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: Engines<'_>) {
self.rhs.subst(type_mapping, engines);
self.lhs_type.subst(type_mapping, engines);
}
}
impl ReplaceSelfType for TyReassignment {
fn replace_self_type(&mut self, engines: Engines<'_>, self_type: TypeId) {
self.rhs.replace_self_type(engines, self_type);
self.lhs_type.replace_self_type(engines, self_type);
}
}
impl ReplaceDecls for TyReassignment {
fn replace_decls_inner(&mut self, decl_mapping: &DeclMapping, engines: Engines<'_>) {
self.rhs.replace_decls(decl_mapping, engines);
}
}
#[derive(Clone, Debug)]
pub enum ProjectionKind {
StructField {
name: Ident,
},
TupleField {
index: usize,
index_span: Span,
},
ArrayIndex {
index: Box<TyExpression>,
index_span: Span,
},
}
impl EqWithEngines for ProjectionKind {}
impl PartialEqWithEngines for ProjectionKind {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
match (self, other) {
(
ProjectionKind::StructField { name: l_name },
ProjectionKind::StructField { name: r_name },
) => l_name == r_name,
(
ProjectionKind::TupleField {
index: l_index,
index_span: l_index_span,
},
ProjectionKind::TupleField {
index: r_index,
index_span: r_index_span,
},
) => l_index == r_index && l_index_span == r_index_span,
(
ProjectionKind::ArrayIndex {
index: l_index,
index_span: l_index_span,
},
ProjectionKind::ArrayIndex {
index: r_index,
index_span: r_index_span,
},
) => l_index.eq(r_index, engines) && l_index_span == r_index_span,
_ => false,
}
}
}
impl Spanned for ProjectionKind {
fn span(&self) -> Span {
match self {
ProjectionKind::StructField { name } => name.span(),
ProjectionKind::TupleField { index_span, .. } => index_span.clone(),
ProjectionKind::ArrayIndex { index_span, .. } => index_span.clone(),
}
}
}
impl ProjectionKind {
pub(crate) fn pretty_print(&self) -> Cow<str> {
match self {
ProjectionKind::StructField { name } => Cow::Borrowed(name.as_str()),
ProjectionKind::TupleField { index, .. } => Cow::Owned(index.to_string()),
ProjectionKind::ArrayIndex { index, .. } => Cow::Owned(format!("{index:#?}")),
}
}
}
#[derive(Clone, Debug)]
pub struct TyStorageReassignment {
pub fields: Vec<TyStorageReassignDescriptor>,
pub(crate) ix: StateIndex,
pub rhs: TyExpression,
}
impl EqWithEngines for TyStorageReassignment {}
impl PartialEqWithEngines for TyStorageReassignment {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
self.fields.eq(&other.fields, engines)
&& self.ix == other.ix
&& self.rhs.eq(&other.rhs, engines)
}
}
impl Spanned for TyStorageReassignment {
fn span(&self) -> Span {
self.fields
.iter()
.fold(self.fields[0].span.clone(), |acc, field| {
Span::join(acc, field.span.clone())
})
}
}
impl TyStorageReassignment {
pub fn names(&self) -> Vec<Ident> {
self.fields
.iter()
.map(|f| f.name.clone())
.collect::<Vec<_>>()
}
}
#[derive(Clone, Debug)]
pub struct TyStorageReassignDescriptor {
pub name: Ident,
pub type_id: TypeId,
pub(crate) span: Span,
}
impl EqWithEngines for TyStorageReassignDescriptor {}
impl PartialEqWithEngines for TyStorageReassignDescriptor {
fn eq(&self, other: &Self, engines: Engines<'_>) -> bool {
let type_engine = engines.te();
self.name == other.name
&& type_engine
.get(self.type_id)
.eq(&type_engine.get(other.type_id), engines)
}
}