Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: wrap_comments = true #5789

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
stacks-node = "run --package stacks-node --"
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module,wrap_comments=true"
clippy-stacks = "clippy -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings"

# Uncomment to improve performance slightly, at the cost of portability
Expand Down
1 change: 0 additions & 1 deletion clarity/src/vm/analysis/arithmetic_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ mod tests;
/// Cost-function defining contracts may not use contract-call,
/// any database operations, traits, or iterating operations (e.g., list
/// operations)
///
pub struct ArithmeticOnlyChecker<'a> {
clarity_version: &'a ClarityVersion,
}
Expand Down
13 changes: 8 additions & 5 deletions clarity/src/vm/analysis/arithmetic_checker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ use crate::vm::types::QualifiedContractIdentifier;
use crate::vm::variables::NativeVariables;
use crate::vm::ClarityVersion;

/// Checks whether or not a contract only contains arithmetic expressions (for example, defining a
/// map would not pass this check).
/// This check is useful in determining the validity of new potential cost functions.
/// Checks whether or not a contract only contains arithmetic expressions (for
/// example, defining a map would not pass this check).
/// This check is useful in determining the validity of new potential cost
/// functions.
fn arithmetic_check(
contract: &str,
version: ClarityVersion,
Expand Down Expand Up @@ -196,7 +197,8 @@ fn test_variables_fail_arithmetic_check_clarity2() {

#[test]
fn test_functions_clarity1() {
// Tests all functions against Clarity1 VM. Results should be different for Clarity1 vs Clarity2 functions.
// Tests all functions against Clarity1 VM. Results should be different for
// Clarity1 vs Clarity2 functions.
let tests = [
// Clarity1 functions.
("(define-private (foo) (at-block 0x0202020202020202020202020202020202020202020202020202020202020202 (+ 1 2)))",
Expand Down Expand Up @@ -335,7 +337,8 @@ fn test_functions_clarity1() {

#[test]
fn test_functions_clarity2() {
// Tests functions against Clarity2 VM. The Clarity1 functions should still cause an error.
// Tests functions against Clarity2 VM. The Clarity1 functions should still
// cause an error.
let tests = [
// Clarity2 functions.
(r#"(stx-transfer-memo? u100 'SPAXYA5XS51713FDTQ8H94EJ4V579CXMTRNBZKSF 'SPAXYA5XS51713FDTQ8H94EJ4V579CXMTRNBZKSF 0x010203)"#,
Expand Down
95 changes: 56 additions & 39 deletions clarity/src/vm/analysis/read_only_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ use crate::vm::ClarityVersion;
#[cfg(test)]
mod tests;

/// `ReadOnlyChecker` analyzes a contract to determine whether there are any violations
/// of read-only declarations. That is, a violating contract is one in which a function
/// that is declared as read-only actually attempts to modify chainstate.
/// `ReadOnlyChecker` analyzes a contract to determine whether there are any
/// violations of read-only declarations. That is, a violating contract is one
/// in which a function that is declared as read-only actually attempts to
/// modify chainstate.
///
/// A contract that does not violate its read-only declarations is called
/// *read-only correct*.
Expand Down Expand Up @@ -74,7 +75,8 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}
}

/// Checks each top-level expression in `contract_analysis.expressions` for read-only correctness.
/// Checks each top-level expression in `contract_analysis.expressions` for
/// read-only correctness.
///
/// Returns successfully iff this function is read-only correct.
///
Expand All @@ -97,8 +99,8 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}

/// Checks the top-level expression `expression` to determine whether it is
/// read-only compliant. `expression` maybe have composite structure that can be
/// parsed into multiple expressions.
/// read-only compliant. `expression` maybe have composite structure that
/// can be parsed into multiple expressions.
///
/// Returns successfully iff this function is read-only correct.
///
Expand All @@ -109,8 +111,9 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
use crate::vm::functions::define::DefineFunctionsParsed::*;
if let Some(define_type) = DefineFunctionsParsed::try_parse(expression)? {
match define_type {
// The *arguments* to Constant, PersistedVariable, FT defines must be checked to ensure that
// any *evaluated arguments* supplied to them are valid with respect to read-only requirements.
// The *arguments* to Constant, PersistedVariable, FT defines must be checked to
// ensure that any *evaluated arguments* supplied to them are
// valid with respect to read-only requirements.
Constant { value, .. } => {
self.check_read_only(value)?;
}
Expand All @@ -136,11 +139,13 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}
}
Map { .. } | NonFungibleToken { .. } | UnboundedFungibleToken { .. } => {
// No arguments to (define-map ...) or (define-non-fungible-token) or fungible tokens without
// No arguments to (define-map ...) or
// (define-non-fungible-token) or fungible tokens without
// max supplies are eval'ed.
}
Trait { .. } | UseTrait { .. } | ImplTrait { .. } => {
// No arguments to (use-trait ...), (define-trait ...). or (impl-trait) are eval'ed.
// No arguments to (use-trait ...), (define-trait ...). or
// (impl-trait) are eval'ed.
}
}
} else {
Expand All @@ -149,13 +154,14 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
Ok(())
}

/// Checks that a function with signature `signature` and body `body` is read-only.
/// Checks that a function with signature `signature` and body `body` is
/// read-only.
///
/// This is used to check the function definitions `PrivateFunction`, `PublicFunction`
/// and `ReadOnlyFunction`.
/// This is used to check the function definitions `PrivateFunction`,
/// `PublicFunction` and `ReadOnlyFunction`.
///
/// Returns a pair of 1) the function name defined, and 2) a `bool` indicating whether the function
/// is read-only.
/// Returns a pair of 1) the function name defined, and 2) a `bool`
/// indicating whether the function is read-only.
///
/// # Errors
/// - Contract parsing errors
Expand All @@ -179,8 +185,9 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
use crate::vm::functions::define::DefineFunctionsParsed::*;
if let Some(define_type) = DefineFunctionsParsed::try_parse(expr)? {
match define_type {
// The _arguments_ to Constant, PersistedVariable, FT defines must be checked to ensure that
// any _evaluated arguments_ supplied to them are valid with respect to read-only requirements.
// The _arguments_ to Constant, PersistedVariable, FT defines must be checked to
// ensure that any _evaluated arguments_ supplied to them are
// valid with respect to read-only requirements.
Constant { value, .. } => {
self.check_read_only(value)?;
}
Expand All @@ -204,10 +211,13 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}
}
Map { .. } | NonFungibleToken { .. } | UnboundedFungibleToken { .. } => {
// No arguments to (define-map ...) or (define-non-fungible-token) or fungible tokens without max supplies are eval'ed.
// No arguments to (define-map ...) or
// (define-non-fungible-token) or fungible tokens without
// max supplies are eval'ed.
}
Trait { .. } | UseTrait { .. } | ImplTrait { .. } => {
// No arguments to (use-trait ...), (define-trait ...). or (impl-trait) are eval'ed.
// No arguments to (use-trait ...), (define-trait ...). or
// (impl-trait) are eval'ed.
}
}
} else {
Expand All @@ -217,18 +227,19 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}

/// Checks the supplied symbolic expressions
/// (1) for whether or not they are valid with respect to read-only requirements.
/// (2) if valid, returns whether or not they are read only.
/// Note that because of (1), this function _cannot_ short-circuit on read-only.
/// (1) for whether or not they are valid with respect to read-only
/// requirements. (2) if valid, returns whether or not they are read
/// only. Note that because of (1), this function _cannot_ short-circuit
/// on read-only.
fn check_read_only(&mut self, expr: &SymbolicExpression) -> CheckResult<bool> {
match expr.expr {
AtomValue(_) | LiteralValue(_) | Atom(_) | TraitReference(_, _) | Field(_) => Ok(true),
List(ref expression) => self.check_expression_application_is_read_only(expression),
}
}

/// Checks each expression in `expressions` to determine whether each uses only
/// read-only operations.
/// Checks each expression in `expressions` to determine whether each uses
/// only read-only operations.
///
/// Returns `true` iff all expressions are read-only.
///
Expand All @@ -241,14 +252,16 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
let mut result = true;
for expression in expressions.iter() {
let expr_read_only = self.check_read_only(expression)?;
// Note: Don't return early on false, because a subsequent error should be returned.
// Note: Don't return early on false, because a subsequent error should be
// returned.
result = result && expr_read_only;
}
Ok(result)
}

/// Checks the native function application of the function named by the string `function`
/// to `args` to determine whether it is read-only compliant.
/// Checks the native function application of the function named by the
/// string `function` to `args` to determine whether it is read-only
/// compliant.
///
/// - Returns `None` if there is no native function named `function`.
/// - If there is such a native function, returns `true` iff this function
Expand Down Expand Up @@ -344,8 +357,8 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
// a special function. that check is performed by the type checker.
// we're pretty directly violating type checks in this recursive step:
// we're asking the read only checker to check whether a function application
// of the _mapping function_ onto the rest of the supplied arguments would be
// read-only or not.
// of the _mapping function_ onto the rest of the supplied arguments would
// be read-only or not.
self.check_expression_application_is_read_only(args)
}
Filter => {
Expand All @@ -359,8 +372,8 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
// a special function. that check is performed by the type checker.
// we're pretty directly violating type checks in this recursive step:
// we're asking the read only checker to check whether a function application
// of the _folding function_ onto the rest of the supplied arguments would be
// read-only or not.
// of the _folding function_ onto the rest of the supplied arguments would
// be read-only or not.
self.check_expression_application_is_read_only(args)
}
TupleCons => {
Expand Down Expand Up @@ -396,9 +409,10 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
)?
.is_some(),
SymbolicExpressionType::Atom(_trait_reference) => {
// Dynamic dispatch from a readonly-function can only be guaranteed at runtime,
// which would defeat granting a static readonly stamp.
// As such dynamic dispatch is currently forbidden.
// Dynamic dispatch from a readonly-function can only be guaranteed at
// runtime, which would defeat granting a static
// readonly stamp. As such dynamic dispatch is
// currently forbidden.
false
}
_ => return Err(CheckError::new(CheckErrors::ContractCallExpectName)),
Expand All @@ -410,16 +424,19 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
}
}

/// Checks the native and user-defined function applications implied by `expressions`.
/// Checks the native and user-defined function applications implied by
/// `expressions`.
///
/// The first expression is used as the function name, and the tail expressions are used as the arguments.
/// The first expression is used as the function name, and the tail
/// expressions are used as the arguments.
///
/// Returns `true` iff the function application is read-only.
///
/// # Errors
/// - `CheckErrors::NonFunctionApplication` if there is no first expression, or if the first
/// expression is not a `ClarityName`.
/// - `CheckErrors::UnknownFunction` if the first expression does not name a known function.
/// - `CheckErrors::NonFunctionApplication` if there is no first expression,
/// or if the first expression is not a `ClarityName`.
/// - `CheckErrors::UnknownFunction` if the first expression does not name a
/// known function.
fn check_expression_application_is_read_only(
&mut self,
expressions: &[SymbolicExpression],
Expand Down
3 changes: 2 additions & 1 deletion clarity/src/vm/analysis/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ fn test_bad_tuple_field_name() {
fn test_bad_function_name_2() {
// outside of the legal "implicit" tuple structures,
// things that look like ((value 100)) are evaluated as
// _function applications_, so this should error, since (value 100) isn't a function.
// _function applications_, so this should error, since (value 100) isn't a
// function.
let snippet = "(get 1 ((value 100)))";
let err = mem_type_check(snippet).unwrap_err();
println!("{}", err.diagnostic);
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/analysis/type_checker/v2_05/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ impl ContractContext {
}
}

/// This function consumes the ContractContext, and puts the relevant information
/// into the provided ContractAnalysis
/// This function consumes the ContractContext, and puts the relevant
/// information into the provided ContractAnalysis
pub fn into_contract_analysis(mut self, contract_analysis: &mut ContractAnalysis) {
for (name, function_type) in self.public_function_types.drain() {
contract_analysis.add_public_function(name, function_type);
Expand Down
12 changes: 8 additions & 4 deletions clarity/src/vm/analysis/type_checker/v2_05/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
Ok(())
}

// Type check an expression, with an expected_type that should _admit_ the expression.
// Type check an expression, with an expected_type that should _admit_ the
// expression.
pub fn type_check_expects(
&mut self,
expr: &SymbolicExpression,
Expand Down Expand Up @@ -634,7 +635,8 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
) -> CheckResult<(ClarityName, (TypeSignature, TypeSignature))> {
self.type_map.set_type(key_type, no_type())?;
self.type_map.set_type(value_type, no_type())?;
// should we set the type of the subexpressions of the signature to no-type as well?
// should we set the type of the subexpressions of the signature to no-type as
// well?

let key_type = TypeSignature::parse_type_repr(StacksEpochId::Epoch2_05, key_type, &mut ())
.map_err(|_| CheckErrors::BadMapTypeDefinition)?;
Expand All @@ -645,7 +647,8 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
Ok((map_name.clone(), (key_type, value_type)))
}

// Aaron: note, using lazy statics here would speed things up a bit and reduce clone()s
// Aaron: note, using lazy statics here would speed things up a bit and reduce
// clone()s
fn try_native_function_check(
&mut self,
function: &str,
Expand Down Expand Up @@ -811,7 +814,8 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
Ok((trait_name.clone(), trait_signature))
}

// Checks if an expression is a _define_ expression, and if so, typechecks it. Otherwise, it returns Ok(None)
// Checks if an expression is a _define_ expression, and if so, typechecks it.
// Otherwise, it returns Ok(None)
fn try_type_check_define(
&mut self,
expression: &SymbolicExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pub fn check_special_mint_asset(
.contract_context
.get_nft_type(asset_name)
.ok_or(CheckErrors::NoSuchNFT(asset_name.to_string()))?
.clone(); // this clone shouldn't be strictly necessary, but to use `type_check_expects` with this, it would have to be.
.clone(); // this clone shouldn't be strictly necessary, but to use `type_check_expects`
// with this, it would have to be.

runtime_cost(
ClarityCostFunction::AnalysisTypeLookup,
Expand Down Expand Up @@ -220,7 +221,8 @@ pub fn check_special_burn_asset(
.contract_context
.get_nft_type(asset_name)
.ok_or(CheckErrors::NoSuchNFT(asset_name.to_string()))?
.clone(); // this clone shouldn't be strictly necessary, but to use `type_check_expects` with this, it would have to be.
.clone(); // this clone shouldn't be strictly necessary, but to use `type_check_expects`
// with this, it would have to be.

runtime_cost(
ClarityCostFunction::AnalysisTypeLookup,
Expand Down
3 changes: 2 additions & 1 deletion clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,8 @@ fn test_response_inference() {
(let ((z (unwrap! x 1))) z)))
(check (ok 1))",
// tests top-level `unwrap!` type-check behavior
// (i.e., let it default to anything, since it will always cause a tx abort if the expectation is unmet.)
// (i.e., let it default to anything, since it will always cause a tx abort if the
// expectation is unmet.)
"(unwrap! (ok 2) true)",
];

Expand Down
13 changes: 8 additions & 5 deletions clarity/src/vm/analysis/type_checker/v2_1/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ use crate::vm::types::{FunctionType, QualifiedContractIdentifier, TraitIdentifie
use crate::vm::ClarityVersion;

enum TraitContext {
/// Traits stored in this context use the trait type-checking behavior defined in Clarity1
/// Traits stored in this context use the trait type-checking behavior
/// defined in Clarity1
Clarity1(HashMap<ClarityName, BTreeMap<ClarityName, FunctionSignature>>),
/// Traits stored in this context use the new trait type-checking behavior defined in Clarity2
/// Traits stored in this context use the new trait type-checking behavior
/// defined in Clarity2
Clarity2 {
/// Aliases for locally defined traits and traits imported with `use-trait`
/// Aliases for locally defined traits and traits imported with
/// `use-trait`
defined: HashSet<ClarityName>,
/// All traits which are defined or used in a contract
all: HashMap<TraitIdentifier, BTreeMap<ClarityName, FunctionSignature>>,
Expand Down Expand Up @@ -343,8 +346,8 @@ impl ContractContext {
}
}

/// This function consumes the ContractContext, and puts the relevant information
/// into the provided ContractAnalysis
/// This function consumes the ContractContext, and puts the relevant
/// information into the provided ContractAnalysis
pub fn into_contract_analysis(mut self, contract_analysis: &mut ContractAnalysis) {
for (name, function_type) in self.public_function_types.drain() {
contract_analysis.add_public_function(name, function_type);
Expand Down
Loading
Loading