Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Nov 29, 2021
1 parent ddcc606 commit adbff60
Show file tree
Hide file tree
Showing 48 changed files with 775 additions and 909 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions crates/analyzer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ impl fmt::Display for ExpressionAttributes {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CallType {
BuiltinFunction(GlobalFunction),
BuiltinValueMethod(ValueMethod),
BuiltinValueMethod {
method: ValueMethod,
typ: Type,
},

// create, create2 (will be methods of the context struct soon)
BuiltinAssociatedFunction {
Expand Down Expand Up @@ -294,7 +297,7 @@ impl CallType {
use CallType::*;
match self {
BuiltinFunction(_)
| BuiltinValueMethod(_)
| BuiltinValueMethod { .. }
| TypeConstructor(_)
| BuiltinAssociatedFunction { .. } => None,
AssociatedFunction { function: id, .. }
Expand All @@ -307,7 +310,7 @@ impl CallType {
pub fn function_name(&self, db: &dyn AnalyzerDb) -> String {
match self {
CallType::BuiltinFunction(f) => f.as_ref().to_string(),
CallType::BuiltinValueMethod(f) => f.as_ref().to_string(),
CallType::BuiltinValueMethod { method, .. } => method.as_ref().to_string(),
CallType::BuiltinAssociatedFunction { function, .. } => function.as_ref().to_string(),

CallType::AssociatedFunction { function: id, .. }
Expand Down
3 changes: 3 additions & 0 deletions crates/analyzer/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ pub trait AnalyzerDb {
&self,
field: ContractFieldId,
) -> Analysis<Result<types::Type, TypeError>>;
#[salsa::cycle(queries::contracts::contract_dependency_graph_cycle)]
#[salsa::invoke(queries::contracts::contract_dependency_graph)]
fn contract_dependency_graph(&self, id: ContractId) -> DepGraphWrapper;
#[salsa::cycle(queries::contracts::contract_runtime_dependency_graph_cycle)]
#[salsa::invoke(queries::contracts::contract_runtime_dependency_graph)]
fn contract_runtime_dependency_graph(&self, id: ContractId) -> DepGraphWrapper;

Expand All @@ -129,6 +131,7 @@ pub trait AnalyzerDb {
fn function_signature(&self, id: FunctionId) -> Analysis<Rc<types::FunctionSignature>>;
#[salsa::invoke(queries::functions::function_body)]
fn function_body(&self, id: FunctionId) -> Analysis<Rc<FunctionBody>>;
#[salsa::cycle(queries::functions::function_dependency_graph_cycle)]
#[salsa::invoke(queries::functions::function_dependency_graph)]
fn function_dependency_graph(&self, id: FunctionId) -> DepGraphWrapper;

Expand Down
18 changes: 17 additions & 1 deletion crates/analyzer/src/db/queries/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn contract_field_type(
pub fn contract_dependency_graph(db: &dyn AnalyzerDb, contract: ContractId) -> DepGraphWrapper {
// A contract depends on the types of its fields, and the things those types depend on.
// Note that this *does not* include the contract's public function graph.
// (See `contract_public_fn_dependency_graph` below)
// (See `contract_runtime_dependency_graph` below)

let fields = contract.fields(db);
let field_types = fields
Expand Down Expand Up @@ -313,6 +313,14 @@ pub fn contract_dependency_graph(db: &dyn AnalyzerDb, contract: ContractId) -> D
DepGraphWrapper(Rc::new(graph))
}

pub fn contract_dependency_graph_cycle(
_db: &dyn AnalyzerDb,
_cycle: &[String],
_contract: &ContractId,
) -> DepGraphWrapper {
DepGraphWrapper(Rc::new(DepGraph::new()))
}

pub fn contract_runtime_dependency_graph(
db: &dyn AnalyzerDb,
contract: ContractId,
Expand All @@ -337,3 +345,11 @@ pub fn contract_runtime_dependency_graph(
}
DepGraphWrapper(Rc::new(graph))
}

pub fn contract_runtime_dependency_graph_cycle(
_db: &dyn AnalyzerDb,
_cycle: &[String],
_contract: &ContractId,
) -> DepGraphWrapper {
DepGraphWrapper(Rc::new(DepGraph::new()))
}
10 changes: 9 additions & 1 deletion crates/analyzer/src/db/queries/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn function_dependency_graph(db: &dyn AnalyzerDb, function: FunctionId) -> D
));
}
// Builtin functions aren't part of the dependency graph yet.
CallType::BuiltinFunction(_) | CallType::BuiltinValueMethod(_) => {}
CallType::BuiltinFunction(_) | CallType::BuiltinValueMethod { .. } => {}
}
}

Expand Down Expand Up @@ -323,3 +323,11 @@ pub fn function_dependency_graph(db: &dyn AnalyzerDb, function: FunctionId) -> D
}
DepGraphWrapper(Rc::new(graph))
}

pub fn function_dependency_graph_cycle(
_db: &dyn AnalyzerDb,
_cycle: &[String],
_function: &FunctionId,
) -> DepGraphWrapper {
DepGraphWrapper(Rc::new(DepGraph::new()))
}
19 changes: 13 additions & 6 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ impl Item {
}

pub fn path(&self, db: &dyn AnalyzerDb) -> Rc<Vec<String>> {
if let Some(parent) = self.parent(db) {
let mut path = parent.path(db).as_ref().clone();
path.push(self.name(db));
Rc::new(path)
} else {
Rc::new(vec![self.name(db)])
// The path is used to generate a yul identifier,
// eg `foo::Bar::new` becomes `$$foo$Bar$new`.
// Right now, the ingot name is the os path, so it could
// be "my project/src".
// For now, we'll just leave the ingot out of the path,
// because we can only compile a single ingot anyway.
match self.parent(db) {
Some(Item::Ingot(_)) | None => Rc::new(vec![self.name(db)]),
Some(parent) => {
let mut path = parent.path(db).as_ref().clone();
path.push(self.name(db));
Rc::new(path)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/analyzer/src/traversal/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,10 @@ fn expr_call_builtin_value_method(
"argument",
);

let calltype = CallType::BuiltinValueMethod(method);
let calltype = CallType::BuiltinValueMethod {
method,
typ: value_attrs.typ.clone(),
};
match method {
ValueMethod::Clone => {
match value_attrs.location {
Expand Down
21 changes: 14 additions & 7 deletions crates/analyzer/tests/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ macro_rules! test_analysis_ingot {
.values()
.into_iter()
.map(|file| {
(
file.id,
(
file.clone(),
fe_parser::parse_file(file.id, &file.content).unwrap().0,
),
)
let ast = match fe_parser::parse_file(file.id, &file.content) {
Ok((ast, diags)) => {
if !diags.is_empty() {
print_diagnostics(&diags, &files);
panic!("non-fatal parsing error");
}
ast
}
Err(diags) => {
print_diagnostics(&diags, &files);
panic!("parsing failed");
}
};
(file.id, (file.clone(), ast))
})
.collect(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/analyzer/tests/analysis.rs
expression: "build_snapshot(&files, module, &db)"
expression: "build_snapshot(&files, module_id, &db)"

---
note:
Expand Down Expand Up @@ -136,7 +136,7 @@ note:
┌─ stress/abi_encoding_stress.fe:27:16
27return self.my_addrs.to_mem()
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 5, inner: Address }) }

note:
┌─ stress/abi_encoding_stress.fe:29:5
Expand Down Expand Up @@ -302,7 +302,7 @@ note:
┌─ stress/abi_encoding_stress.fe:39:16
39return self.my_string.to_mem()
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: String(FeString { max_size: 10 }) }

note:
┌─ stress/abi_encoding_stress.fe:41:5
Expand Down Expand Up @@ -397,7 +397,7 @@ note:
┌─ stress/abi_encoding_stress.fe:45:16
45return self.my_u16s.to_mem()
^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 255, inner: Numeric(U16) }) }

note:
┌─ stress/abi_encoding_stress.fe:47:5
Expand Down Expand Up @@ -565,7 +565,7 @@ note:
┌─ stress/abi_encoding_stress.fe:57:16
57return self.my_bytes.to_mem()
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 100, inner: Numeric(U8) }) }

note:
┌─ stress/abi_encoding_stress.fe:59:5
Expand Down Expand Up @@ -948,14 +948,14 @@ note:
┌─ stress/abi_encoding_stress.fe:76:22
76my_addrs=self.my_addrs.to_mem(),
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 5, inner: Address }) }
77my_u128=self.my_u128,
78my_string=self.my_string.to_mem(),
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: String(FeString { max_size: 10 }) }
79my_u16s=self.my_u16s.to_mem(),
^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 255, inner: Numeric(U16) }) }
80my_bool=self.my_bool,
81my_bytes=self.my_bytes.to_mem()
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 100, inner: Numeric(U8) }) }


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/analyzer/tests/analysis.rs
expression: "build_snapshot(&files, module, &db)"
expression: "build_snapshot(&files, module_id, &db)"

---
note:
Expand Down Expand Up @@ -72,7 +72,7 @@ note:
┌─ features/address_bytes10_map.fe:5:16
5return self.bar[key].to_mem()
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: Array(Array { size: 10, inner: Numeric(U8) }) }

note:
┌─ features/address_bytes10_map.fe:7:5
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/tests/snapshots/analysis__assert.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/analyzer/tests/analysis.rs
expression: "build_snapshot(\"features/assert.fe\", &src, module, &db)"
expression: "build_snapshot(&files, module_id, &db)"

---
note:
Expand Down Expand Up @@ -247,6 +247,6 @@ note:
┌─ features/assert.fe:20:23
20assert false, self.my_string.to_mem()
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod(ToMem)
^^^^^^^^^^^^^^^^^^^^^ BuiltinValueMethod { method: ToMem, typ: String(FeString { max_size: 5 }) }


Loading

0 comments on commit adbff60

Please sign in to comment.