Skip to content

Commit f9a9f6a

Browse files
committed
Merge branch 'aac-client-breaking' into chore/rename-interpreter-error-to-vm-internal-error
2 parents bbead54 + 2783191 commit f9a9f6a

File tree

51 files changed

+2723
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2723
-456
lines changed

.github/workflows/clippy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
pull_request:
1414
branches:
1515
- develop
16+
- aac-client-breaking # temp branch for aac work
1617
types:
1718
- opened
1819
- reopened

clarity-types/src/errors/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum Error {
5959
/// indicating a mismatch in function entry/exit logic.
6060
Internal(VmInternalError),
6161
Runtime(RuntimeErrorType, Option<StackTrace>),
62-
ShortReturn(ShortReturnType),
62+
EarlyReturn(EarlyReturnError),
6363
}
6464

6565
/// Represents an internal, unrecoverable error within the Clarity VM.
@@ -148,8 +148,15 @@ pub enum RuntimeErrorType {
148148
}
149149

150150
#[derive(Debug, PartialEq)]
151-
pub enum ShortReturnType {
152-
ExpectedValue(Box<Value>),
151+
/// Errors triggered during Clarity contract evaluation that cause early termination.
152+
/// These errors halt evaluation and fail the transaction.
153+
pub enum EarlyReturnError {
154+
/// Failed to unwrap an `Optional` (`none`) or `Response` (`err` or `ok`) Clarity value.
155+
/// The `Box<Value>` holds the original or thrown value. Triggered by `try!`, `unwrap-or`, or
156+
/// `unwrap-err-or`.
157+
UnwrapFailed(Box<Value>),
158+
/// An 'asserts!' expression evaluated to false.
159+
/// The `Box<Value>` holds the value provided as the second argument to `asserts!`.
153160
AssertionFailed(Box<Value>),
154161
}
155162

@@ -166,7 +173,7 @@ impl PartialEq<Error> for Error {
166173
match (self, other) {
167174
(Error::Runtime(x, _), Error::Runtime(y, _)) => x == y,
168175
(Error::Unchecked(x), Error::Unchecked(y)) => x == y,
169-
(Error::ShortReturn(x), Error::ShortReturn(y)) => x == y,
176+
(Error::EarlyReturn(x), Error::EarlyReturn(y)) => x == y,
170177
(Error::Internal(x), Error::Internal(y)) => x == y,
171178
_ => false,
172179
}
@@ -252,9 +259,9 @@ impl From<(CheckErrors, &SymbolicExpression)> for Error {
252259
}
253260
}
254261

255-
impl From<ShortReturnType> for Error {
256-
fn from(err: ShortReturnType) -> Self {
257-
Error::ShortReturn(err)
262+
impl From<EarlyReturnError> for Error {
263+
fn from(err: EarlyReturnError) -> Self {
264+
Error::EarlyReturn(err)
258265
}
259266
}
260267

@@ -269,11 +276,11 @@ impl From<Error> for () {
269276
fn from(_err: Error) -> Self {}
270277
}
271278

272-
impl From<ShortReturnType> for Value {
273-
fn from(val: ShortReturnType) -> Self {
279+
impl From<EarlyReturnError> for Value {
280+
fn from(val: EarlyReturnError) -> Self {
274281
match val {
275-
ShortReturnType::ExpectedValue(v) => *v,
276-
ShortReturnType::AssertionFailed(v) => *v,
282+
EarlyReturnError::UnwrapFailed(v) => *v,
283+
EarlyReturnError::AssertionFailed(v) => *v,
277284
}
278285
}
279286
}
@@ -285,15 +292,15 @@ mod test {
285292
#[test]
286293
fn equality() {
287294
assert_eq!(
288-
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true)))),
289-
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
295+
Error::EarlyReturn(EarlyReturnError::UnwrapFailed(Box::new(Value::Bool(true)))),
296+
Error::EarlyReturn(EarlyReturnError::UnwrapFailed(Box::new(Value::Bool(true))))
290297
);
291298
assert_eq!(
292299
Error::Internal(VmInternalError::InvariantViolation("".to_string())),
293300
Error::Internal(VmInternalError::InvariantViolation("".to_string()))
294301
);
295302
assert!(
296-
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
303+
Error::EarlyReturn(EarlyReturnError::UnwrapFailed(Box::new(Value::Bool(true))))
297304
!= Error::Internal(VmInternalError::InvariantViolation("".to_string()))
298305
);
299306
}

clarity-types/src/types/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ impl SequenceData {
560560
pub fn concat(&mut self, epoch: &StacksEpochId, other_seq: SequenceData) -> Result<()> {
561561
match (self, other_seq) {
562562
(SequenceData::List(inner_data), SequenceData::List(other_inner_data)) => {
563-
inner_data.append(epoch, other_inner_data)
563+
inner_data.append(epoch, other_inner_data)?;
564564
}
565565
(SequenceData::Buffer(inner_data), SequenceData::Buffer(ref mut other_inner_data)) => {
566-
inner_data.append(other_inner_data)
566+
inner_data.append(other_inner_data);
567567
}
568568
(
569569
SequenceData::String(CharType::ASCII(inner_data)),
@@ -573,8 +573,8 @@ impl SequenceData {
573573
SequenceData::String(CharType::UTF8(inner_data)),
574574
SequenceData::String(CharType::UTF8(ref mut other_inner_data)),
575575
) => inner_data.append(other_inner_data),
576-
_ => Err(RuntimeErrorType::BadTypeConstruction.into()),
577-
}?;
576+
_ => return Err(RuntimeErrorType::BadTypeConstruction.into()),
577+
};
578578
Ok(())
579579
}
580580

@@ -1240,9 +1240,8 @@ impl BuffData {
12401240
self.data.as_slice()
12411241
}
12421242

1243-
fn append(&mut self, other_seq: &mut BuffData) -> Result<()> {
1243+
fn append(&mut self, other_seq: &mut BuffData) {
12441244
self.data.append(&mut other_seq.data);
1245-
Ok(())
12461245
}
12471246

12481247
pub fn empty() -> Self {
@@ -1279,9 +1278,8 @@ impl ListData {
12791278
}
12801279

12811280
impl ASCIIData {
1282-
fn append(&mut self, other_seq: &mut ASCIIData) -> Result<()> {
1281+
fn append(&mut self, other_seq: &mut ASCIIData) {
12831282
self.data.append(&mut other_seq.data);
1284-
Ok(())
12851283
}
12861284

12871285
pub fn len(&self) -> Result<BufferLength> {
@@ -1293,9 +1291,8 @@ impl ASCIIData {
12931291
}
12941292

12951293
impl UTF8Data {
1296-
fn append(&mut self, other_seq: &mut UTF8Data) -> Result<()> {
1294+
fn append(&mut self, other_seq: &mut UTF8Data) {
12971295
self.data.append(&mut other_seq.data);
1298-
Ok(())
12991296
}
13001297

13011298
pub fn len(&self) -> Result<BufferLength> {
@@ -1528,12 +1525,11 @@ impl TupleData {
15281525
fn new(
15291526
type_signature: TupleTypeSignature,
15301527
data_map: BTreeMap<ClarityName, Value>,
1531-
) -> Result<TupleData> {
1532-
let t = TupleData {
1528+
) -> TupleData {
1529+
TupleData {
15331530
type_signature,
15341531
data_map,
1535-
};
1536-
Ok(t)
1532+
}
15371533
}
15381534

15391535
/// Return the number of fields in this tuple value
@@ -1561,7 +1557,7 @@ impl TupleData {
15611557
data_map.insert(name, value);
15621558
}
15631559

1564-
Self::new(TupleTypeSignature::try_from(type_map)?, data_map)
1560+
Ok(Self::new(TupleTypeSignature::try_from(type_map)?, data_map))
15651561
}
15661562

15671563
// TODO: add tests from mutation testing results #4834
@@ -1581,7 +1577,7 @@ impl TupleData {
15811577
}
15821578
data_map.insert(name, value);
15831579
}
1584-
Self::new(expected.clone(), data_map)
1580+
Ok(Self::new(expected.clone(), data_map))
15851581
}
15861582

15871583
pub fn get(&self, name: &str) -> Result<&Value> {

clarity/src/vm/analysis/type_checker/v2_05/contexts.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,8 @@ impl ContractContext {
173173
Ok(())
174174
}
175175

176-
pub fn add_implemented_trait(
177-
&mut self,
178-
trait_identifier: TraitIdentifier,
179-
) -> Result<(), CheckError> {
176+
pub fn add_implemented_trait(&mut self, trait_identifier: TraitIdentifier) {
180177
self.implemented_traits.insert(trait_identifier);
181-
Ok(())
182178
}
183179

184180
pub fn get_trait(&self, trait_name: &str) -> Option<&BTreeMap<ClarityName, FunctionSignature>> {

clarity/src/vm/analysis/type_checker/v2_05/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
10081008
}
10091009
DefineFunctionsParsed::ImplTrait { trait_identifier } => {
10101010
self.contract_context
1011-
.add_implemented_trait(trait_identifier.clone())?;
1011+
.add_implemented_trait(trait_identifier.clone());
10121012
}
10131013
};
10141014
Ok(Some(()))

clarity/src/vm/analysis/type_checker/v2_1/contexts.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl TraitContext {
6161
contract_identifier: QualifiedContractIdentifier,
6262
trait_name: ClarityName,
6363
trait_signature: BTreeMap<ClarityName, FunctionSignature>,
64-
) -> Result<(), CheckError> {
64+
) {
6565
match self {
6666
Self::Clarity1(map) => {
6767
map.insert(trait_name, trait_signature);
@@ -77,15 +77,14 @@ impl TraitContext {
7777
);
7878
}
7979
}
80-
Ok(())
8180
}
8281

8382
pub fn add_used_trait(
8483
&mut self,
8584
alias: ClarityName,
8685
trait_id: TraitIdentifier,
8786
trait_signature: BTreeMap<ClarityName, FunctionSignature>,
88-
) -> Result<(), CheckError> {
87+
) {
8988
match self {
9089
Self::Clarity1(map) => {
9190
map.insert(trait_id.name, trait_signature);
@@ -95,7 +94,6 @@ impl TraitContext {
9594
all.insert(trait_id, trait_signature);
9695
}
9796
}
98-
Ok(())
9997
}
10098

10199
pub fn get_trait(
@@ -293,7 +291,8 @@ impl ContractContext {
293291
self.contract_identifier.clone(),
294292
trait_name,
295293
trait_signature,
296-
)
294+
);
295+
Ok(())
297296
}
298297

299298
pub fn add_used_trait(
@@ -306,15 +305,12 @@ impl ContractContext {
306305
self.check_name_used(&alias)?;
307306
}
308307

309-
self.traits.add_used_trait(alias, trait_id, trait_signature)
308+
self.traits.add_used_trait(alias, trait_id, trait_signature);
309+
Ok(())
310310
}
311311

312-
pub fn add_implemented_trait(
313-
&mut self,
314-
trait_identifier: TraitIdentifier,
315-
) -> Result<(), CheckError> {
312+
pub fn add_implemented_trait(&mut self, trait_identifier: TraitIdentifier) {
316313
self.implemented_traits.insert(trait_identifier);
317-
Ok(())
318314
}
319315

320316
pub fn get_trait(

clarity/src/vm/analysis/type_checker/v2_1/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
18881888
self.add_memory(trait_identifier.name.len().into())?;
18891889
}
18901890
self.contract_context
1891-
.add_implemented_trait(trait_identifier.clone())?;
1891+
.add_implemented_trait(trait_identifier.clone());
18921892
}
18931893
};
18941894
Ok(Some(()))

clarity/src/vm/ast/definition_sorter/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl DefinitionSorter {
8787
)?;
8888

8989
let mut walker = GraphWalker::new();
90-
let sorted_indexes = walker.get_sorted_dependencies(&self.graph)?;
90+
let sorted_indexes = walker.get_sorted_dependencies(&self.graph);
9191

9292
if let Some(deps) = walker.get_cycling_dependencies(&self.graph, &sorted_indexes) {
9393
let functions_names = deps
@@ -461,13 +461,12 @@ impl GraphWalker {
461461
}
462462

463463
/// Depth-first search producing a post-order sort
464-
fn get_sorted_dependencies(&mut self, graph: &Graph) -> ParseResult<Vec<usize>> {
464+
fn get_sorted_dependencies(&mut self, graph: &Graph) -> Vec<usize> {
465465
let mut sorted_indexes = Vec::<usize>::new();
466466
for expr_index in 0..graph.nodes_count() {
467467
self.sort_dependencies_recursion(expr_index, graph, &mut sorted_indexes);
468468
}
469-
470-
Ok(sorted_indexes)
469+
sorted_indexes
471470
}
472471

473472
fn sort_dependencies_recursion(

clarity/src/vm/callables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl DefinedFunction {
294294
match result {
295295
Ok(r) => Ok(r),
296296
Err(e) => match e {
297-
Error::ShortReturn(v) => Ok(v.into()),
297+
Error::EarlyReturn(v) => Ok(v.into()),
298298
_ => Err(e),
299299
},
300300
}

clarity/src/vm/errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
pub use clarity_types::errors::{
18-
Error, IncomparableError, InterpreterResult, RuntimeErrorType, ShortReturnType, VmInternalError,
18+
EarlyReturnError, Error, IncomparableError, VmInternalError, InterpreterResult,
19+
RuntimeErrorType,
1920
};
2021

2122
pub use crate::vm::analysis::errors::{

0 commit comments

Comments
 (0)