• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergoplatform / sigma-rust / 19909456309

03 Dec 2025 09:29PM UTC coverage: 86.947% (+8.5%) from 78.463%
19909456309

Pull #838

github

web-flow
Merge 717ebc4b7 into 2f840d387
Pull Request #838: Fix CI, bump dependencies and rust toolchain

20 of 24 new or added lines in 12 files covered. (83.33%)

1614 existing lines in 221 files now uncovered.

27478 of 31603 relevant lines covered (86.95%)

506307.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/ergotree-ir/src/source_span.rs
1
//! Source position for an IR node in the source code
2

3
use alloc::boxed::Box;
4

5
use crate::mir::and::And;
6
use crate::mir::bin_op::BinOp;
7
use crate::mir::block::BlockValue;
8
use crate::mir::byte_array_to_bigint::ByteArrayToBigInt;
9
use crate::mir::byte_array_to_long::ByteArrayToLong;
10
use crate::mir::coll_append::Append;
11
use crate::mir::coll_by_index::ByIndex;
12
use crate::mir::coll_exists::Exists;
13
use crate::mir::coll_filter::Filter;
14
use crate::mir::coll_fold::Fold;
15
use crate::mir::coll_forall::ForAll;
16
use crate::mir::coll_map::Map;
17
use crate::mir::coll_slice::Slice;
18
use crate::mir::expr::Expr;
19
use crate::mir::extract_reg_as::ExtractRegisterAs;
20
use crate::mir::get_var::GetVar;
21
use crate::mir::logical_not::LogicalNot;
22
use crate::mir::method_call::MethodCall;
23
use crate::mir::negation::Negation;
24
use crate::mir::option_get::OptionGet;
25
use crate::mir::option_get_or_else::OptionGetOrElse;
26
use crate::mir::option_is_defined::OptionIsDefined;
27
use crate::mir::or::Or;
28
use crate::mir::property_call::PropertyCall;
29
use crate::mir::select_field::SelectField;
30
use crate::mir::subst_const::SubstConstants;
31
use crate::mir::tree_lookup::TreeLookup;
32
use crate::mir::val_def::ValDef;
33
use crate::traversable::Traversable;
34

35
/// Source position for the Expr
36
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
37
pub struct SourceSpan {
38
    /// Start position in the span
39
    pub offset: usize,
40
    /// The length of the span
41
    pub length: usize,
42
}
43

44
impl SourceSpan {
45
    /// Empty span
46
    pub fn empty() -> Self {
424,181✔
47
        SourceSpan {
424,181✔
48
            offset: 0,
424,181✔
49
            length: 0,
424,181✔
50
        }
424,181✔
51
    }
424,181✔
52
}
53

54
impl From<(usize, usize)> for SourceSpan {
55
    fn from(value: (usize, usize)) -> Self {
4✔
56
        SourceSpan {
4✔
57
            offset: value.0,
4✔
58
            length: value.1,
4✔
59
        }
4✔
60
    }
4✔
61
}
62

63
#[cfg(feature = "std")]
64
impl From<SourceSpan> for miette::SourceSpan {
65
    fn from(value: SourceSpan) -> Self {
×
NEW
66
        miette::SourceSpan::new(value.offset.into(), value.length)
×
UNCOV
67
    }
×
68
}
69

70
/// Wrapper for Expr with source position
71
#[derive(PartialEq, Eq, Debug, Clone)]
72
pub struct Spanned<T> {
73
    /// Source position
74
    pub source_span: SourceSpan,
75
    /// Wrapped value
76
    pub expr: T,
77
}
78

79
impl<T> Spanned<T> {
80
    /// Expression
81
    pub fn expr(&self) -> &T {
363,480✔
82
        &self.expr
363,480✔
83
    }
363,480✔
84
}
85

86
impl<T: Traversable> Traversable for Spanned<T> {
87
    type Item = T::Item;
88
    fn children<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Self::Item> + 'a> {
6✔
89
        self.expr.children()
6✔
90
    }
6✔
91
    fn children_mut<'a>(&'a mut self) -> Box<dyn Iterator<Item = &'a mut T::Item> + 'a> {
5,142✔
92
        self.expr.children_mut()
5,142✔
93
    }
5,142✔
94
}
95

96
macro_rules! into_expr {
97
    ($variant: ident) => {
98
        impl From<$variant> for Expr {
99
            fn from(v: $variant) -> Self {
153,600✔
100
                Expr::$variant(Spanned {
153,600✔
101
                    source_span: SourceSpan::empty(),
153,600✔
102
                    expr: v,
153,600✔
103
                })
153,600✔
104
            }
153,600✔
105
        }
106
    };
107
}
108

109
into_expr!(Append);
110
into_expr!(BlockValue);
111
into_expr!(ValDef);
112
into_expr!(BinOp);
113
into_expr!(ByIndex);
114
into_expr!(SubstConstants);
115
into_expr!(ByteArrayToLong);
116
into_expr!(ByteArrayToBigInt);
117
into_expr!(MethodCall);
118
into_expr!(PropertyCall);
119
into_expr!(Negation);
120
into_expr!(OptionGet);
121
into_expr!(OptionIsDefined);
122
into_expr!(OptionGetOrElse);
123
into_expr!(ExtractRegisterAs);
124
into_expr!(Slice);
125
into_expr!(Fold);
126
into_expr!(Map);
127
into_expr!(Filter);
128
into_expr!(Exists);
129
into_expr!(ForAll);
130
into_expr!(SelectField);
131
into_expr!(GetVar);
132
into_expr!(TreeLookup);
133
into_expr!(And);
134
into_expr!(Or);
135
into_expr!(LogicalNot);
136

137
impl<T> From<T> for Spanned<T> {
138
    fn from(v: T) -> Self {
14,712✔
139
        Spanned {
14,712✔
140
            source_span: SourceSpan::empty(),
14,712✔
141
            expr: v,
14,712✔
142
        }
14,712✔
143
    }
14,712✔
144
}
145

146
impl Expr {
147
    /// Source span for the Expr
148
    pub fn span(&self) -> SourceSpan {
310,118✔
149
        match self {
310,118✔
150
            Expr::Append(op) => op.source_span,
30✔
151
            Expr::Const(_) => SourceSpan::empty(),
221,306✔
152
            Expr::ConstPlaceholder(_) => SourceSpan::empty(),
×
153
            Expr::SubstConstants(op) => op.source_span,
1,024✔
154
            Expr::ByteArrayToLong(op) => op.source_span,
12✔
155
            Expr::ByteArrayToBigInt(op) => op.source_span,
20✔
156
            Expr::LongToByteArray(_) => SourceSpan::empty(),
8✔
157
            Expr::Collection(_) => SourceSpan::empty(),
2,056✔
158
            Expr::Tuple(_) => SourceSpan::empty(),
4✔
159
            Expr::CalcBlake2b256(_) => SourceSpan::empty(),
512✔
160
            Expr::CalcSha256(_) => SourceSpan::empty(),
512✔
161
            Expr::Context => SourceSpan::empty(),
172✔
162
            Expr::Global => SourceSpan::empty(),
8,634✔
163
            Expr::GlobalVars(_) => SourceSpan::empty(),
72✔
164
            Expr::FuncValue(_) => SourceSpan::empty(),
130✔
165
            Expr::Apply(_) => SourceSpan::empty(),
6✔
166
            Expr::MethodCall(op) => op.source_span,
46,686✔
167
            Expr::PropertyCall(op) => op.source_span,
218✔
168
            Expr::BlockValue(op) => op.source_span,
14✔
169
            Expr::ValDef(op) => op.source_span,
×
170
            Expr::ValUse(_) => SourceSpan::empty(),
170✔
171
            Expr::If(_) => SourceSpan::empty(),
24✔
172
            Expr::BinOp(op) => op.source_span,
5,949✔
173
            Expr::And(_) => SourceSpan::empty(),
512✔
174
            Expr::Or(_) => SourceSpan::empty(),
512✔
175
            Expr::Xor(_) => SourceSpan::empty(),
522✔
176
            Expr::Atleast(_) => SourceSpan::empty(),
158✔
177
            Expr::LogicalNot(_) => SourceSpan::empty(),
6✔
178
            Expr::Negation(op) => op.source_span,
20✔
179
            Expr::BitInversion(_) => SourceSpan::empty(),
40✔
180
            Expr::OptionGet(op) => op.source_span,
6✔
181
            Expr::OptionIsDefined(op) => op.source_span,
2✔
182
            Expr::OptionGetOrElse(op) => op.source_span,
12✔
183
            Expr::ExtractAmount(_) => SourceSpan::empty(),
57✔
184
            Expr::ExtractRegisterAs(op) => op.source_span,
18✔
185
            Expr::ExtractBytes(_) => SourceSpan::empty(),
2✔
186
            Expr::ExtractBytesWithNoRef(_) => SourceSpan::empty(),
2✔
187
            Expr::ExtractScriptBytes(_) => SourceSpan::empty(),
2✔
188
            Expr::ExtractCreationInfo(_) => SourceSpan::empty(),
2✔
189
            Expr::ExtractId(_) => SourceSpan::empty(),
2✔
190
            Expr::ByIndex(op) => op.source_span,
50✔
191
            Expr::SizeOf(_) => SourceSpan::empty(),
2✔
192
            Expr::Slice(op) => op.source_span,
18✔
193
            Expr::Fold(op) => op.source_span,
32✔
194
            Expr::Map(op) => op.source_span,
34✔
195
            Expr::Filter(op) => op.source_span,
32✔
196
            Expr::Exists(op) => op.source_span,
8✔
197
            Expr::ForAll(op) => op.source_span,
6✔
198
            Expr::SelectField(op) => op.source_span,
46✔
199
            Expr::BoolToSigmaProp(_) => SourceSpan::empty(),
516✔
200
            Expr::Upcast(_) => SourceSpan::empty(),
9,230✔
201
            Expr::Downcast(_) => SourceSpan::empty(),
6,272✔
202
            Expr::CreateProveDlog(_) => SourceSpan::empty(),
×
203
            Expr::CreateProveDhTuple(_) => SourceSpan::empty(),
×
204
            Expr::SigmaPropBytes(_) => SourceSpan::empty(),
528✔
205
            Expr::DecodePoint(_) => SourceSpan::empty(),
512✔
206
            Expr::SigmaAnd(_) => SourceSpan::empty(),
254✔
207
            Expr::SigmaOr(_) => SourceSpan::empty(),
564✔
208
            Expr::GetVar(op) => op.source_span,
8✔
209
            Expr::DeserializeRegister(_) => SourceSpan::empty(),
2✔
210
            Expr::DeserializeContext(_) => SourceSpan::empty(),
2✔
211
            Expr::MultiplyGroup(_) => SourceSpan::empty(),
1,024✔
212
            Expr::Exponentiate(_) => SourceSpan::empty(),
1,026✔
213
            Expr::XorOf(_) => SourceSpan::empty(),
512✔
214
            Expr::TreeLookup(op) => op.source_span,
4✔
215
            Expr::CreateAvlTree(_) => SourceSpan::empty(),
2✔
216
        }
217
    }
310,118✔
218
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc