Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Native tests. #28449

Open
wants to merge 21 commits into
base: mainnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/target
/tmp/
/temp/
**.idea/
*.DS_Store
.vscode
Expand All @@ -23,4 +24,4 @@ sccache*/
*.bat

# environment
.env
.env
2 changes: 2 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ workspace = true
[dependencies.leo-compiler]
workspace = true

[dependencies.leo-disassembler]
workspace = true

[dependencies.leo-errors]
workspace = true

Expand Down Expand Up @@ -190,6 +193,9 @@ version = "0.15.7"
[dependencies.indexmap]
workspace = true

[dependencies.num_cpus]
version = "1.16.0"

[dependencies.rand]
workspace = true

Expand Down
18 changes: 17 additions & 1 deletion compiler/ast/src/functions/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{Identifier, Node, NodeID, simple_node_impl};

use leo_span::Span;

use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::fmt;

Expand All @@ -27,6 +28,8 @@ pub struct Annotation {
// TODO: Consider using a symbol instead of an identifier.
/// The name of the annotation.
pub identifier: Identifier,
/// The data associated with the annotation.
pub data: IndexMap<Identifier, Option<String>>,
/// A span locating where the annotation occurred in the source.
pub span: Span,
/// The ID of the node.
Expand All @@ -37,6 +40,19 @@ simple_node_impl!(Annotation);

impl fmt::Display for Annotation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "@{}", self.identifier)
let data = match self.data.is_empty() {
true => "".to_string(),
false => {
let mut string = String::new();
for (key, value) in self.data.iter() {
match value {
None => string.push_str(&format!("{key},")),
Some(value) => string.push_str(&format!("{key} = \"{value}\",")),
}
}
format!("({string})")
}
};
write!(f, "@{}{}", self.identifier, data)
}
}
10 changes: 10 additions & 0 deletions compiler/ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ use leo_errors::{AstError, Result};
///
/// The [`Ast`] type represents a Leo program as a series of recursive data types.
/// These data types form a tree that begins from a [`Program`] type root.
// TODO: Clean up by removing the `Ast` type and renaming the exiting `Program` type to `Ast`.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Ast {
pub ast: Program,
Expand All @@ -81,6 +82,15 @@ impl Ast {
Self { ast: program }
}

/// Combines the two ASTs into a single AST.
/// The ASTs are combined by extending the components of the first AST with the components of the second AST.
pub fn combine(&mut self, other: Self) {
let Program { imports, stubs, program_scopes } = other.ast;
self.ast.imports.extend(imports);
self.ast.stubs.extend(stubs);
self.ast.program_scopes.extend(program_scopes);
}

/// Returns a reference to the inner program AST representation.
pub fn as_repr(&self) -> &Program {
&self.ast
Expand Down
6 changes: 3 additions & 3 deletions compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,6 @@ pub trait ProgramReconstructor: StatementReconstructor {
fn reconstruct_program_scope(&mut self, input: ProgramScope) -> ProgramScope {
ProgramScope {
program_id: input.program_id,
structs: input.structs.into_iter().map(|(i, c)| (i, self.reconstruct_struct(c))).collect(),
mappings: input.mappings.into_iter().map(|(id, mapping)| (id, self.reconstruct_mapping(mapping))).collect(),
functions: input.functions.into_iter().map(|(i, f)| (i, self.reconstruct_function(f))).collect(),
consts: input
.consts
.into_iter()
Expand All @@ -454,6 +451,9 @@ pub trait ProgramReconstructor: StatementReconstructor {
_ => unreachable!("`reconstruct_const` can only return `Statement::Const`"),
})
.collect(),
structs: input.structs.into_iter().map(|(i, c)| (i, self.reconstruct_struct(c))).collect(),
mappings: input.mappings.into_iter().map(|(id, mapping)| (id, self.reconstruct_mapping(mapping))).collect(),
functions: input.functions.into_iter().map(|(i, f)| (i, self.reconstruct_function(f))).collect(),
span: input.span,
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/ast/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,10 @@ pub trait ProgramVisitor<'a>: StatementVisitor<'a> {
}

fn visit_program_scope(&mut self, input: &'a ProgramScope) {
input.consts.iter().for_each(|(_, c)| (self.visit_const(c)));
input.structs.iter().for_each(|(_, c)| (self.visit_struct(c)));

input.mappings.iter().for_each(|(_, c)| (self.visit_mapping(c)));

input.functions.iter().for_each(|(_, c)| (self.visit_function(c)));

input.consts.iter().for_each(|(_, c)| (self.visit_const(c)));
}

fn visit_stub(&mut self, _input: &'a Stub) {}
Expand Down
Loading
Loading