Skip to content

Commit

Permalink
clippy and fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Dec 5, 2023
1 parent 60acf33 commit a759b88
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 142 deletions.
8 changes: 3 additions & 5 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,9 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
// If the type is a pointer then we use LOGD to log the data. First put the size into
// the data section, then add a LW to get it, then add a LOGD which uses it.
let log_ty = log_ty.get_pointee_type(self.context).unwrap();

// Slices arrive here as "ptr slice" because they are demoted. (see fn log_demotion)
let is_slice = log_ty.is_slice(self.context);
let is_slice = log_ty.is_slice(self.context);

if is_slice {
let ptr_reg = self.reg_seqr.next();
Expand Down Expand Up @@ -1301,7 +1301,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
});
} else {
let size_in_bytes = log_ty.size(self.context).in_bytes();

let size_reg = self.reg_seqr.next();
self.immediate_to_reg(
size_in_bytes,
Expand Down Expand Up @@ -1822,8 +1822,6 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
})
})
.ok_or_else(|| {
dbg!(value.with_context(self.context));
todo!();
CompileError::Internal(
"An attempt to get register for unknown Value.",
Span::dummy(),
Expand Down
6 changes: 2 additions & 4 deletions sway-core/src/decl_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::RwLock,
};

use sway_types::{ModuleId, Named, Spanned, Span};
use sway_types::{ModuleId, Named, Span, Spanned};

use crate::{
concurrent_slab::{ConcurrentSlab, ListDisplay},
Expand Down Expand Up @@ -313,9 +313,7 @@ impl DeclEngine {

pub fn get_structs_by_name(&self, name: &Ident) -> Option<DeclRef<DeclId<TyStructDecl>>> {
self.struct_slab.with_slice(|elems| {
let i = elems
.iter()
.position(|decl| decl.name() == name)?;
let i = elems.iter().position(|decl| decl.name() == name)?;

Some(DeclRef::new(name.clone(), DeclId::new(i), Span::dummy()))
})
Expand Down
250 changes: 132 additions & 118 deletions sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use sway_error::handler::{ErrorEmitted, Handler};
use sway_types::{Ident, Named, Span, Spanned};

use crate::{
decl_engine::{DeclEngineInsert, DeclRef, ReplaceFunctionImplementingType, DeclEngineGet},
decl_engine::{DeclEngineGet, DeclEngineInsert, DeclRef, ReplaceFunctionImplementingType},
language::{
parsed,
ty::{
self, TyAstNode, TyCodeBlock, TyDecl, TyExpression, TyFunctionDecl,
TyFunctionParameter, TyImplItem, TyIntrinsicFunctionKind, TyStructExpressionField, VariableMutability,
TyFunctionParameter, TyImplItem, VariableMutability,
},
CallPath, QualifiedCallPath,
},
Expand All @@ -35,140 +35,154 @@ fn auto_impl_abi_encode(handler: &Handler, ctx: &mut TypeCheckContext, decl: ty:
.te()
.insert(ctx.engines, TypeInfo::Tuple(vec![]), None);

let u64_type_id = ctx.engines.te().insert(
let struct_ref = ctx.engines().de().get(decl_ref.id());

let buffer_type_id = ctx.engines.te().insert(
ctx.engines,
TypeInfo::UnsignedInteger(sway_types::integer_bits::IntegerBits::SixtyFour),
TypeInfo::Custom {
qualified_call_path: QualifiedCallPath {
call_path: CallPath {
prefixes: vec![
Ident::new_no_span("core".into()),
Ident::new_no_span("codec".into()),
],
suffix: Ident::new_no_span("Buffer".into()),
is_absolute: true,
},
qualified_path_root: None,
},
type_arguments: None,
root_type_id: None,
},
None,
);

let struct_ref = ctx.engines().de().get(decl_ref.id());

let buffer_type_id = ctx.engines.te().insert(&ctx.engines, TypeInfo::Custom {
qualified_call_path: QualifiedCallPath {
call_path: CallPath {
prefixes: vec![
Ident::new_no_span("core".into()),
Ident::new_no_span("codec".into()),
],
suffix: Ident::new_no_span("Buffer".into()),
is_absolute: true
},
qualified_path_root: None
},
type_arguments: None,
root_type_id: None
}, None);
let buffer_type_id = ctx.resolve_type(handler,
buffer_type_id,
&Span::dummy(),
EnforceTypeArguments::No,
None
).unwrap();

let abi_encode_body = struct_ref.fields.iter()
let buffer_type_id = ctx
.resolve_type(
handler,
buffer_type_id,
&Span::dummy(),
EnforceTypeArguments::No,
None,
)
.unwrap();

let abi_encode_body = struct_ref
.fields
.iter()
.map(|x| {
let abi_encode_ref = ctx.find_items_for_type(handler, x.type_argument.type_id, &[
let abi_encode_ref = ctx
.find_items_for_type(
handler,
x.type_argument.type_id,
&[
// Ident::new_no_span("core".into()),
// Ident::new_no_span("codec".into()),
], &Ident::new_no_span("abi_encode".into())).unwrap().into_iter().next().unwrap();
],
&Ident::new_no_span("abi_encode".into()),
)
.unwrap()
.into_iter()
.next()
.unwrap();
let abi_encode_ref = match abi_encode_ref {
ty::TyTraitItem::Fn(f) => f,
ty::TyTraitItem::Constant(_) => todo!(),
ty::TyTraitItem::Type(_) => todo!(),
};

TyAstNode {
content: ty::TyAstNodeContent::Expression(
TyExpression {
expression: ty::TyExpressionVariant::FunctionApplication {
call_path: CallPath {
prefixes: vec![

],
suffix: Ident::new_no_span("abi_encode".into()),
is_absolute: false,
},
contract_call_params: HashMap::default(),
arguments: vec![
(
Ident::new_no_span("self".into()),
TyExpression {
expression: ty::TyExpressionVariant::StructFieldAccess {
prefix: Box::new(TyExpression {
expression: ty::TyExpressionVariant::VariableExpression {
name: Ident::new_no_span("self".into()),
span: Span::dummy(),
mutability: VariableMutability::Immutable,
call_path: None
content: ty::TyAstNodeContent::Expression(TyExpression {
expression: ty::TyExpressionVariant::FunctionApplication {
call_path: CallPath {
prefixes: vec![],
suffix: Ident::new_no_span("abi_encode".into()),
is_absolute: false,
},
contract_call_params: HashMap::default(),
arguments: vec![
(
Ident::new_no_span("self".into()),
TyExpression {
expression: ty::TyExpressionVariant::StructFieldAccess {
prefix: Box::new(TyExpression {
expression:
ty::TyExpressionVariant::VariableExpression {
name: Ident::new_no_span("self".into()),
span: Span::dummy(),
mutability: VariableMutability::Immutable,
call_path: None,
},
return_type: unit.clone(),
span: Span::dummy()
}),
field_to_access: x.clone(),
field_instantiation_span: Span::dummy(),
resolved_type_of_parent: type_id.clone()
},
return_type: unit,
span: Span::dummy()
}
),
(
Ident::new_no_span("buffer".into()),
TyExpression {
expression: ty::TyExpressionVariant::VariableExpression {
name: Ident::new_no_span("buffer".into()),
span: Span::dummy(),
mutability: VariableMutability::Mutable,
call_path: None
},
return_type: buffer_type_id,
span: Span::dummy()
}
)
],
fn_ref: abi_encode_ref,
selector: None,
type_binding: None,
call_path_typeid: Some(type_id),
deferred_monomorphization: ctx.defer_monomorphization()
},
return_type: unit,
span: Span::dummy()
}
),
return_type: unit,
span: Span::dummy(),
}),
field_to_access: x.clone(),
field_instantiation_span: Span::dummy(),
resolved_type_of_parent: type_id,
},
return_type: unit,
span: Span::dummy(),
},
),
(
Ident::new_no_span("buffer".into()),
TyExpression {
expression: ty::TyExpressionVariant::VariableExpression {
name: Ident::new_no_span("buffer".into()),
span: Span::dummy(),
mutability: VariableMutability::Mutable,
call_path: None,
},
return_type: buffer_type_id,
span: Span::dummy(),
},
),
],
fn_ref: abi_encode_ref,
selector: None,
type_binding: None,
call_path_typeid: Some(type_id),
deferred_monomorphization: ctx.defer_monomorphization(),
},
return_type: unit,
span: Span::dummy(),
}),
span: Span::dummy(),
}
}).collect::<Vec<_>>();
})
.collect::<Vec<_>>();

let abi_encode_impl = ctx.engines.de().insert(TyFunctionDecl {
name: Ident::new_no_span("abi_encode".into()),
body: TyCodeBlock {
contents: abi_encode_body,
whole_block_span: Span::dummy(),
},
parameters: vec![TyFunctionParameter {
name: Ident::new_no_span("self".into()),
is_reference: false,
is_mutable: false,
mutability_span: Span::dummy(),
type_argument: TypeArgument {
type_id,
initial_type_id: type_id,
span: Span::dummy(),
call_path_tree: None,
parameters: vec![
TyFunctionParameter {
name: Ident::new_no_span("self".into()),
is_reference: false,
is_mutable: false,
mutability_span: Span::dummy(),
type_argument: TypeArgument {
type_id,
initial_type_id: type_id,
span: Span::dummy(),
call_path_tree: None,
},
},
}, TyFunctionParameter {
name: Ident::new_no_span("buffer".into()),
is_reference: true,
is_mutable: true,
mutability_span: Span::dummy(),
type_argument: TypeArgument {
type_id: buffer_type_id,
initial_type_id: buffer_type_id,
span: Span::dummy(),
call_path_tree: None,
TyFunctionParameter {
name: Ident::new_no_span("buffer".into()),
is_reference: true,
is_mutable: true,
mutability_span: Span::dummy(),
type_argument: TypeArgument {
type_id: buffer_type_id,
initial_type_id: buffer_type_id,
span: Span::dummy(),
call_path_tree: None,
},
},
}],
],
implementing_type: None,
span: Span::dummy(),
call_path: CallPath {
Expand All @@ -191,7 +205,6 @@ fn auto_impl_abi_encode(handler: &Handler, ctx: &mut TypeCheckContext, decl: ty:
is_trait_method_dummy: false,
});


let _ = ctx.namespace.implemented_traits.insert(
handler,
CallPath {
Expand Down Expand Up @@ -434,12 +447,13 @@ impl TyDecl {
}
parsed::Declaration::StructDeclaration(decl) => {
let span = decl.span.clone();
let decl: ty::TyStructDecl = match ty::TyStructDecl::type_check(handler, ctx.by_ref(), decl) {
Ok(res) => res,
Err(err) => {
return Ok(ty::TyDecl::ErrorRecovery(span, err));
}
};
let decl: ty::TyStructDecl =
match ty::TyStructDecl::type_check(handler, ctx.by_ref(), decl) {
Ok(res) => res,
Err(err) => {
return Ok(ty::TyDecl::ErrorRecovery(span, err));
}
};
let call_path = decl.call_path.clone();
let decl: ty::TyDecl = decl_engine.insert(decl).into();

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ty::TyAstNode {
// dbg!(&ctx.namespace.name);
let import =
ctx.star_import(&star_import_handler, &path, a.is_absolute);

if import.is_ok() {
handler.append(star_import_handler);
import
Expand Down
16 changes: 7 additions & 9 deletions sway-core/src/semantic_analysis/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,13 @@ impl Items {
}

pub(crate) fn check_symbol(&self, name: &Ident) -> Result<&ty::TyDecl, CompileError> {
self.symbols
.get(name)
.ok_or_else(|| {
// dbg!(1);
CompileError::SymbolNotFound {
name: name.clone(),
span: name.span(),
}
})
self.symbols.get(name).ok_or_else(|| {
// dbg!(1);
CompileError::SymbolNotFound {
name: name.clone(),
span: name.span(),
}
})
}

pub fn get_items_for_type(&self, engines: &Engines, type_id: TypeId) -> Vec<ty::TyTraitItem> {
Expand Down
Loading

0 comments on commit a759b88

Please sign in to comment.