-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement type aliases (#2112)
* . * . * . * . * stash * . * . * . * remove tyalias as an hir type * namings * . * clippy * move to collector * working? * working? * move test to new_ssa * resolve type alias name in module * . * comments * review * move test to test_data folder * type aliases cannot be used in type namespace * more efficient? * remove comment * use interner for id * . * Rework def_interner storage of aliases * Update crates/noirc_frontend/src/ast/type_alias.rs Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> * Update crates/noirc_frontend/src/ast/type_alias.rs Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> * Update crates/noirc_frontend/src/ast/type_alias.rs Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> * Update crates/noirc_frontend/src/hir/def_collector/dc_mod.rs Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> * Update crates/noirc_frontend/src/hir/resolution/resolver.rs Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> * typ -> type --------- Co-authored-by: ethan-000 <ethan_000@outlook.com> Co-authored-by: Ethan-000 <s2026080@ed.ac.uk> Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
- Loading branch information
1 parent
920a900
commit ce94cb4
Showing
16 changed files
with
393 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "type_aliases" | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = [2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use dep::std; | ||
|
||
type Foo<T> = [T; 2]; | ||
|
||
type Bar = Field; | ||
|
||
type Three = Two<u8>; | ||
type Two<A> = One<A, u32>; | ||
type One<A, B> = (A, B); | ||
|
||
struct MyStruct { | ||
foo: Bar, | ||
} | ||
|
||
fn main(x : [Field; 2]) { | ||
let a: Foo<Field> = [1, 2]; | ||
assert(a[0] != x[0]); | ||
|
||
let b: Bar = 2; | ||
assert(x[0] == b); | ||
|
||
let c: u8 = 1; | ||
let d: u32 = 2; | ||
let e: Three = (c, d); | ||
assert(e.0 == 1); | ||
|
||
let s = MyStruct { | ||
foo: 10 | ||
}; | ||
assert(s.foo == 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::{Ident, UnresolvedGenerics, UnresolvedType}; | ||
use iter_extended::vecmap; | ||
use noirc_errors::Span; | ||
use std::fmt::Display; | ||
|
||
/// Ast node for type aliases | ||
#[derive(Clone, Debug)] | ||
pub struct NoirTypeAlias { | ||
pub name: Ident, | ||
pub generics: UnresolvedGenerics, | ||
pub typ: UnresolvedType, | ||
pub span: Span, | ||
} | ||
|
||
impl NoirTypeAlias { | ||
pub fn new( | ||
name: Ident, | ||
generics: UnresolvedGenerics, | ||
typ: UnresolvedType, | ||
span: Span, | ||
) -> NoirTypeAlias { | ||
NoirTypeAlias { name, generics, typ, span } | ||
} | ||
} | ||
|
||
impl Display for NoirTypeAlias { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let generics = vecmap(&self.generics, |generic| generic.to_string()); | ||
write!(f, "type {}<{}> = {}", self.name, generics.join(", "), self.typ) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.