Skip to content

Commit

Permalink
Hack lib ingot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
g-r-a-n-t committed Dec 15, 2021
1 parent cc236ae commit 794684a
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 95 deletions.
25 changes: 22 additions & 3 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ impl Item {
pub fn items(&self, db: &dyn AnalyzerDb) -> Rc<IndexMap<String, Item>> {
match self {
Item::Ingot(ingot) => ingot
.lib_module(db)
.expect("ingot is missing a lib file")
.items(db),
.lib_items(db),
Item::Module(module) => module.items(db),
Item::Type(_) => todo!("cannot access items in types yet"),
Item::GenericType(_)
Expand Down Expand Up @@ -362,6 +360,27 @@ impl IngotId {
db.ingot_lib_module(*self).value
}

pub fn lib_items(&self, db: &dyn AnalyzerDb) -> Rc<IndexMap<String, Item>> {
let lib_module = self.lib_module(db).expect("missing lib module");
let items = lib_module.items(db);
let ajacent_modules = lib_module.adjacent_modules(db);

let items = items
.deref()
.clone()
.into_iter()
.chain(
ajacent_modules
.deref()
.clone()
.into_iter()
.map(|(name, module)| (name, Item::Module(module)))
)
.collect();

Rc::new(items)
}

pub fn diagnostics(&self, db: &dyn AnalyzerDb) -> Vec<Diagnostic> {
let mut diagnostics = vec![];
self.sink_diagnostics(db, &mut diagnostics);
Expand Down
184 changes: 92 additions & 92 deletions crates/analyzer/tests/snapshots/analysis__basic_ingot.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,86 @@ note:
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Array<u256, 42>


note:
┌─ ingots/basic_ingot/src/bing.fe:5:5
5my_address: address
│ ^^^^^^^^^^^^^^^^^^^ address

note:
┌─ ingots/basic_ingot/src/bing.fe:7:1
7 │ ╭ fn get_42_backend() -> u256:
8 │ │ return std::get_42()
│ ╰────────────────────────^ attributes hash: 17979516652885443340
= FunctionSignature {
self_decl: None,
params: [],
return_type: Ok(
Base(
Numeric(
U256,
),
),
),
}

note:
┌─ ingots/basic_ingot/src/bing.fe:11:4
11 │ ╭ pub fn add(x: u256, y: u256) -> u256:
12 │ │ return x + y
│ ╰───────────────────^ attributes hash: 4022593831796629401
= FunctionSignature {
self_decl: None,
params: [
FunctionParam {
name: "x",
typ: Ok(
Base(
Numeric(
U256,
),
),
),
},
FunctionParam {
name: "y",
typ: Ok(
Base(
Numeric(
U256,
),
),
),
},
],
return_type: Ok(
Base(
Numeric(
U256,
),
),
),
}

note:
┌─ ingots/basic_ingot/src/bing.fe:12:15
12return x + y
│ ^ ^ u256: Value
│ │
u256: Value

note:
┌─ ingots/basic_ingot/src/bing.fe:12:15
12return x + y
│ ^^^^^ u256: Value


note:
┌─ ingots/basic_ingot/src/ding/dong.fe:2:3
Expand All @@ -35,7 +115,7 @@ note:
9 │ ╭ pub fn get_my_baz() -> Baz:
10 │ │ return Baz(my_bool=true, my_u256=26)
│ ╰────────────────────────────────────────────^ attributes hash: 12775921899186886669
│ ╰────────────────────────────────────────────^ attributes hash: 12400766704252115713
= FunctionSignature {
self_decl: None,
Expand All @@ -45,7 +125,7 @@ note:
Struct {
name: "Baz",
id: StructId(
1,
2,
),
field_count: 2,
},
Expand All @@ -71,14 +151,14 @@ note:
┌─ ingots/basic_ingot/src/main.fe:10:16
10return Baz(my_bool=true, my_u256=26)
│ ^^^ TypeConstructor(Struct(Struct { name: "Baz", id: StructId(1), field_count: 2 }))
│ ^^^ TypeConstructor(Struct(Struct { name: "Baz", id: StructId(2), field_count: 2 }))

note:
┌─ ingots/basic_ingot/src/main.fe:12:5
12 │ ╭ pub fn get_my_bing() -> Bong:
13 │ │ return Bong(my_address=address(42))
│ ╰───────────────────────────────────────────^ attributes hash: 9604670028259107253
│ ╰───────────────────────────────────────────^ attributes hash: 4642145316486155293
= FunctionSignature {
self_decl: None,
Expand All @@ -88,7 +168,7 @@ note:
Struct {
name: "Bing",
id: StructId(
2,
0,
),
field_count: 1,
},
Expand Down Expand Up @@ -124,7 +204,7 @@ note:
┌─ ingots/basic_ingot/src/main.fe:13:16
13return Bong(my_address=address(42))
│ ^^^^ TypeConstructor(Struct(Struct { name: "Bing", id: StructId(2), field_count: 1 }))
│ ^^^^ TypeConstructor(Struct(Struct { name: "Bing", id: StructId(0), field_count: 1 }))

note:
┌─ ingots/basic_ingot/src/main.fe:15:5
Expand Down Expand Up @@ -155,7 +235,7 @@ note:
┌─ ingots/basic_ingot/src/main.fe:16:16
16return get_42_backend()
│ ^^^^^^^^^^^^^^ Pure(FunctionId(5))
│ ^^^^^^^^^^^^^^ Pure(FunctionId(0))

note:
┌─ ingots/basic_ingot/src/main.fe:18:5
Expand All @@ -166,7 +246,7 @@ note:
21 │ │ my_u256=42,
22 │ │ my_i8=-1
23 │ │ )
│ ╰─────────^ attributes hash: 12523642377619379671
│ ╰─────────^ attributes hash: 12062965033232055368
= FunctionSignature {
self_decl: None,
Expand All @@ -176,7 +256,7 @@ note:
Struct {
name: "Dyng",
id: StructId(
0,
1,
),
field_count: 3,
},
Expand Down Expand Up @@ -227,7 +307,7 @@ note:
┌─ ingots/basic_ingot/src/main.fe:19:16
19return dong::Dyng(
│ ^^^^^^^^^^ TypeConstructor(Struct(Struct { name: "Dyng", id: StructId(0), field_count: 3 }))
│ ^^^^^^^^^^ TypeConstructor(Struct(Struct { name: "Dyng", id: StructId(1), field_count: 3 }))

note:
┌─ ingots/basic_ingot/src/main.fe:25:5
Expand Down Expand Up @@ -282,89 +362,9 @@ note:
┌─ ingots/basic_ingot/src/main.fe:26:34
26let bing: BingContract = BingContract.create(0)
│ ^^^^^^^^^^^^^^^^^^^ BuiltinAssociatedFunction { contract: ContractId(1), function: Create }
│ ^^^^^^^^^^^^^^^^^^^ BuiltinAssociatedFunction { contract: ContractId(0), function: Create }
27return bing.add(40, 50)
│ ^^^^^^^^ External { contract: ContractId(1), function: FunctionId(6) }


note:
┌─ ingots/basic_ingot/src/bing.fe:2:5
2my_address: address
│ ^^^^^^^^^^^^^^^^^^^ address

note:
┌─ ingots/basic_ingot/src/bing.fe:4:1
4 │ ╭ fn get_42_backend() -> u256:
5 │ │ return std::get_42()
│ ╰────────────────────────^ attributes hash: 17979516652885443340
= FunctionSignature {
self_decl: None,
params: [],
return_type: Ok(
Base(
Numeric(
U256,
),
),
),
}

note:
┌─ ingots/basic_ingot/src/bing.fe:8:4
8 │ ╭ pub fn add(x: u256, y: u256) -> u256:
9 │ │ return x + y
│ ╰───────────────────^ attributes hash: 4022593831796629401
= FunctionSignature {
self_decl: None,
params: [
FunctionParam {
name: "x",
typ: Ok(
Base(
Numeric(
U256,
),
),
),
},
FunctionParam {
name: "y",
typ: Ok(
Base(
Numeric(
U256,
),
),
),
},
],
return_type: Ok(
Base(
Numeric(
U256,
),
),
),
}

note:
┌─ ingots/basic_ingot/src/bing.fe:9:15
9return x + y
│ ^ ^ u256: Value
│ │
u256: Value

note:
┌─ ingots/basic_ingot/src/bing.fe:9:15
9return x + y
│ ^^^^^ u256: Value
│ ^^^^^^^^ External { contract: ContractId(0), function: FunctionId(1) }



Expand Down
2 changes: 2 additions & 0 deletions crates/library/std/src/bar/bar.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
struct Bar:
pass
2 changes: 2 additions & 0 deletions crates/library/std/src/foo.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
struct Foo:
pass
3 changes: 3 additions & 0 deletions crates/test-files/fixtures/ingots/basic_ingot/src/bing.fe
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::foo::Foo
use std::bar::bar::Bar

struct Bing:
my_address: address

Expand Down

0 comments on commit 794684a

Please sign in to comment.