Skip to content

Commit cf252f6

Browse files
committed
Implement path resolution
1 parent 5a0c25c commit cf252f6

56 files changed

Lines changed: 939 additions & 534 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/analyzer/benches/bench.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
2-
use fe_analyzer::namespace::items::ModuleId;
3-
use fe_analyzer::TestDb;
2+
use fe_analyzer::{namespace::items::ModuleId, TestDb};
43

54
fn criterion_benchmark(c: &mut Criterion) {
65
let path = "demos/uniswap.fe";

crates/analyzer/src/context.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@ use crate::{
55
pattern_analysis::PatternMatrix,
66
};
77

8-
use crate::namespace::items::{
9-
ContractId, DiagnosticSink, FunctionId, FunctionSigId, Item, TraitId,
10-
};
11-
use crate::namespace::types::{Generic, SelfDecl, Type, TypeId};
12-
use crate::AnalyzerDb;
138
use crate::{
149
builtins::{ContractTypeMethod, GlobalFunction, Intrinsic, ValueMethod},
15-
namespace::scopes::BlockScopeType,
16-
};
17-
use crate::{
1810
errors::{self, IncompleteItem, TypeError},
19-
namespace::items::ModuleId,
11+
namespace::{
12+
items::{ContractId, DiagnosticSink, FunctionId, FunctionSigId, Item, ModuleId, TraitId},
13+
scopes::BlockScopeType,
14+
types::{Generic, SelfDecl, Type, TypeId},
15+
},
16+
AnalyzerDb,
2017
};
21-
use fe_common::diagnostics::Diagnostic;
2218
pub use fe_common::diagnostics::Label;
23-
use fe_common::Span;
24-
use fe_parser::ast;
25-
use fe_parser::node::{Node, NodeId};
19+
use fe_common::{diagnostics::Diagnostic, Span};
20+
use fe_parser::{
21+
ast,
22+
node::{Node, NodeId},
23+
};
2624

2725
use indexmap::IndexMap;
2826
use num_bigint::BigInt;
2927
use smol_str::SmolStr;
30-
use std::fmt::{self, Debug};
31-
use std::hash::Hash;
32-
use std::marker::PhantomData;
33-
use std::rc::Rc;
34-
use std::{cell::RefCell, collections::HashMap};
28+
use std::{
29+
cell::RefCell,
30+
collections::HashMap,
31+
fmt::{self, Debug},
32+
hash::Hash,
33+
marker::PhantomData,
34+
rc::Rc,
35+
};
3536

3637
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
3738
pub struct Analysis<T> {

crates/analyzer/src/db.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
use crate::namespace::items::{
2-
self, AttributeId, ContractFieldId, ContractId, DepGraphWrapper, EnumVariantKind, FunctionId,
3-
FunctionSigId, ImplId, IngotId, Item, ModuleConstantId, ModuleId, StructFieldId, StructId,
4-
TraitId, TypeAliasId,
5-
};
6-
use crate::namespace::types::{self, Type, TypeId};
71
use crate::{
82
context::{Analysis, Constant, FunctionBody},
9-
namespace::items::EnumId,
10-
};
11-
use crate::{
123
errors::{ConstEvalError, TypeError},
13-
namespace::items::EnumVariantId,
4+
namespace::{
5+
items::{
6+
self, AttributeId, ContractFieldId, ContractId, DepGraphWrapper, EnumId, EnumVariantId,
7+
EnumVariantKind, FunctionId, FunctionSigId, ImplId, IngotId, Item, ModuleConstantId,
8+
ModuleId, StructFieldId, StructId, TraitId, TypeAliasId,
9+
},
10+
types::{self, Type, TypeId},
11+
},
12+
};
13+
use fe_common::{
14+
db::{SourceDb, SourceDbStorage, Upcast, UpcastMut},
15+
SourceFileId, Span,
1416
};
15-
use fe_common::db::{SourceDb, SourceDbStorage, Upcast, UpcastMut};
16-
use fe_common::{SourceFileId, Span};
1717
use fe_parser::ast;
1818
use indexmap::map::IndexMap;
1919
use smol_str::SmolStr;

crates/analyzer/src/db/queries/contracts.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
use crate::context::AnalyzerContext;
2-
use crate::db::{Analysis, AnalyzerDb};
3-
use crate::errors;
4-
use crate::namespace::items::{
5-
self, ContractFieldId, ContractId, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item,
6-
TypeDef,
1+
use crate::{
2+
context::AnalyzerContext,
3+
db::{Analysis, AnalyzerDb},
4+
errors,
5+
namespace::{
6+
items::{
7+
self, ContractFieldId, ContractId, DepGraph, DepGraphWrapper, DepLocality, FunctionId,
8+
Item, TypeDef,
9+
},
10+
scopes::ItemScope,
11+
types::{self, Type},
12+
},
13+
traversal::types::type_desc,
714
};
8-
use crate::namespace::scopes::ItemScope;
9-
use crate::namespace::types::{self, Type};
10-
use crate::traversal::types::type_desc;
1115
use fe_common::diagnostics::Label;
1216
use fe_parser::ast;
1317
use indexmap::map::{Entry, IndexMap};

crates/analyzer/src/db/queries/functions.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
use crate::context::{AnalyzerContext, CallType, FunctionBody};
2-
use crate::db::{Analysis, AnalyzerDb};
3-
use crate::display::Displayable;
4-
use crate::errors::TypeError;
5-
use crate::namespace::items::{
6-
DepGraph, DepGraphWrapper, DepLocality, FunctionId, FunctionSigId, Item, TypeDef,
1+
use crate::{
2+
context::{AnalyzerContext, CallType, FunctionBody},
3+
db::{Analysis, AnalyzerDb},
4+
display::Displayable,
5+
errors::TypeError,
6+
namespace::{
7+
items::{DepGraph, DepGraphWrapper, DepLocality, FunctionId, FunctionSigId, Item, TypeDef},
8+
scopes::{BlockScope, BlockScopeType, FunctionScope, ItemScope},
9+
types::{self, CtxDecl, Generic, SelfDecl, Type, TypeId},
10+
},
11+
traversal::{
12+
functions::traverse_statements,
13+
types::{type_desc, type_desc_to_trait},
14+
},
715
};
8-
use crate::namespace::scopes::{BlockScope, BlockScopeType, FunctionScope, ItemScope};
9-
use crate::namespace::types::{self, CtxDecl, Generic, SelfDecl, Type, TypeId};
10-
use crate::traversal::functions::traverse_statements;
11-
use crate::traversal::types::{type_desc, type_desc_to_trait};
1216
use fe_common::diagnostics::Label;
13-
use fe_parser::ast::{self, GenericParameter};
14-
use fe_parser::node::Node;
17+
use fe_parser::{
18+
ast::{self, GenericParameter},
19+
node::Node,
20+
};
1521
use if_chain::if_chain;
1622
use smol_str::SmolStr;
17-
use std::collections::HashMap;
18-
use std::rc::Rc;
23+
use std::{collections::HashMap, rc::Rc};
1924

2025
/// Gather context information for a function definition and check for type
2126
/// errors. Does not inspect the function body.

crates/analyzer/src/db/queries/impls.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use indexmap::map::Entry;
2-
use indexmap::IndexMap;
1+
use indexmap::{map::Entry, IndexMap};
32
use smol_str::SmolStr;
43

5-
use crate::context::{Analysis, AnalyzerContext};
6-
use crate::namespace::items::{Function, FunctionId, ImplId, Item};
7-
use crate::namespace::scopes::ItemScope;
8-
use crate::AnalyzerDb;
4+
use crate::{
5+
context::{Analysis, AnalyzerContext},
6+
namespace::{
7+
items::{Function, FunctionId, ImplId, Item},
8+
scopes::ItemScope,
9+
},
10+
AnalyzerDb,
11+
};
912
use std::rc::Rc;
1013

1114
pub fn impl_all_functions(db: &dyn AnalyzerDb, impl_: ImplId) -> Rc<[FunctionId]> {

crates/analyzer/src/db/queries/structs.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
use crate::builtins;
2-
use crate::constants::MAX_INDEXED_EVENT_FIELDS;
3-
use crate::context::AnalyzerContext;
4-
use crate::db::Analysis;
5-
use crate::errors::TypeError;
6-
use crate::namespace::items::{
7-
self, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item, StructField, StructFieldId,
8-
StructId, TypeDef,
1+
use crate::{
2+
builtins,
3+
constants::MAX_INDEXED_EVENT_FIELDS,
4+
context::AnalyzerContext,
5+
db::Analysis,
6+
errors::TypeError,
7+
namespace::{
8+
items::{
9+
self, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item, StructField,
10+
StructFieldId, StructId, TypeDef,
11+
},
12+
scopes::ItemScope,
13+
types::{Type, TypeId},
14+
},
15+
traversal::types::type_desc,
16+
AnalyzerDb,
917
};
10-
use crate::namespace::scopes::ItemScope;
11-
use crate::namespace::types::{Type, TypeId};
12-
use crate::traversal::types::type_desc;
13-
use crate::AnalyzerDb;
1418
use fe_common::utils::humanize::pluralize_conditionally;
1519
use fe_parser::{ast, Label};
1620
use indexmap::map::{Entry, IndexMap};
1721
use smol_str::SmolStr;
18-
use std::rc::Rc;
19-
use std::str::FromStr;
22+
use std::{rc::Rc, str::FromStr};
2023

2124
pub fn struct_all_fields(db: &dyn AnalyzerDb, struct_: StructId) -> Rc<[StructFieldId]> {
2225
struct_

crates/analyzer/src/db/queries/traits.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use indexmap::map::Entry;
2-
use indexmap::IndexMap;
1+
use indexmap::{map::Entry, IndexMap};
32
use smol_str::SmolStr;
43

5-
use crate::context::{Analysis, AnalyzerContext};
6-
use crate::namespace::items::{FunctionSig, FunctionSigId, Item, TraitId};
7-
use crate::namespace::scopes::ItemScope;
8-
use crate::namespace::types::TypeId;
9-
use crate::AnalyzerDb;
4+
use crate::{
5+
context::{Analysis, AnalyzerContext},
6+
namespace::{
7+
items::{FunctionSig, FunctionSigId, Item, TraitId},
8+
scopes::ItemScope,
9+
types::TypeId,
10+
},
11+
AnalyzerDb,
12+
};
1013
use std::rc::Rc;
1114

1215
pub fn trait_all_functions(db: &dyn AnalyzerDb, trait_: TraitId) -> Rc<[FunctionSigId]> {

crates/analyzer/src/db/queries/types.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ use std::rc::Rc;
22

33
use smol_str::SmolStr;
44

5-
use crate::context::{AnalyzerContext, TempContext};
6-
use crate::db::Analysis;
7-
use crate::errors::TypeError;
8-
use crate::namespace::items::{FunctionSigId, ImplId, TraitId, TypeAliasId};
9-
use crate::namespace::scopes::ItemScope;
10-
use crate::namespace::types::{self, TypeId};
11-
use crate::traversal::types::type_desc;
12-
use crate::AnalyzerDb;
5+
use crate::{
6+
context::{AnalyzerContext, TempContext},
7+
db::Analysis,
8+
errors::TypeError,
9+
namespace::{
10+
items::{FunctionSigId, ImplId, TraitId, TypeAliasId},
11+
scopes::ItemScope,
12+
types::{self, TypeId},
13+
},
14+
traversal::types::type_desc,
15+
AnalyzerDb,
16+
};
1317

1418
/// Returns all `impl` for the given type from the current ingot as well as
1519
/// dependency ingots

0 commit comments

Comments
 (0)