Skip to content

Commit

Permalink
Merge pull request #494 from g-r-a-n-t/fix-build
Browse files Browse the repository at this point in the history
fixed build
  • Loading branch information
g-r-a-n-t authored Jul 31, 2021
2 parents 9fc45b3 + 8f7079e commit 851a316
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 104 deletions.
4 changes: 2 additions & 2 deletions crates/analyzer/src/namespace/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ impl BlockScope {
loop {
parent = match parent {
BlockScopeParent::Block(ref scope) => {
last_block_scope = Rc::clone(&scope);
last_block_scope = Rc::clone(scope);
scope.borrow().parent.clone()
}
BlockScopeParent::Contract(ref scope) => {
return (Rc::clone(&scope), last_block_scope)
return (Rc::clone(scope), last_block_scope)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn bin_pow(left: &Type, right: &Type) -> Result<Type, BinaryOperationError> {
// side and under/overflow checks are based on that type.
if right.is_signed() {
Err(BinaryOperationError::RightIsSigned)
} else if left.can_hold(&right) {
} else if left.can_hold(right) {
Ok(Type::Base(Base::Numeric(left.to_owned())))
} else {
Err(BinaryOperationError::RightTooLarge)
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/traversal/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn contract_field(
stmt: &Node<fe::Field>,
) -> Result<(), FatalError> {
let fe::Field { name, typ, .. } = &stmt.kind;
let typ = types::type_desc(&Scope::Contract(Rc::clone(&scope)), context, &typ)?;
let typ = types::type_desc(&Scope::Contract(Rc::clone(&scope)), context, typ)?;

if let Err(AlreadyDefined) = scope.borrow_mut().add_field(&name.kind, typ) {
context.fancy_error(
Expand Down Expand Up @@ -206,7 +206,7 @@ fn event_field(
*is_idx,
(
name.kind.to_string(),
types::type_desc_fixed_size(&Scope::Contract(scope), context, &typ)?,
types::type_desc_fixed_size(&Scope::Contract(scope), context, typ)?,
),
))
}
6 changes: 3 additions & 3 deletions crates/analyzer/src/traversal/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn var_decl(
) -> Result<(), FatalError> {
if let fe::FuncStmt::VarDecl { target, typ, value } = &stmt.kind {
let declared_type =
types::type_desc_fixed_size(&Scope::Block(Rc::clone(&scope)), context, &typ)?;
types::type_desc_fixed_size(&Scope::Block(Rc::clone(&scope)), context, typ)?;

if let Some(value) = value {
let value_attributes = expressions::assignable_expr(
Expand All @@ -37,7 +37,7 @@ pub fn var_decl(
}
}

add_var(context, &scope, &target, declared_type.clone())?;
add_var(context, &scope, target, declared_type.clone())?;
context.add_declaration(stmt, declared_type);
return Ok(());
}
Expand All @@ -54,7 +54,7 @@ fn add_var(
) -> Result<(), FatalError> {
match (&target.kind, typ) {
(fe::VarDeclTarget::Name(name), typ) => {
if let Err(AlreadyDefined) = scope.borrow_mut().add_var(&name, typ) {
if let Err(AlreadyDefined) = scope.borrow_mut().add_var(name, typ) {
context.fancy_error(
"a variable with the same name already exists in this scope",
// TODO: figure out how to include the previously defined var
Expand Down
8 changes: 4 additions & 4 deletions crates/analyzer/src/traversal/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ fn expr_call_struct_constructor(
context,
&typ.name,
name_span,
&args,
args,
&typ.fields,
)?;

Expand Down Expand Up @@ -1052,7 +1052,7 @@ fn expr_call_value_attribute(
args: &Node<Vec<Node<fe::CallArg>>>,
) -> Result<ExpressionAttributes, FatalError> {
if let fe::Expr::Attribute { value, attr } = &func.kind {
let value_attributes = expr(Rc::clone(&scope), context, &value, None)?;
let value_attributes = expr(Rc::clone(&scope), context, value, None)?;

if let Type::Contract(contract) = &value_attributes.typ {
// We must ensure the expression is loaded onto the stack.
Expand Down Expand Up @@ -1431,7 +1431,7 @@ fn expr_attribute_call_type(
) -> Result<CallType, FatalError> {
if let fe::Expr::Attribute { value, attr } = &exp.kind {
if let fe::Expr::Name(name) = &value.kind {
match Object::from_str(&name) {
match Object::from_str(name) {
Ok(Object::Block) | Ok(Object::Chain) | Ok(Object::Msg) | Ok(Object::Tx) => {
context.fancy_error(
format!("no function `{}` exists on builtin `{}`", &attr.kind, &name),
Expand All @@ -1449,7 +1449,7 @@ fn expr_attribute_call_type(
Err(_) => {}
}

if let Some(typ) = scope.borrow().get_module_type_def(&name) {
if let Some(typ) = scope.borrow().get_module_type_def(name) {
return Ok(CallType::TypeAttribute {
typ,
func_name: attr.kind.to_string(),
Expand Down
16 changes: 8 additions & 8 deletions crates/analyzer/src/traversal/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn func_def(
let mut return_type = return_type_node
.as_ref()
.map(|typ| {
types::type_desc_fixed_size(&Scope::Block(Rc::clone(&function_scope)), context, &typ)
types::type_desc_fixed_size(&Scope::Block(Rc::clone(&function_scope)), context, typ)
})
.transpose()?
.unwrap_or_else(FixedSize::unit);
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn func_body(
// both returning (explicit) or not returning (implicit return) are valid syntax.
// If the return type is anything else, we do need to ensure that all code paths
// return or revert.
if !host_func_def.return_type.is_unit() && !all_paths_return_or_revert(&body) {
if !host_func_def.return_type.is_unit() && !all_paths_return_or_revert(body) {
context.fancy_error(
"function body is missing a return or revert statement",
vec![
Expand Down Expand Up @@ -173,8 +173,8 @@ fn all_paths_return_or_revert(block: &[Node<fe::FuncStmt>]) -> bool {
body,
or_else,
} => {
let body_returns = all_paths_return_or_revert(&body);
let or_else_returns = or_else.is_empty() || all_paths_return_or_revert(&or_else);
let body_returns = all_paths_return_or_revert(body);
let or_else_returns = or_else.is_empty() || all_paths_return_or_revert(or_else);
if body_returns && or_else_returns {
return true;
}
Expand All @@ -192,7 +192,7 @@ fn func_def_arg(
arg: &Node<fe::FunctionArg>,
) -> Result<(String, FixedSize), FatalError> {
let fe::FunctionArg { name, typ } = &arg.kind;
let typ = types::type_desc_fixed_size(&Scope::Block(Rc::clone(&scope)), context, &typ)?;
let typ = types::type_desc_fixed_size(&Scope::Block(Rc::clone(&scope)), context, typ)?;

if let Err(AlreadyDefined) = scope.borrow_mut().add_var(&name.kind, typ.clone()) {
context.fancy_error(
Expand Down Expand Up @@ -252,7 +252,7 @@ fn for_loop(
let body_scope = BlockScope::from_block_scope(BlockScopeType::Loop, Rc::clone(&scope));
// Make sure iter is in the function scope & it should be an array.

let iter_type = expressions::expr(Rc::clone(&scope), context, &iter, None)?.typ;
let iter_type = expressions::expr(Rc::clone(&scope), context, iter, None)?.typ;
let target_type = if let Type::Array(array) = iter_type {
FixedSize::Base(array.inner)
} else {
Expand Down Expand Up @@ -346,7 +346,7 @@ fn while_loop(
) -> Result<(), FatalError> {
match &stmt.kind {
fe::FuncStmt::While { test, body } => {
let test_type = expressions::expr(Rc::clone(&scope), context, &test, None)?.typ;
let test_type = expressions::expr(Rc::clone(&scope), context, test, None)?.typ;
if test_type != Type::Base(Base::Bool) {
context.type_error(
"`while` loop condition is not bool",
Expand Down Expand Up @@ -412,7 +412,7 @@ fn assert(
stmt: &Node<fe::FuncStmt>,
) -> Result<(), FatalError> {
if let fe::FuncStmt::Assert { test, msg } = &stmt.kind {
let test_type = expressions::expr(Rc::clone(&scope), context, &test, None)?.typ;
let test_type = expressions::expr(Rc::clone(&scope), context, test, None)?.typ;
if test_type != Type::Base(Base::Bool) {
context.type_error(
"`assert` condition is not bool",
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/traversal/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn module(context: &mut Context, module: &fe::Module) -> Result<(), FatalErr
}

for (contract, scope) in contracts.iter() {
contracts::contract_body(Rc::clone(&scope), context, contract)?
contracts::contract_body(Rc::clone(scope), context, contract)?
}

context.set_module(scope.into());
Expand All @@ -47,7 +47,7 @@ fn type_alias(
type_alias: &Node<fe::TypeAlias>,
) -> Result<(), FatalError> {
let fe::TypeAlias { name, typ } = &type_alias.kind;
let typ = types::type_desc(&Scope::Module(Rc::clone(&scope)), context, &typ)?;
let typ = types::type_desc(&Scope::Module(Rc::clone(&scope)), context, typ)?;

if let Err(AlreadyDefined) = scope.borrow_mut().add_type_def(&name.kind, typ) {
context.fancy_error(
Expand Down
10 changes: 5 additions & 5 deletions crates/analyzer/src/traversal/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn type_desc(
}
},
fe::TypeDesc::Array { typ, dimension } => {
if let Type::Base(base) = type_desc(scope, context, &typ)? {
if let Type::Base(base) = type_desc(scope, context, typ)? {
Type::Array(Array {
inner: base,
size: *dimension,
Expand All @@ -64,17 +64,17 @@ pub fn type_desc(
}
fe::TypeDesc::Generic { base, args } => match base.kind.as_str() {
"Map" => {
validate_arg_count(context, &base.kind, base.span, &args, 2);
validate_arg_count(context, &base.kind, base.span, args, 2);
if args.kind.len() < 2 {
return Err(FatalError::new());
}
match &args.kind[..2] {
[fe::GenericArg::TypeDesc(from), fe::GenericArg::TypeDesc(to)] => {
let key_type = type_desc(scope, context, &from)?;
let key_type = type_desc(scope, context, from)?;
if let Type::Base(base) = key_type {
Type::Map(Map {
key: base,
value: Box::new(type_desc(scope, context, &to)?),
value: Box::new(type_desc(scope, context, to)?),
})
} else {
context.error(
Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn type_desc(
items: Vec1::try_from_vec(
items
.iter()
.map(|typ| type_desc_fixed_size(scope, context, &typ))
.map(|typ| type_desc_fixed_size(scope, context, typ))
.collect::<Result<_, _>>()?,
)
.expect("tuple is empty"),
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn print_diagnostics(diagnostics: &[Diagnostic], files: &FileStore) {
let config = term::Config::default();

for diag in diagnostics {
term::emit(&mut buffer, &config, files, &diag).unwrap();
term::emit(&mut buffer, &config, files, diag).unwrap();
}
// If we use `writer` here, the output won't be captured by rust's test system.
eprintln!("{}", std::str::from_utf8(buffer.as_slice()).unwrap());
Expand All @@ -65,7 +65,7 @@ pub fn diagnostics_string(diagnostics: &[Diagnostic], files: &FileStore) -> Stri
let config = term::Config::default();

for diag in diagnostics {
term::emit(&mut buffer, &config, files, &diag).expect("failed to emit diagnostic");
term::emit(&mut buffer, &config, files, diag).expect("failed to emit diagnostic");
}
std::str::from_utf8(buffer.as_slice()).unwrap().to_string()
}
4 changes: 2 additions & 2 deletions crates/common/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct SourceFileId(pub u128);
impl SourceFile {
pub fn new(name: &str, content: &str) -> Self {
let hash = keccak::full_as_bytes(content.as_bytes());
let line_starts = cs::files::line_starts(&content).collect();
let line_starts = cs::files::line_starts(content).collect();
Self {
id: SourceFileId(u128::from_be_bytes(hash[..16].try_into().unwrap())),
name: name.to_string(),
Expand Down Expand Up @@ -86,7 +86,7 @@ impl FileStore {
}

pub fn load_file(&mut self, path: &str) -> io::Result<(String, SourceFileId)> {
let content = self.loader.load_file(&Path::new(&path))?;
let content = self.loader.load_file(Path::new(&path))?;
let id = self.add_file(path, &content);
Ok((content, id))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> Literal<'a> {

/// Parse the numeric literal to `T`.
pub fn parse<T: num_traits::Num>(&self) -> Result<T, T::FromStrRadixErr> {
T::from_str_radix(&self.num, self.radix.as_num())
T::from_str_radix(self.num, self.radix.as_num())
}

/// Returns radix of the numeric literal.
Expand Down
2 changes: 1 addition & 1 deletion crates/fe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn main() {
std::process::exit(1)
}
};
match write_compiled_module(compiled_module, &content, &targets, &output_dir, overwrite) {
match write_compiled_module(compiled_module, &content, &targets, output_dir, overwrite) {
Ok(_) => println!("Compiled {}. Outputs in `{}`", input_file, output_dir),
Err(err) => {
eprintln!(
Expand Down
2 changes: 1 addition & 1 deletion crates/lowering/src/mappers/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn build_type_desc(module: &ModuleContext, typ: &FixedSize) -> fe::TypeDesc {
typ: build_type_desc(module, &array.inner.into()).into_boxed_node(),
},
FixedSize::Tuple(tuple) => fe::TypeDesc::Base {
base: names::tuple_struct_name(&tuple),
base: names::tuple_struct_name(tuple),
},
FixedSize::String(string) => fe::TypeDesc::Generic {
base: Node::new("String".to_string(), Span::zero()),
Expand Down
8 changes: 4 additions & 4 deletions crates/lowering/tests/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn lower_file(src: &str, id: SourceFileId, files: &FileStore) -> fe::Module {
}

fn analyze(module: &fe::Module, id: SourceFileId, files: &FileStore) -> Context {
match fe_analyzer::analyze(&module, id) {
match fe_analyzer::analyze(module, id) {
Ok(context) => context,
Err(AnalyzerError(diagnostics)) => {
print_diagnostics(&diagnostics, &files);
print_diagnostics(&diagnostics, files);
panic!("analysis failed");
}
}
Expand Down Expand Up @@ -66,8 +66,8 @@ fn test_lowering(fixture: &str) {
let expected_lowered = test_files::fixture(&path);
let el_id = files.add_file(&path, expected_lowered);

let expected_lowered_ast = parse_file(&expected_lowered, el_id, &files);
let actual_lowered_ast = lower_file(&src, src_id, &files);
let expected_lowered_ast = parse_file(expected_lowered, el_id, &files);
let actual_lowered_ast = lower_file(src, src_id, &files);

assert_strings_eq!(
replace_spans(to_ron_string_pretty(&expected_lowered_ast).unwrap()),
Expand Down
10 changes: 5 additions & 5 deletions crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl ContractHarness {
) -> Option<ethabi::Token> {
let function = &self.abi.functions[name][0];

match self.capture_call(executor, name, &input) {
match self.capture_call(executor, name, input) {
evm::Capture::Exit((ExitReason::Succeed(_), output)) => function
.decode_output(&output)
.unwrap_or_else(|_| panic!("unable to decode output of {}: {:?}", name, &output))
Expand Down Expand Up @@ -245,7 +245,7 @@ pub fn deploy_contract(
let mut files = FileStore::new();
let id = files.add_file(fixture, src);

let compiled_module = match driver::compile(&src, id, true, true) {
let compiled_module = match driver::compile(src, id, true, true) {
Ok(module) => module,
Err(error) => {
fe_common::diagnostics::print_diagnostics(&error.0, &files);
Expand Down Expand Up @@ -382,7 +382,7 @@ pub fn compile_solidity_contract(
}
}
"#;
let solc_config = solc_config.replace("{src}", &solidity_src);
let solc_config = solc_config.replace("{src}", solidity_src);

let raw_output = solc::compile(&solc_config);

Expand Down Expand Up @@ -448,7 +448,7 @@ pub fn load_contract(address: H160, fixture: &str, contract_name: &str) -> Contr
let mut files = FileStore::new();
let src = test_files::fixture(fixture);
let id = files.add_file(fixture, src);
let compiled_module = match driver::compile(&src, id, true, true) {
let compiled_module = match driver::compile(src, id, true, true) {
Ok(module) => module,
Err(err) => {
print_diagnostics(&err.0, &files);
Expand Down Expand Up @@ -526,7 +526,7 @@ impl Runtime {

#[cfg(feature = "solc-backend")]
pub fn execute(&self, executor: &mut Executor) -> ExecutionOutput {
let (exit_reason, data) = execute_runtime_functions(executor, &self);
let (exit_reason, data) = execute_runtime_functions(executor, self);
ExecutionOutput::new(exit_reason, data)
}
}
Expand Down
Loading

0 comments on commit 851a316

Please sign in to comment.