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

Debugger. #28441

Draft
wants to merge 28 commits into
base: mainnet
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f2c0167
Interpreter.
mikebenfield Oct 23, 2024
eadf559
Breakpoints, mapping fixes, respect project structure, cleanup.
mikebenfield Nov 12, 2024
ce1ec05
support Rand core functions
mikebenfield Nov 13, 2024
f5bb2b1
version fix
mikebenfield Nov 13, 2024
24254bf
some doc comments
mikebenfield Nov 14, 2024
9ee9df6
some doc comments
mikebenfield Nov 14, 2024
18818da
await
mikebenfield Nov 14, 2024
4ad3ec7
check for empty frames
mikebenfield Nov 14, 2024
f6b27b6
fix
mikebenfield Nov 14, 2024
4ee88a1
doc fix
mikebenfield Nov 14, 2024
fe2da9c
futures in tuple return
mikebenfield Nov 14, 2024
aa691db
Address review comments.
mikebenfield Nov 15, 2024
8901f1d
Recursively destroy spans of REPL-read code.
mikebenfield Nov 15, 2024
0f7a623
rename interpret to debug
mikebenfield Nov 18, 2024
148183f
self.signer, self.caller, and block.height
mikebenfield Nov 18, 2024
b2f7fd7
Aleo VM interpretation and misc
mikebenfield Nov 19, 2024
334881c
rest of Aleo commands
mikebenfield Nov 21, 2024
94638be
setting top level values
mikebenfield Nov 21, 2024
7b9e525
conditional fix
mikebenfield Nov 22, 2024
b2b0513
Use dialoguer for prompts with history.
mikebenfield Nov 22, 2024
a453ad3
use a default caller address if not using Leo project structure
mikebenfield Nov 22, 2024
fc08264
Interpreter struct into separate file
mikebenfield Nov 22, 2024
c48afb3
call SnarkVM's implementation of ToBits
mikebenfield Nov 22, 2024
64c995b
prettier prompts
mikebenfield Nov 22, 2024
bc314c3
still prettier messages
mikebenfield Nov 22, 2024
d0ade71
interpreter testing
mikebenfield Nov 22, 2024
18cf244
access registers using Register::Access
mikebenfield Nov 25, 2024
358e6a6
track spans for code entered at the REPL
mikebenfield Nov 26, 2024
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
25 changes: 25 additions & 0 deletions Cargo.lock

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

23 changes: 20 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ members = [
"compiler/span",
"docs/grammar",
"errors",
"interpreter",
"leo/package",
"tests/test-framework",
"utils/disassembler",
Expand All @@ -60,6 +61,10 @@ version = "2.3.1"
path = "./errors"
version = "2.3.1"

[workspace.dependencies.leo-interpreter]
path = "./interpreter"
version = "2.3.0"

[workspace.dependencies.leo-package]
path = "./leo/package"
version = "2.3.1"
Expand All @@ -84,6 +89,9 @@ version = "2.3.1"
version = "0.1.24"
default-features = false

[workspace.dependencies.colored]
version = "2.0"

[workspace.dependencies.indexmap]
version = "2.6"
features = [ "serde" ]
Expand All @@ -95,6 +103,10 @@ version = "0.13.0"
version = "0.8"
default-features = false

[workspace.dependencies.rand_chacha]
version = "0.3.0"
default-features = false

[workspace.dependencies.regex]
version = "1.11.1"

Expand All @@ -109,6 +121,9 @@ features = [ "derive", "rc" ]
version = "1.0"
features = [ "preserve_order" ]

[workspace.dependencies.tempfile]
version = "3.13"

[workspace.dependencies.toml]
version = "0.8"
features = [ "preserve_order" ]
Expand Down Expand Up @@ -145,6 +160,9 @@ workspace = true
[dependencies.leo-errors]
workspace = true

[dependencies.leo-interpreter]
workspace = true

[dependencies.leo-package]
workspace = true

Expand All @@ -165,7 +183,7 @@ version = "4.5"
features = [ "derive", "env", "color", "unstable-styles" ]

[dependencies.colored]
version = "2.0"
workspace = true

[dependencies.dotenvy]
version = "0.15.7"
Expand All @@ -177,8 +195,7 @@ workspace = true
workspace = true

[dependencies.rand_chacha]
version = "0.3.0"
default-features = false
workspace = true

[dependencies.self_update]
version = "0.41.0"
Expand Down
2 changes: 1 addition & 1 deletion compiler/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ workspace = true
version = "3.1.1"

[dev-dependencies.tempfile]
version = "3.13"
workspace = true

[features]
default = [ ]
Expand Down
34 changes: 33 additions & 1 deletion compiler/parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use crate::{Token, tokenizer::*};

use leo_ast::*;
use leo_errors::{Result, emitter::Handler};
use leo_errors::{ParserError, Result, emitter::Handler};
use leo_span::{Span, span::BytePos};

use snarkvm::prelude::Network;
Expand All @@ -49,3 +49,35 @@ pub fn parse<N: Network>(

tokens.parse_program()
}

pub fn parse_expression<N: Network>(
handler: &Handler,
node_builder: &NodeBuilder,
source: &str,
start_pos: BytePos,
) -> Result<Expression> {
let mut context = ParserContext::<N>::new(handler, node_builder, crate::tokenize(source, start_pos)?);

let expression = context.parse_expression()?;
if context.token.token == Token::Eof {
Ok(expression)
} else {
Err(ParserError::unexpected(context.token.token, Token::Eof, context.token.span).into())
}
}

pub fn parse_statement<N: Network>(
handler: &Handler,
node_builder: &NodeBuilder,
source: &str,
start_pos: BytePos,
) -> Result<Statement> {
let mut context = ParserContext::<N>::new(handler, node_builder, crate::tokenize(source, start_pos)?);

let statement = context.parse_statement()?;
if context.token.token == Token::Eof {
Ok(statement)
} else {
Err(ParserError::unexpected(context.token.token, Token::Eof, context.token.span).into())
}
}
2 changes: 1 addition & 1 deletion compiler/span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl SourceMap {
}

/// Find the source file containing `pos`.
fn find_source_file(&self, pos: BytePos) -> Option<Rc<SourceFile>> {
pub fn find_source_file(&self, pos: BytePos) -> Option<Rc<SourceFile>> {
Some(self.inner.borrow().source_files[self.find_source_file_index(pos)?].clone())
}

Expand Down
50 changes: 50 additions & 0 deletions errors/src/errors/interpreter_halt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (C) 2019-2024 Aleo Systems Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use std::fmt;

use leo_span::Span;

/// Represents the interpreter halting, which should not be considered an
/// actual runtime error.
#[derive(Clone, Debug, Error)]
pub struct InterpreterHalt {
/// Optional Span where the halt occurred.
span: Option<Span>,

/// User visible message.
message: String,
}

impl InterpreterHalt {
pub fn new(message: String) -> Self {
InterpreterHalt { span: None, message }
}

pub fn new_spanned(message: String, span: Span) -> Self {
InterpreterHalt { span: Some(span), message }
}

pub fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for InterpreterHalt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}
7 changes: 7 additions & 0 deletions errors/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub use self::flattener::*;
pub mod loop_unroller;
pub use self::loop_unroller::*;

pub mod interpreter_halt;
pub use self::interpreter_halt::*;

/// Contains the Package error definitions.
pub mod package;
pub use self::package::*;
Expand Down Expand Up @@ -70,6 +73,8 @@ pub enum LeoError {
/// Represents a Compiler Error in a Leo Error.
#[error(transparent)]
CompilerError(#[from] CompilerError),
#[error(transparent)]
InterpreterHalt(#[from] InterpreterHalt),
/// Represents a Package Error in a Leo Error.
#[error(transparent)]
PackageError(#[from] PackageError),
Expand Down Expand Up @@ -118,6 +123,7 @@ impl LeoError {
UtilError(error) => error.error_code(),
LastErrorCode(_) => unreachable!(),
Anyhow(_) => "SnarkVM Error".to_string(), // todo: implement error codes for snarkvm errors.
InterpreterHalt(_) => "Interpreter Halt".to_string(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we give these a proper error code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. My thought is that unlike the other error variants, InterpreterHalt doesn't necessarily represent undesired/unexpected behavior - the user may be stepping through code perfectly well expecting that an assert may trigger (or whatever).

}
}

Expand All @@ -138,6 +144,7 @@ impl LeoError {
UtilError(error) => error.exit_code(),
LastErrorCode(code) => *code,
Anyhow(_) => 11000, // todo: implement exit codes for snarkvm errors.
InterpreterHalt(_) => 1,
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions interpreter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[package]
name = "leo-interpreter"
version = "2.3.1"
authors = [ "The Leo Team <leo@provable.com>" ]
description = "Interpreter for the Leo programming language"
homepage = "https://leo-lang.org"
repository = "https://github.com/ProvableHQ/leo"
keywords = [
"aleo",
"cryptography",
"leo",
"programming-language",
"zero-knowledge"
]
categories = [ "compilers", "cryptography", "web-programming" ]
include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2021"
rust-version = "1.82.0"

[dependencies.snarkvm]
workspace = true

[dependencies.snarkvm-circuit]
version = "1.0.0"

[dependencies.snarkvm-synthesizer-program]
version = "1.0.0"

[dependencies.leo-ast]
workspace = true

[dependencies.leo-passes]
workspace = true

[dependencies.leo-errors]
workspace = true

[dependencies.leo-package]
workspace = true

[dependencies.leo-parser]
workspace = true

[dependencies.leo-span]
workspace = true

[dependencies.colored]
workspace = true

[dependencies.indexmap]
workspace = true

[dependencies.dialoguer]
version = "0.11.0"
features = [ "history" ]

[dependencies.rand]
workspace = true

[dependencies.rand_chacha]
workspace = true

[dependencies.toml]
workspace = true

[dev-dependencies.leo-test-framework]
path = "../tests/test-framework"

[dev-dependencies.serial_test]
version = "3.1.1"

[dev-dependencies.tempfile]
workspace = true
Loading
Loading