Skip to content

Commit

Permalink
Implement path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed May 3, 2023
1 parent 5a0c25c commit 3bffc14
Show file tree
Hide file tree
Showing 55 changed files with 895 additions and 517 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/analyzer/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use fe_analyzer::namespace::items::ModuleId;
use fe_analyzer::TestDb;
use fe_analyzer::{namespace::items::ModuleId, TestDb};

fn criterion_benchmark(c: &mut Criterion) {
let path = "demos/uniswap.fe";
Expand Down
37 changes: 19 additions & 18 deletions crates/analyzer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@ use crate::{
pattern_analysis::PatternMatrix,
};

use crate::namespace::items::{
ContractId, DiagnosticSink, FunctionId, FunctionSigId, Item, TraitId,
};
use crate::namespace::types::{Generic, SelfDecl, Type, TypeId};
use crate::AnalyzerDb;
use crate::{
builtins::{ContractTypeMethod, GlobalFunction, Intrinsic, ValueMethod},
namespace::scopes::BlockScopeType,
};
use crate::{
errors::{self, IncompleteItem, TypeError},
namespace::items::ModuleId,
namespace::{
items::{ContractId, DiagnosticSink, FunctionId, FunctionSigId, Item, ModuleId, TraitId},
scopes::BlockScopeType,
types::{Generic, SelfDecl, Type, TypeId},
},
AnalyzerDb,
};
use fe_common::diagnostics::Diagnostic;
pub use fe_common::diagnostics::Label;
use fe_common::Span;
use fe_parser::ast;
use fe_parser::node::{Node, NodeId};
use fe_common::{diagnostics::Diagnostic, Span};
use fe_parser::{
ast,
node::{Node, NodeId},
};

use indexmap::IndexMap;
use num_bigint::BigInt;
use smol_str::SmolStr;
use std::fmt::{self, Debug};
use std::hash::Hash;
use std::marker::PhantomData;
use std::rc::Rc;
use std::{cell::RefCell, collections::HashMap};
use std::{
cell::RefCell,
collections::HashMap,
fmt::{self, Debug},
hash::Hash,
marker::PhantomData,
rc::Rc,
};

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Analysis<T> {
Expand Down
24 changes: 12 additions & 12 deletions crates/analyzer/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::namespace::items::{
self, AttributeId, ContractFieldId, ContractId, DepGraphWrapper, EnumVariantKind, FunctionId,
FunctionSigId, ImplId, IngotId, Item, ModuleConstantId, ModuleId, StructFieldId, StructId,
TraitId, TypeAliasId,
};
use crate::namespace::types::{self, Type, TypeId};
use crate::{
context::{Analysis, Constant, FunctionBody},
namespace::items::EnumId,
};
use crate::{
errors::{ConstEvalError, TypeError},
namespace::items::EnumVariantId,
namespace::{
items::{
self, AttributeId, ContractFieldId, ContractId, DepGraphWrapper, EnumId, EnumVariantId,
EnumVariantKind, FunctionId, FunctionSigId, ImplId, IngotId, Item, ModuleConstantId,
ModuleId, StructFieldId, StructId, TraitId, TypeAliasId,
},
types::{self, Type, TypeId},
},
};
use fe_common::{
db::{SourceDb, SourceDbStorage, Upcast, UpcastMut},
SourceFileId, Span,
};
use fe_common::db::{SourceDb, SourceDbStorage, Upcast, UpcastMut};
use fe_common::{SourceFileId, Span};
use fe_parser::ast;
use indexmap::map::IndexMap;
use smol_str::SmolStr;
Expand Down
22 changes: 13 additions & 9 deletions crates/analyzer/src/db/queries/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::context::AnalyzerContext;
use crate::db::{Analysis, AnalyzerDb};
use crate::errors;
use crate::namespace::items::{
self, ContractFieldId, ContractId, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item,
TypeDef,
use crate::{
context::AnalyzerContext,
db::{Analysis, AnalyzerDb},
errors,
namespace::{
items::{
self, ContractFieldId, ContractId, DepGraph, DepGraphWrapper, DepLocality, FunctionId,
Item, TypeDef,
},
scopes::ItemScope,
types::{self, Type},
},
traversal::types::type_desc,
};
use crate::namespace::scopes::ItemScope;
use crate::namespace::types::{self, Type};
use crate::traversal::types::type_desc;
use fe_common::diagnostics::Label;
use fe_parser::ast;
use indexmap::map::{Entry, IndexMap};
Expand Down
33 changes: 19 additions & 14 deletions crates/analyzer/src/db/queries/functions.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
use crate::context::{AnalyzerContext, CallType, FunctionBody};
use crate::db::{Analysis, AnalyzerDb};
use crate::display::Displayable;
use crate::errors::TypeError;
use crate::namespace::items::{
DepGraph, DepGraphWrapper, DepLocality, FunctionId, FunctionSigId, Item, TypeDef,
use crate::{
context::{AnalyzerContext, CallType, FunctionBody},
db::{Analysis, AnalyzerDb},
display::Displayable,
errors::TypeError,
namespace::{
items::{DepGraph, DepGraphWrapper, DepLocality, FunctionId, FunctionSigId, Item, TypeDef},
scopes::{BlockScope, BlockScopeType, FunctionScope, ItemScope},
types::{self, CtxDecl, Generic, SelfDecl, Type, TypeId},
},
traversal::{
functions::traverse_statements,
types::{type_desc, type_desc_to_trait},
},
};
use crate::namespace::scopes::{BlockScope, BlockScopeType, FunctionScope, ItemScope};
use crate::namespace::types::{self, CtxDecl, Generic, SelfDecl, Type, TypeId};
use crate::traversal::functions::traverse_statements;
use crate::traversal::types::{type_desc, type_desc_to_trait};
use fe_common::diagnostics::Label;
use fe_parser::ast::{self, GenericParameter};
use fe_parser::node::Node;
use fe_parser::{
ast::{self, GenericParameter},
node::Node,
};
use if_chain::if_chain;
use smol_str::SmolStr;
use std::collections::HashMap;
use std::rc::Rc;
use std::{collections::HashMap, rc::Rc};

/// Gather context information for a function definition and check for type
/// errors. Does not inspect the function body.
Expand Down
15 changes: 9 additions & 6 deletions crates/analyzer/src/db/queries/impls.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use indexmap::map::Entry;
use indexmap::IndexMap;
use indexmap::{map::Entry, IndexMap};
use smol_str::SmolStr;

use crate::context::{Analysis, AnalyzerContext};
use crate::namespace::items::{Function, FunctionId, ImplId, Item};
use crate::namespace::scopes::ItemScope;
use crate::AnalyzerDb;
use crate::{
context::{Analysis, AnalyzerContext},
namespace::{
items::{Function, FunctionId, ImplId, Item},
scopes::ItemScope,
},
AnalyzerDb,
};
use std::rc::Rc;

pub fn impl_all_functions(db: &dyn AnalyzerDb, impl_: ImplId) -> Rc<[FunctionId]> {
Expand Down
31 changes: 17 additions & 14 deletions crates/analyzer/src/db/queries/structs.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use crate::builtins;
use crate::constants::MAX_INDEXED_EVENT_FIELDS;
use crate::context::AnalyzerContext;
use crate::db::Analysis;
use crate::errors::TypeError;
use crate::namespace::items::{
self, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item, StructField, StructFieldId,
StructId, TypeDef,
use crate::{
builtins,
constants::MAX_INDEXED_EVENT_FIELDS,
context::AnalyzerContext,
db::Analysis,
errors::TypeError,
namespace::{
items::{
self, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item, StructField,
StructFieldId, StructId, TypeDef,
},
scopes::ItemScope,
types::{Type, TypeId},
},
traversal::types::type_desc,
AnalyzerDb,
};
use crate::namespace::scopes::ItemScope;
use crate::namespace::types::{Type, TypeId};
use crate::traversal::types::type_desc;
use crate::AnalyzerDb;
use fe_common::utils::humanize::pluralize_conditionally;
use fe_parser::{ast, Label};
use indexmap::map::{Entry, IndexMap};
use smol_str::SmolStr;
use std::rc::Rc;
use std::str::FromStr;
use std::{rc::Rc, str::FromStr};

pub fn struct_all_fields(db: &dyn AnalyzerDb, struct_: StructId) -> Rc<[StructFieldId]> {
struct_
Expand Down
17 changes: 10 additions & 7 deletions crates/analyzer/src/db/queries/traits.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use indexmap::map::Entry;
use indexmap::IndexMap;
use indexmap::{map::Entry, IndexMap};
use smol_str::SmolStr;

use crate::context::{Analysis, AnalyzerContext};
use crate::namespace::items::{FunctionSig, FunctionSigId, Item, TraitId};
use crate::namespace::scopes::ItemScope;
use crate::namespace::types::TypeId;
use crate::AnalyzerDb;
use crate::{
context::{Analysis, AnalyzerContext},
namespace::{
items::{FunctionSig, FunctionSigId, Item, TraitId},
scopes::ItemScope,
types::TypeId,
},
AnalyzerDb,
};
use std::rc::Rc;

pub fn trait_all_functions(db: &dyn AnalyzerDb, trait_: TraitId) -> Rc<[FunctionSigId]> {
Expand Down
20 changes: 12 additions & 8 deletions crates/analyzer/src/db/queries/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use std::rc::Rc;

use smol_str::SmolStr;

use crate::context::{AnalyzerContext, TempContext};
use crate::db::Analysis;
use crate::errors::TypeError;
use crate::namespace::items::{FunctionSigId, ImplId, TraitId, TypeAliasId};
use crate::namespace::scopes::ItemScope;
use crate::namespace::types::{self, TypeId};
use crate::traversal::types::type_desc;
use crate::AnalyzerDb;
use crate::{
context::{AnalyzerContext, TempContext},
db::Analysis,
errors::TypeError,
namespace::{
items::{FunctionSigId, ImplId, TraitId, TypeAliasId},
scopes::ItemScope,
types::{self, TypeId},
},
traversal::types::type_desc,
AnalyzerDb,
};

/// Returns all `impl` for the given type from the current ingot as well as
/// dependency ingots
Expand Down
6 changes: 4 additions & 2 deletions crates/analyzer/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Semantic errors.

use crate::context::{DiagnosticVoucher, NamedThing};
use fe_common::diagnostics::{Diagnostic, Label, Severity};
use fe_common::Span;
use fe_common::{
diagnostics::{Diagnostic, Label, Severity},
Span,
};
use std::fmt::Display;

/// Error indicating that a type is invalid.
Expand Down
38 changes: 21 additions & 17 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
use crate::constants::{EMITTABLE_TRAIT_NAME, INDEXED};
use crate::context::{self, Analysis, Constant, NamedThing};
use crate::display::{DisplayWithDb, Displayable};
use crate::errors::{self, IncompleteItem, TypeError};
use crate::namespace::types::{self, GenericType, Type, TypeId};
use crate::traversal::pragma::check_pragma_version;
use crate::AnalyzerDb;
use crate::{builtins, errors::ConstEvalError};
use fe_common::diagnostics::Diagnostic;
use fe_common::diagnostics::Label;
use fe_common::files::{common_prefix, Utf8Path};
use fe_common::{impl_intern_key, FileKind, SourceFileId};
use fe_parser::ast::GenericParameter;
use fe_parser::node::{Node, Span};
use fe_parser::{ast, node::NodeId};
use crate::{
builtins,
constants::{EMITTABLE_TRAIT_NAME, INDEXED},
context::{self, Analysis, Constant, NamedThing},
display::{DisplayWithDb, Displayable},
errors::{self, ConstEvalError, IncompleteItem, TypeError},
namespace::types::{self, GenericType, Type, TypeId},
traversal::pragma::check_pragma_version,
AnalyzerDb,
};
use fe_common::{
diagnostics::{Diagnostic, Label},
files::{common_prefix, Utf8Path},
impl_intern_key, FileKind, SourceFileId,
};
use fe_parser::{
ast,
ast::GenericParameter,
node::{Node, NodeId, Span},
};
use indexmap::{indexmap, IndexMap};
use smallvec::SmallVec;
use smol_str::SmolStr;
use std::rc::Rc;
use std::{fmt, ops::Deref};
use std::{fmt, ops::Deref, rc::Rc};
use strum::IntoEnumIterator;

use super::types::TraitOrType;
Expand Down
33 changes: 19 additions & 14 deletions crates/analyzer/src/namespace/scopes.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#![allow(unstable_name_collisions)] // expect_none, which ain't gonna be stabilized

use crate::context::{
AnalyzerContext, CallType, Constant, ExpressionAttributes, FunctionBody, NamedThing,
use crate::{
context::{
AnalyzerContext, CallType, Constant, ExpressionAttributes, FunctionBody, NamedThing,
},
errors::{AlreadyDefined, FatalError, IncompleteItem, TypeError},
namespace::{
items::{FunctionId, Item, ModuleId, TypeDef},
types::{Type, TypeId},
},
pattern_analysis::PatternMatrix,
AnalyzerDb,
};
use fe_common::{diagnostics::Diagnostic, Span};
use fe_parser::{
ast,
ast::Expr,
node::{Node, NodeId},
Label,
};
use crate::errors::{AlreadyDefined, FatalError, IncompleteItem, TypeError};
use crate::namespace::items::{FunctionId, ModuleId};
use crate::namespace::items::{Item, TypeDef};
use crate::namespace::types::{Type, TypeId};
use crate::pattern_analysis::PatternMatrix;
use crate::AnalyzerDb;
use fe_common::diagnostics::Diagnostic;
use fe_common::Span;
use fe_parser::{ast, node::NodeId, Label};
use fe_parser::{ast::Expr, node::Node};
use indexmap::IndexMap;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::{cell::RefCell, collections::BTreeMap};

pub struct ItemScope<'a> {
db: &'a dyn AnalyzerDb,
Expand Down
Loading

0 comments on commit 3bffc14

Please sign in to comment.