Skip to content

Commit b769284

Browse files
Merge pull request #6913 from federico-stacks/aac/static-expect-to-unrechable
aac: convert static check "expectable" errors to "unrechable"
2 parents 93284cc + d642759 commit b769284

File tree

15 files changed

+104
-134
lines changed

15 files changed

+104
-134
lines changed

clarity-types/src/errors/analysis.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,8 @@ pub enum StaticCheckErrorKind {
249249
/// Supertype (i.e. common denominator between two types) exceeds the maximum allowed size or complexity.
250250
SupertypeTooLarge,
251251

252-
// Unexpected interpreter behavior
253252
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
254-
ExpectsRejectable(String),
255-
// Unexpected interpreter behavior
256-
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
257-
/// This error does NOT indicate a transaction would invalidate a block if included.
258-
ExpectsAcceptable(String),
253+
Unreachable(String),
259254

260255
// Match expression errors
261256
/// Invalid syntax in an `option` match expression.
@@ -660,7 +655,7 @@ impl StaticCheckErrorKind {
660655
pub fn rejectable_in_epoch(&self, epoch: StacksEpochId) -> bool {
661656
match self {
662657
StaticCheckErrorKind::SupertypeTooLarge => epoch.rejects_supertype_too_large(),
663-
StaticCheckErrorKind::ExpectsRejectable(_) => true,
658+
StaticCheckErrorKind::Unreachable(_) => true,
664659
_ => false,
665660
}
666661
}
@@ -724,22 +719,20 @@ impl From<ClarityTypeError> for StaticCheckErrorKind {
724719
| ClarityTypeError::TypeMismatchValue(_, _)
725720
| ClarityTypeError::ResponseTypeMismatch { .. }
726721
| ClarityTypeError::InvalidAsciiCharacter(_)
727-
| ClarityTypeError::InvalidUtf8Encoding => Self::ExpectsAcceptable(format!(
728-
"Unexpected error type during static analysis: {err}"
729-
)),
730-
ClarityTypeError::InvariantViolation(_)
731-
| ClarityTypeError::InvalidPrincipalVersion(_) => Self::ExpectsRejectable(format!(
722+
| ClarityTypeError::InvalidUtf8Encoding
723+
| ClarityTypeError::InvariantViolation(_)
724+
| ClarityTypeError::InvalidPrincipalVersion(_) => Self::Unreachable(format!(
732725
"Unexpected error type during static analysis: {err}"
733726
)),
734727
ClarityTypeError::CouldNotDetermineSerializationType => {
735728
Self::CouldNotDetermineSerializationType
736729
}
737730
ClarityTypeError::CouldNotDetermineType => Self::CouldNotDetermineType,
738731
ClarityTypeError::UnsupportedTypeInEpoch(ty, epoch) => {
739-
Self::ExpectsRejectable(format!("{ty} should not be used in {epoch}"))
732+
Self::Unreachable(format!("{ty} should not be used in {epoch}"))
740733
}
741734
ClarityTypeError::UnsupportedEpoch(epoch) => {
742-
Self::ExpectsRejectable(format!("{epoch} is not supported"))
735+
Self::Unreachable(format!("{epoch} is not supported"))
743736
}
744737
}
745738
}
@@ -875,10 +868,10 @@ impl From<CostErrors> for StaticCheckErrorKind {
875868
CostErrors::CostContractLoadFailure => {
876869
StaticCheckErrorKind::CostComputationFailed("Failed to load cost contract".into())
877870
}
878-
CostErrors::InterpreterFailure => StaticCheckErrorKind::ExpectsRejectable(
871+
CostErrors::InterpreterFailure => StaticCheckErrorKind::Unreachable(
879872
"Unexpected interpreter failure in cost computation".into(),
880873
),
881-
CostErrors::Expect(s) => StaticCheckErrorKind::ExpectsRejectable(s),
874+
CostErrors::Expect(s) => StaticCheckErrorKind::Unreachable(s),
882875
CostErrors::ExecutionTimeExpired => StaticCheckErrorKind::ExecutionTimeExpired,
883876
}
884877
}
@@ -1101,8 +1094,7 @@ impl DiagnosableError for StaticCheckErrorKind {
11011094
fn message(&self) -> String {
11021095
match &self {
11031096
StaticCheckErrorKind::SupertypeTooLarge => "supertype of two types is too large".into(),
1104-
StaticCheckErrorKind::ExpectsRejectable(s) => format!("unexpected and unacceptable interpreter behavior: {s}"),
1105-
StaticCheckErrorKind::ExpectsAcceptable(s) => format!("unexpected but acceptable interpreter behaviour: {s}"),
1097+
StaticCheckErrorKind::Unreachable(s) => format!("unexpected and unacceptable interpreter behavior: {s}"),
11061098
StaticCheckErrorKind::BadMatchOptionSyntax(source) =>
11071099
format!("match on a optional type uses the following syntax: (match input some-name if-some-expression if-none-expression). Caused by: {}",
11081100
source.message()),

clarity/src/vm/analysis/analysis_db.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ impl<'a> AnalysisDatabase<'a> {
5151
self.begin();
5252
let result = f(self).or_else(|e| {
5353
self.roll_back()
54-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
54+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("{e:?}")))?;
5555
Err(e)
5656
})?;
5757
self.commit()
58-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
58+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("{e:?}")))?;
5959
Ok(result)
6060
}
6161

@@ -66,13 +66,13 @@ impl<'a> AnalysisDatabase<'a> {
6666
pub fn commit(&mut self) -> Result<(), StaticCheckError> {
6767
self.store
6868
.commit()
69-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")).into())
69+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("{e:?}")).into())
7070
}
7171

7272
pub fn roll_back(&mut self) -> Result<(), StaticCheckError> {
7373
self.store
7474
.rollback()
75-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")).into())
75+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("{e:?}")).into())
7676
}
7777

7878
pub fn storage_key() -> &'static str {
@@ -108,8 +108,7 @@ impl<'a> AnalysisDatabase<'a> {
108108
.flatten()
109109
.map(|x| {
110110
ContractAnalysis::deserialize(&x).map_err(|_| {
111-
StaticCheckErrorKind::ExpectsRejectable("Bad data deserialized from DB".into())
112-
.into()
111+
StaticCheckErrorKind::Unreachable("Bad data deserialized from DB".into()).into()
113112
})
114113
})
115114
.transpose()
@@ -129,7 +128,7 @@ impl<'a> AnalysisDatabase<'a> {
129128
.flatten()
130129
.map(|x| {
131130
ContractAnalysis::deserialize(&x).map_err(|_| {
132-
StaticCheckErrorKind::ExpectsRejectable("Bad data deserialized from DB".into())
131+
StaticCheckErrorKind::Unreachable("Bad data deserialized from DB".into())
133132
})
134133
})
135134
.transpose()?
@@ -154,7 +153,7 @@ impl<'a> AnalysisDatabase<'a> {
154153

155154
self.store
156155
.insert_metadata(contract_identifier, key, &contract.serialize())
157-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
156+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("{e:?}")))?;
158157
Ok(())
159158
}
160159

clarity/src/vm/analysis/contract_interface_builder/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl ContractInterfaceFunction {
278278
FunctionType::Fixed(FixedFunction { returns, .. }) => {
279279
ContractInterfaceAtomType::from_type_signature(returns)
280280
}
281-
_ => return Err(StaticCheckErrorKind::ExpectsRejectable(
281+
_ => return Err(StaticCheckErrorKind::Unreachable(
282282
"Contract functions should only have fixed function return types!"
283283
.into(),
284284
)
@@ -290,7 +290,7 @@ impl ContractInterfaceFunction {
290290
ContractInterfaceFunctionArg::from_function_args(args)
291291
}
292292
_ => {
293-
return Err(StaticCheckErrorKind::ExpectsRejectable(
293+
return Err(StaticCheckErrorKind::Unreachable(
294294
"Contract functions should only have fixed function arguments!"
295295
.into(),
296296
)
@@ -402,7 +402,7 @@ impl ContractInterface {
402402

403403
pub fn serialize(&self) -> Result<String, StaticCheckError> {
404404
serde_json::to_string(self).map_err(|_| {
405-
StaticCheckErrorKind::ExpectsRejectable("Failed to serialize contract interface".into())
405+
StaticCheckErrorKind::Unreachable("Failed to serialize contract interface".into())
406406
.into()
407407
})
408408
}

clarity/src/vm/analysis/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn mem_type_check(
5757
) -> Result<(Option<TypeSignature>, ContractAnalysis), StaticCheckError> {
5858
let contract_identifier = QualifiedContractIdentifier::transient();
5959
let contract = build_ast(&contract_identifier, snippet, &mut (), version, epoch)
60-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("Failed to build AST: {e}")))?
60+
.map_err(|e| StaticCheckErrorKind::Unreachable(format!("Failed to build AST: {e}")))?
6161
.expressions;
6262

6363
let mut marf = MemoryBackingStore::new();
@@ -79,11 +79,9 @@ pub fn mem_type_check(
7979
let first_type = x
8080
.type_map
8181
.as_ref()
82-
.ok_or_else(|| {
83-
StaticCheckErrorKind::ExpectsRejectable("Should be non-empty".into())
84-
})?
82+
.ok_or_else(|| StaticCheckErrorKind::Unreachable("Should be non-empty".into()))?
8583
.get_type_expected(x.expressions.last().ok_or_else(|| {
86-
StaticCheckErrorKind::ExpectsRejectable("Should be non-empty".into())
84+
StaticCheckErrorKind::Unreachable("Should be non-empty".into())
8785
})?)
8886
.cloned();
8987
Ok((first_type, x))
@@ -155,7 +153,7 @@ pub fn run_analysis(
155153
TypeChecker2_1::run_pass(&epoch, &mut contract_analysis, db, build_type_map)
156154
}
157155
StacksEpochId::Epoch10 => {
158-
return Err(StaticCheckErrorKind::ExpectsRejectable(
156+
return Err(StaticCheckErrorKind::Unreachable(
159157
"Epoch 1.0 is not a valid epoch for analysis".into(),
160158
)
161159
.into());

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ impl FunctionType {
4949
| StacksEpochId::Epoch32
5050
| StacksEpochId::Epoch33
5151
| StacksEpochId::Epoch34 => self.check_args_2_1(accounting, args, clarity_version),
52-
StacksEpochId::Epoch10 => Err(StaticCheckErrorKind::ExpectsRejectable(
53-
"Epoch10 is not supported".into(),
54-
)
55-
.into()),
52+
StacksEpochId::Epoch10 => {
53+
Err(StaticCheckErrorKind::Unreachable("Epoch10 is not supported".into()).into())
54+
}
5655
}
5756
}
5857

@@ -79,10 +78,9 @@ impl FunctionType {
7978
| StacksEpochId::Epoch34 => {
8079
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
8180
}
82-
StacksEpochId::Epoch10 => Err(StaticCheckErrorKind::ExpectsRejectable(
83-
"Epoch10 is not supported".into(),
84-
)
85-
.into()),
81+
StacksEpochId::Epoch10 => {
82+
Err(StaticCheckErrorKind::Unreachable("Epoch10 is not supported".into()).into())
83+
}
8684
}
8785
}
8886
}

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl FunctionType {
249249

250250
Ok(TypeSignature::BoolType)
251251
}
252-
FunctionType::Binary(_, _, _) => Err(StaticCheckErrorKind::ExpectsRejectable(
252+
FunctionType::Binary(_, _, _) => Err(StaticCheckErrorKind::Unreachable(
253253
"Binary type should not be reached in 2.05".into(),
254254
)
255255
.into()),
@@ -264,10 +264,9 @@ impl FunctionType {
264264
let (expected_args, returns) = match self {
265265
FunctionType::Fixed(FixedFunction { args, returns }) => (args, returns),
266266
_ => {
267-
return Err(StaticCheckErrorKind::ExpectsRejectable(
268-
"Unexpected function type".into(),
269-
)
270-
.into());
267+
return Err(
268+
StaticCheckErrorKind::Unreachable("Unexpected function type".into()).into(),
269+
);
271270
}
272271
};
273272
check_argument_count(expected_args.len(), func_args)?;
@@ -340,13 +339,13 @@ fn type_reserved_variable(variable_name: &str) -> Result<Option<TypeSignature>,
340339
BlockHeight => TypeSignature::UIntType,
341340
BurnBlockHeight => TypeSignature::UIntType,
342341
NativeNone => TypeSignature::new_option(no_type())
343-
.map_err(|_| StaticCheckErrorKind::ExpectsRejectable("Bad constructor".into()))?,
342+
.map_err(|_| StaticCheckErrorKind::Unreachable("Bad constructor".into()))?,
344343
NativeTrue => TypeSignature::BoolType,
345344
NativeFalse => TypeSignature::BoolType,
346345
TotalLiquidMicroSTX => TypeSignature::UIntType,
347346
Regtest => TypeSignature::BoolType,
348347
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight | StacksBlockTime | CurrentContract => {
349-
return Err(StaticCheckErrorKind::ExpectsRejectable(
348+
return Err(StaticCheckErrorKind::Unreachable(
350349
"tx-sponsor, mainnet, chain-id, stacks-block-height, tenure-height, stacks-block-time, and current-contract should not reach here in 2.05".into(),
351350
)
352351
.into())
@@ -437,9 +436,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
437436
}
438437
Err(e) => Err(e),
439438
})?
440-
.ok_or_else(|| {
441-
StaticCheckErrorKind::ExpectsRejectable("Expected a depth result".into())
442-
})?;
439+
.ok_or_else(|| StaticCheckErrorKind::Unreachable("Expected a depth result".into()))?;
443440
}
444441

445442
runtime_cost(ClarityCostFunction::AnalysisStorage, self, size)?;
@@ -610,7 +607,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
610607
)?;
611608

612609
if self.function_return_tracker.is_some() {
613-
return Err(StaticCheckErrorKind::ExpectsRejectable(
610+
return Err(StaticCheckErrorKind::Unreachable(
614611
"Interpreter error: Previous function define left dirty typecheck state.".into(),
615612
)
616613
.into());

0 commit comments

Comments
 (0)