Skip to content

Commit

Permalink
Merge branch 'next' into feat/4354-aggregate-key
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Feb 21, 2024
2 parents 055fad3 + 0b482e3 commit d2e6ad8
Show file tree
Hide file tree
Showing 99 changed files with 908 additions and 899 deletions.
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn type_check(

pub fn run_analysis(
contract_identifier: &QualifiedContractIdentifier,
expressions: &mut [SymbolicExpression],
expressions: &[SymbolicExpression],
analysis_db: &mut AnalysisDatabase,
save_contract: bool,
cost_tracker: LimitedCostTracker,
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/read_only_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a, 'b> ReadOnlyChecker<'a, 'b> {
body: &SymbolicExpression,
) -> CheckResult<(ClarityName, bool)> {
let function_name = signature
.get(0)
.first()
.ok_or(CheckErrors::DefineFunctionBadSignature)?
.match_atom()
.ok_or(CheckErrors::BadFunctionName)?;
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/trait_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TraitChecker {

pub fn run(
&mut self,
contract_analysis: &mut ContractAnalysis,
contract_analysis: &ContractAnalysis,
analysis_db: &mut AnalysisDatabase,
) -> CheckResult<()> {
for trait_identifier in &contract_analysis.implemented_traits {
Expand Down
6 changes: 3 additions & 3 deletions clarity/src/vm/analysis/type_checker/v2_05/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
}
}

pub fn run(&mut self, contract_analysis: &mut ContractAnalysis) -> CheckResult<()> {
pub fn run(&mut self, contract_analysis: &ContractAnalysis) -> CheckResult<()> {
// charge for the eventual storage cost of the analysis --
// it is linear in the size of the AST.
let mut size: u64 = 0;
Expand Down Expand Up @@ -562,7 +562,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
let function_name = function_name
.match_atom()
.ok_or(CheckErrors::BadFunctionName)?;
let mut args = parse_name_type_pairs::<()>(StacksEpochId::Epoch2_05, args, &mut ())
let args = parse_name_type_pairs::<()>(StacksEpochId::Epoch2_05, args, &mut ())
.map_err(|_| CheckErrors::BadSyntaxBinding)?;

if self.function_return_tracker.is_some() {
Expand Down Expand Up @@ -618,7 +618,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
self.function_return_tracker = None;

let func_args: Vec<FunctionArg> = args
.drain(..)
.into_iter()
.map(|(arg_name, arg_type)| FunctionArg::new(arg_type, arg_name))
.collect();

Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ fn check_special_equals(
) -> TypeResult {
check_arguments_at_least(1, args)?;

let mut arg_types = checker.type_check_all(args, context)?;
let arg_types = checker.type_check_all(args, context)?;

let mut arg_type = arg_types[0].clone();
for x_type in arg_types.drain(..) {
for x_type in arg_types.into_iter() {
analysis_typecheck_cost(checker, &x_type, &arg_type)?;
arg_type = TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, &x_type, &arg_type)
.map_err(|_| CheckErrors::TypeError(x_type, arg_type))?;
Expand Down
6 changes: 3 additions & 3 deletions clarity/src/vm/analysis/type_checker/v2_1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
}
}

pub fn run(&mut self, contract_analysis: &mut ContractAnalysis) -> CheckResult<()> {
pub fn run(&mut self, contract_analysis: &ContractAnalysis) -> CheckResult<()> {
// charge for the eventual storage cost of the analysis --
// it is linear in the size of the AST.
let mut size: u64 = 0;
Expand Down Expand Up @@ -1066,7 +1066,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
let function_name = function_name
.match_atom()
.ok_or(CheckErrors::BadFunctionName)?;
let mut args = parse_name_type_pairs::<()>(StacksEpochId::Epoch21, args, &mut ())
let args = parse_name_type_pairs::<()>(StacksEpochId::Epoch21, args, &mut ())
.map_err(|_| CheckErrors::BadSyntaxBinding)?;

if self.function_return_tracker.is_some() {
Expand Down Expand Up @@ -1123,7 +1123,7 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
self.function_return_tracker = None;

let func_args: Vec<FunctionArg> = args
.drain(..)
.into_iter()
.map(|(arg_name, arg_type)| FunctionArg::new(arg_type, arg_name))
.collect();

Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ fn check_special_equals(
) -> TypeResult {
check_arguments_at_least(1, args)?;

let mut arg_types = checker.type_check_all(args, context)?;
let arg_types = checker.type_check_all(args, context)?;

let mut arg_type = arg_types[0].clone();
for x_type in arg_types.drain(..) {
for x_type in arg_types.into_iter() {
analysis_typecheck_cost(checker, &x_type, &arg_type)?;
arg_type = TypeSignature::least_supertype(&StacksEpochId::Epoch21, &x_type, &arg_type)
.map_err(|_| CheckErrors::TypeError(x_type, arg_type))?;
Expand Down
16 changes: 8 additions & 8 deletions clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,8 @@ fn test_replace_at_buff() {
CheckErrors::IncorrectArgumentCount(3, 4),
CheckErrors::IncorrectArgumentCount(3, 2),
CheckErrors::TypeError(
SequenceType(BufferType(buff_len.clone())),
SequenceType(BufferType(buff_len_two.clone())),
SequenceType(BufferType(buff_len)),
SequenceType(BufferType(buff_len_two)),
),
];
for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) {
Expand Down Expand Up @@ -1746,8 +1746,8 @@ fn test_replace_at_ascii() {
CheckErrors::IncorrectArgumentCount(3, 4),
CheckErrors::IncorrectArgumentCount(3, 2),
CheckErrors::TypeError(
SequenceType(StringType(ASCII(buff_len.clone()))),
SequenceType(StringType(ASCII(buff_len_two.clone()))),
SequenceType(StringType(ASCII(buff_len))),
SequenceType(StringType(ASCII(buff_len_two))),
),
];
for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) {
Expand Down Expand Up @@ -1796,14 +1796,14 @@ fn test_replace_at_utf8() {
),
CheckErrors::TypeError(
SequenceType(StringType(UTF8(str_len.clone()))),
SequenceType(BufferType(buff_len.clone())),
SequenceType(BufferType(buff_len)),
),
CheckErrors::TypeError(UIntType, IntType),
CheckErrors::IncorrectArgumentCount(3, 4),
CheckErrors::IncorrectArgumentCount(3, 2),
CheckErrors::TypeError(
SequenceType(StringType(UTF8(str_len.clone()))),
SequenceType(StringType(UTF8(str_len_two.clone()))),
SequenceType(StringType(UTF8(str_len))),
SequenceType(StringType(UTF8(str_len_two))),
),
];
for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) {
Expand Down Expand Up @@ -3399,7 +3399,7 @@ fn test_trait_args() {
},
TraitIdentifier {
name: ClarityName::from("trait-bar"),
contract_identifier: contract_identifier.clone(),
contract_identifier: contract_identifier,
},
)];

Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ mod test {
{
assert_eq!(
fixed.args[1].signature,
TypeSignature::CallableType(CallableSubtype::Trait(trait_id.clone()))
TypeSignature::CallableType(CallableSubtype::Trait(trait_id))
);
} else {
panic!("Expected fixed function type");
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/ast/definition_sorter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ impl DefinitionSorter {
DefineFunctions::lookup_by_name(function_name)?;
Some(args)
}?;
let defined_name = match args.get(0)?.match_list() {
Some(list) => list.get(0)?,
let defined_name = match args.first()?.match_list() {
Some(list) => list.first()?,
_ => &args[0],
};
let tle_name = defined_name.match_atom()?;
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/ast/definition_sorter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn test_clarity_versions_definition_sorter(#[case] version: ClarityVersion) {}
fn run_scoped_parsing_helper(contract: &str, version: ClarityVersion) -> ParseResult<ContractAST> {
let contract_identifier = QualifiedContractIdentifier::transient();
let pre_expressions = parser::v1::parse(contract)?;
let mut contract_ast = ContractAST::new(contract_identifier.clone(), pre_expressions);
let mut contract_ast = ContractAST::new(contract_identifier, pre_expressions);
ExpressionIdentifier::run_pre_expression_pass(&mut contract_ast, version)?;
DefinitionSorter::run_pass(&mut contract_ast, &mut (), version)?;
Ok(contract_ast)
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/ast/parser/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ fn handle_expression(
}
}

pub fn parse_lexed(mut input: Vec<(LexItem, u32, u32)>) -> ParseResult<Vec<PreSymbolicExpression>> {
pub fn parse_lexed(input: Vec<(LexItem, u32, u32)>) -> ParseResult<Vec<PreSymbolicExpression>> {
let mut parse_stack = Vec::new();

let mut output_list = Vec::new();

for (item, line_pos, column_pos) in input.drain(..) {
for (item, line_pos, column_pos) in input.into_iter() {
match item {
LexItem::LeftParen => {
// start new list.
Expand Down
42 changes: 14 additions & 28 deletions clarity/src/vm/ast/parser/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<'a> Parser<'a> {
// Report an error, then skip this token
self.add_diagnostic(
ParseErrors::UnexpectedToken(token.token.clone()),
token.span.clone(),
token.span,
)?;
*whitespace = self.ignore_whitespace();
Ok(None)
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<'a> Parser<'a> {
// This indicates we have reached the end of the input.
// Create a placeholder value so that parsing can continue,
// then return.
let eof_span = last_token.span.clone();
let eof_span = last_token.span;

self.add_diagnostic(
ParseErrors::TupleValueExpected,
Expand Down Expand Up @@ -428,9 +428,7 @@ impl<'a> Parser<'a> {
return Ok(Some(e));
}
Token::Eof => (),
_ => {
self.add_diagnostic(ParseErrors::TupleCommaExpectedv2, token.span.clone())?
}
_ => self.add_diagnostic(ParseErrors::TupleCommaExpectedv2, token.span)?,
}

let mut comments = self.ignore_whitespace_and_comments();
Expand Down Expand Up @@ -463,7 +461,7 @@ impl<'a> Parser<'a> {
fn open_tuple(&mut self, lbrace: PlacedToken) -> ParseResult<SetupTupleResult> {
let mut open_tuple = OpenTuple {
nodes: vec![],
span: lbrace.span.clone(),
span: lbrace.span,
expects: OpenTupleStatus::ParseKey,
diagnostic_token: self.peek_next_token(),
};
Expand All @@ -474,10 +472,7 @@ impl<'a> Parser<'a> {
let token = self.peek_next_token();
match token.token {
Token::Comma => {
self.add_diagnostic(
ParseErrors::UnexpectedToken(token.token),
token.span.clone(),
)?;
self.add_diagnostic(ParseErrors::UnexpectedToken(token.token), token.span)?;
self.next_token();
}
Token::Rbrace => {
Expand Down Expand Up @@ -548,10 +543,7 @@ impl<'a> Parser<'a> {
}) => {
span.end_line = token_span.end_line;
span.end_column = token_span.end_column;
self.add_diagnostic(
ParseErrors::ExpectedContractIdentifier,
token_span.clone(),
)?;
self.add_diagnostic(ParseErrors::ExpectedContractIdentifier, token_span)?;
let mut placeholder = PreSymbolicExpression::placeholder(format!(
"'{}.{}",
principal,
Expand All @@ -561,7 +553,7 @@ impl<'a> Parser<'a> {
return Ok(placeholder);
}
None => {
self.add_diagnostic(ParseErrors::ExpectedContractIdentifier, dot.span.clone())?;
self.add_diagnostic(ParseErrors::ExpectedContractIdentifier, dot.span)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!("'{}.", principal));
placeholder.copy_span(&span);
Expand All @@ -572,7 +564,7 @@ impl<'a> Parser<'a> {
if name.len() > MAX_CONTRACT_NAME_LEN {
self.add_diagnostic(
ParseErrors::ContractNameTooLong(name.clone()),
contract_span.clone(),
contract_span,
)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!("'{}.{}", principal, name));
Expand All @@ -584,7 +576,7 @@ impl<'a> Parser<'a> {
Err(_) => {
self.add_diagnostic(
ParseErrors::IllegalContractName(name.clone()),
contract_span.clone(),
contract_span,
)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!("'{}.{}", principal, name));
Expand Down Expand Up @@ -639,10 +631,7 @@ impl<'a> Parser<'a> {
}
};
if name.len() > MAX_STRING_LEN {
self.add_diagnostic(
ParseErrors::NameTooLong(name.clone()),
trait_span.clone(),
)?;
self.add_diagnostic(ParseErrors::NameTooLong(name.clone()), trait_span)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!("'{}.{}", contract_id, name,));
placeholder.copy_span(&span);
Expand All @@ -653,7 +642,7 @@ impl<'a> Parser<'a> {
Err(_) => {
self.add_diagnostic(
ParseErrors::IllegalTraitName(name.clone()),
trait_span.clone(),
trait_span,
)?;
let mut placeholder = PreSymbolicExpression::placeholder(format!(
"'{}.{}",
Expand Down Expand Up @@ -728,7 +717,7 @@ impl<'a> Parser<'a> {
Err(_) => {
self.add_diagnostic(
ParseErrors::IllegalContractName(name.clone()),
contract_span.clone(),
contract_span,
)?;
let mut placeholder = PreSymbolicExpression::placeholder(format!(".{}", name));
placeholder.copy_span(&span);
Expand Down Expand Up @@ -775,7 +764,7 @@ impl<'a> Parser<'a> {
}
};
if name.len() > MAX_STRING_LEN {
self.add_diagnostic(ParseErrors::NameTooLong(name.clone()), trait_span.clone())?;
self.add_diagnostic(ParseErrors::NameTooLong(name.clone()), trait_span)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!(".{}.{}", contract_name, name));
placeholder.copy_span(&span);
Expand All @@ -784,10 +773,7 @@ impl<'a> Parser<'a> {
let trait_name = match ClarityName::try_from(name.clone()) {
Ok(id) => id,
Err(_) => {
self.add_diagnostic(
ParseErrors::IllegalTraitName(name.clone()),
trait_span.clone(),
)?;
self.add_diagnostic(ParseErrors::IllegalTraitName(name.clone()), trait_span)?;
let mut placeholder =
PreSymbolicExpression::placeholder(format!(".{}.{}", contract_name, name));
placeholder.copy_span(&span);
Expand Down
Loading

0 comments on commit d2e6ad8

Please sign in to comment.