Skip to content

Commit

Permalink
Remove more unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Jun 1, 2022
1 parent 93db9cb commit ecfccc5
Show file tree
Hide file tree
Showing 42 changed files with 210 additions and 333 deletions.
4 changes: 0 additions & 4 deletions crates/analyzer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,6 @@ pub struct FunctionBody {
pub string_literals: IndexSet<SmolStr>, // for yulgen
// Map lhs of variable declaration to type.
pub var_types: IndexMap<NodeId, Type>,

// This is the id of the VarDecl TypeDesc node
// TODO: Do we really need this?
pub var_decl_types: IndexMap<NodeId, Type>,
pub calls: IndexMap<NodeId, CallType>,
pub spans: HashMap<NodeId, Span>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/db/queries/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub fn function_dependency_graph(db: &dyn AnalyzerDb, function: FunctionId) -> D
.values()
.map(|event| (root, Item::Event(*event), DepLocality::Local)),
);
directs.extend(body.var_decl_types.values().filter_map(|typ| match typ {
directs.extend(body.var_types.values().filter_map(|typ| match typ {
Type::Contract(Contract { id, .. }) => Some((
root,
Item::Type(TypeDef::Contract(*id)),
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/db/queries/ingots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn ingot_modules(db: &dyn AnalyzerDb, ingot: IngotId) -> Rc<[ModuleId]> {
.iter()
.flat_map(|(_file, path)| {
path.strip_prefix(&file_path_prefix.as_str())
.unwrap_or_else(|_| path)
.unwrap_or(path)
.ancestors()
.skip(1) // first elem of .ancestors() is the path itself
})
Expand All @@ -52,7 +52,7 @@ pub fn ingot_modules(db: &dyn AnalyzerDb, ingot: IngotId) -> Rc<[ModuleId]> {
.iter()
.map(|(_file, path)| {
path.strip_prefix(&file_path_prefix.as_str())
.unwrap_or_else(|_| path)
.unwrap_or(path)
.as_str()
.trim_end_matches(".fe")
.into()
Expand Down
7 changes: 0 additions & 7 deletions crates/analyzer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ pub struct AlreadyDefined;
#[derive(Debug)]
pub struct CannotMove;

/// Error indicating that a [`Type`] does not have a fixed size.
#[derive(Debug)]
pub struct NotFixedSize;

/// Errors that can result from indexing
#[derive(Debug, PartialEq)]
pub enum IndexingError {
Expand All @@ -145,9 +141,6 @@ pub enum BinaryOperationError {
NotEqualAndUnsigned,
}

#[derive(Debug)]
pub struct AnalyzerError(pub Vec<Diagnostic>);

impl From<TypeError> for FatalError {
fn from(err: TypeError) -> Self {
Self::new(err.0)
Expand Down
31 changes: 0 additions & 31 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ impl Item {
}
}

/// Downcast utility function
pub fn as_contract(&self) -> Option<ContractId> {
match self {
Item::Type(TypeDef::Contract(id)) => Some(*id),
_ => None,
}
}

pub fn sink_diagnostics(&self, db: &dyn AnalyzerDb, sink: &mut impl DiagnosticSink) {
match self {
Item::Type(id) => id.sink_diagnostics(db, sink),
Expand Down Expand Up @@ -641,11 +633,6 @@ impl ModuleId {
items
}

/// All structs, including duplicatecrates/analyzer/src/db.rss
pub fn all_structs(&self, db: &dyn AnalyzerDb) -> Rc<[StructId]> {
db.module_structs(*self)
}

/// All module constants.
pub fn all_constants(&self, db: &dyn AnalyzerDb) -> Rc<Vec<ModuleConstantId>> {
db.module_constants(*self)
Expand Down Expand Up @@ -978,11 +965,6 @@ impl ContractId {
db.contract_public_function_map(*self)
}

/// Get a function that takes self by its name.
pub fn self_function(&self, db: &dyn AnalyzerDb, name: &str) -> Option<FunctionId> {
self.function(db, name).filter(|f| f.takes_self(db))
}

/// Lookup an event by name.
pub fn event(&self, db: &dyn AnalyzerDb, name: &str) -> Option<EventId> {
self.events(db).get(name).copied()
Expand Down Expand Up @@ -1196,12 +1178,6 @@ impl Class {
}
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum MemberFunction {
BuiltIn(builtins::ValueMethod),
Function(FunctionId),
}

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Struct {
pub ast: Node<ast::Struct>,
Expand Down Expand Up @@ -1256,10 +1232,6 @@ impl StructId {
matches!(self.field_type(db, name), Some(Ok(types::Type::Base(_))))
}

pub fn field_index(&self, db: &dyn AnalyzerDb, name: &str) -> Option<usize> {
self.fields(db).get_index_of(name)
}

pub fn has_complex_fields(&self, db: &dyn AnalyzerDb) -> bool {
self.fields(db)
.iter()
Expand All @@ -1280,9 +1252,6 @@ impl StructId {
pub fn function(&self, db: &dyn AnalyzerDb, name: &str) -> Option<FunctionId> {
self.functions(db).get(name).copied()
}
pub fn self_function(&self, db: &dyn AnalyzerDb, name: &str) -> Option<FunctionId> {
self.function(db, name).filter(|f| f.takes_self(db))
}
pub fn parent(&self, db: &dyn AnalyzerDb) -> Item {
Item::Module(self.data(db).module)
}
Expand Down
14 changes: 0 additions & 14 deletions crates/analyzer/src/namespace/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,6 @@ impl<'a> FunctionScope<'a> {
.expect_none("emit statement attributes already exist");
}

/// Attribute contextual information to a declaration node.
///
/// # Panics
///
/// Panics if an entry already exists for the node id.
pub fn add_declaration(&self, node: &Node<ast::TypeDesc>, typ: Type) {
self.add_node(node);
self.body
.borrow_mut()
.var_decl_types
.insert(node.id, typ)
.expect_none("declaration attributes already exist");
}

pub fn map_variable_type<T>(&self, node: &Node<T>, typ: Type) {
self.add_node(node);
self.body
Expand Down
30 changes: 0 additions & 30 deletions crates/analyzer/src/namespace/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,6 @@ pub struct EventField {
}

impl FunctionSignature {
/// # Panics
/// Panics if any param type is an `Err`
pub fn param_types(&self) -> Vec<Type> {
self.params
.iter()
.map(|param| param.typ.clone().expect("fn param type error"))
.collect()
}

/// # Panics
/// Panics if the return type is an `Err`
pub fn expect_return_type(&self) -> Type {
self.return_type.clone().expect("fn return type error")
}

/// Parameters without `ctx`, if it is a contract function that declares it.
///
/// This is used when calling a contract method externally.
Expand Down Expand Up @@ -491,21 +476,6 @@ impl Type {
Type::Base(Base::Numeric(int_type))
}

pub fn generic_arg_type(&self, idx: usize) -> Option<Type> {
match self {
Type::Map(Map { key, value }) => match idx {
0 => Some(Type::Base(*key)),
1 => Some((**value).clone()),
_ => None,
},
Type::Array(array) => match idx {
0 => Some(Type::Base(array.inner)),
_ => None,
},
_ => None,
}
}

pub fn has_fixed_size(&self) -> bool {
match self {
Type::Base(_)
Expand Down
2 changes: 0 additions & 2 deletions crates/analyzer/src/traversal/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn var_decl(scope: &mut BlockScope, stmt: &Node<fe::FuncStmt>) -> Result<(),
}
}

scope.root.add_declaration(typ, declared_type.clone());
add_var(scope, target, declared_type)?;
return Ok(());
}
Expand Down Expand Up @@ -70,7 +69,6 @@ pub fn const_decl(scope: &mut BlockScope, stmt: &Node<fe::FuncStmt>) -> Result<(
// Perform constant evaluation.
let const_value = const_expr::eval_expr(scope, value)?;

scope.root.add_declaration(typ, declared_type.clone());
scope.root.map_variable_type(name, declared_type.clone());
// this logs a message on err, so it's safe to ignore here.
let _ = scope.add_var(name.kind.as_str(), declared_type, true, name.span);
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/tests/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn function_diagnostics(fun: items::FunctionId, db: &dyn AnalyzerDb) -> Vec<Diag
// signature
build_debug_diagnostics(&[(fun.data(db).ast.span, &fun.signature(db))]),
// declarations
label_in_non_overlapping_groups(&lookup_spans(&body.var_decl_types, &body.spans)),
label_in_non_overlapping_groups(&lookup_spans(&body.var_types, &body.spans)),
// expressions
label_in_non_overlapping_groups(&lookup_spans(&body.expressions, &body.spans)),
// emits
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/tests/snapshots/analysis__aug_assign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ note:
}

note:
┌─ aug_assign.fe:66:23
┌─ aug_assign.fe:66:13
66let my_array: Array<u256, 10>
^^^^^^^^^^^^^^^ Array<u256, 10>
^^^^^^^^ Array<u256, 10>

note:
┌─ aug_assign.fe:67:9
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/tests/snapshots/analysis__basic_ingot.snap
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ note:
}

note:
┌─ ingots/basic_ingot/src/main.fe:37:28
┌─ ingots/basic_ingot/src/main.fe:37:13
37let bing_contract: BingContract = BingContract.create(ctx, 0)
^^^^^^^^^^^^ BingContract
^^^^^^^^^^^^^ BingContract

note:
┌─ ingots/basic_ingot/src/main.fe:37:63
Expand Down
62 changes: 31 additions & 31 deletions crates/analyzer/tests/snapshots/analysis__const_generics.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,75 +27,75 @@ note:
}

note:
┌─ const_generics.fe:4:24
┌─ const_generics.fe:4:13
4let array_lit: Array<i32, 8>
^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
5let array_lit2: Array<i32, { 8 }>
^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^^ Array<i32, 8>
·
8let array_ternary: Array<i32, { 3 if false else 8 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^^^^^ Array<i32, 8>
·
11let array_logical_or: Array<i32, { 8 if (true or false) else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^^^^^^^^ Array<i32, 8>
12let array_logical_and: Array<i32, { 0 if (true and false) else 8 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^^^^^^^^^ Array<i32, 8>
·
15let array_add: Array<i32, { 5 + 3 }>
^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
16let array_sub: Array<i32, { 10 - 2 }>
^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
17let array_mul: Array<i32, { 2 * 4 }>
^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
18let array_div: Array<i32, { 16 / 2 }>
^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
19let array_mod: Array<i32, { 26 % 9 }>
^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
20let array_pow: Array<i32, { 2 ** 3 }>
^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
^^^^^^^^^ Array<i32, 8>
21let array_shl: Array<i32, { 0b0010 << 2 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
22 │ let array_shr: Array<i32, { 0b100000 >> 2 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
23 │ let array_bitor: Array<i32, { 0b1000 | 0b0000 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^^^ Array<i32, 8>
24 │ let array_xor: Array<i32, { 0b1111 ^ 0b0111 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
25 │ let array_bitand: Array<i32, { 0b1010 & 0b1101 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^^^^ Array<i32, 8>
·
28 │ let array_eq: Array<i32, { 8 if 10 == 10 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^ Array<i32, 8>
29 │ let array_ne: Array<i32, { 8 if 10 != 0 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^ Array<i32, 8>
30 │ let array_lt1: Array<i32, { 8 if 0 < 10 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
31 │ let array_lt2: Array<i32, { 0 if 10 < 10 else 8 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
32 │ let array_lte: Array<i32, { 8 if 0 <= 10 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
33 │ let array_lte2: Array<i32, { 8 if 10 <= 10 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^^ Array<i32, 8>
34 │ let array_gt: Array<i32, { 8 if 10 > 0 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^ Array<i32, 8>
35 │ let array_gt2: Array<i32, { 1 if 10 > 10 else 8 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
36 │ let array_gte: Array<i32, { 1 if 0 >= 10 else 8 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
37 │ let array_gte2: Array<i32, { 8 if 10 >= 10 else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^^ Array<i32, 8>
·
40 │ let array_not: Array<i32, { 8 if not false else 0 }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^ Array<i32, 8>
·
43 │ const DOUBLE_ARRAY_LENGTH: u64 = 16
^^^ u64
^^^^^^^^^^^^^^^^^^^ u64
44 │ const TWO: u64 = 2
^^^ u64
│ ^^^ u64
45 │
46 │ let array_with_const: Array<i32, { DOUBLE_ARRAY_LENGTH / TWO }>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<i32, 8>
│ ^^^^^^^^^^^^^^^^ Array<i32, 8>

note:
┌─ const_generics.fe:5:38
Expand Down
Loading

0 comments on commit ecfccc5

Please sign in to comment.