Skip to content

Commit

Permalink
Merge pull request #27794 from AleoHQ/feat/futures
Browse files Browse the repository at this point in the history
Feat/futures
  • Loading branch information
d0cd authored Apr 16, 2024
2 parents e7ddc52 + 32aedab commit 13b29db
Show file tree
Hide file tree
Showing 958 changed files with 10,319 additions and 8,770 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acl2.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Leo-ACL2
on: workflow_dispatch
env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 0

# This job can only be run on linux (Ubuntu)
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'docs/**'
- 'documentation/**'
env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 0

jobs:
test-package:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'docs/**'
- 'documentation/**'
env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 0

jobs:
codecov:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 0

jobs:
ubuntu:
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion compiler/ast/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// 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/>.

pub mod location;
pub use location::*;

pub mod identifier;
pub use identifier::*;

Expand All @@ -29,5 +32,4 @@ pub mod node_builder;
pub use node_builder::*;

pub mod static_string;

pub use static_string::*;
6 changes: 5 additions & 1 deletion compiler/ast/src/functions/core_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ pub enum CoreFunction {
GroupToYCoordinate,

SignatureVerify,
FutureAwait,
}

impl CoreFunction {
Expand Down Expand Up @@ -564,6 +565,7 @@ impl CoreFunction {
(sym::group, sym::to_y_coordinate) => Self::GroupToYCoordinate,

(sym::signature, sym::verify) => Self::SignatureVerify,
(sym::Future, sym::Await) => Self::FutureAwait,
_ => return None,
})
}
Expand Down Expand Up @@ -841,13 +843,15 @@ impl CoreFunction {
Self::GroupToYCoordinate => 1,

Self::SignatureVerify => 3,
Self::FutureAwait => 1,
}
}

/// Returns whether or not this function is finalize command.
pub fn is_finalize_command(&self) -> bool {
match self {
CoreFunction::ChaChaRandAddress
CoreFunction::FutureAwait
| CoreFunction::ChaChaRandAddress
| CoreFunction::ChaChaRandBool
| CoreFunction::ChaChaRandField
| CoreFunction::ChaChaRandGroup
Expand Down
88 changes: 0 additions & 88 deletions compiler/ast/src/functions/finalize.rs

This file was deleted.

21 changes: 4 additions & 17 deletions compiler/ast/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ pub use variant::*;
pub mod external;
pub use external::*;

pub mod finalize;
pub use finalize::*;

pub mod input;
pub use input::*;

Expand Down Expand Up @@ -61,8 +58,6 @@ pub struct Function {
pub output_type: Type,
/// The body of the function.
pub block: Block,
/// An optional finalize block
pub finalize: Option<Finalize>,
/// The entire span of the function definition.
pub span: Span,
/// The ID of the node.
Expand All @@ -87,7 +82,6 @@ impl Function {
input: Vec<Input>,
output: Vec<Output>,
block: Block,
finalize: Option<Finalize>,
span: Span,
id: NodeID,
) -> Self {
Expand All @@ -103,7 +97,7 @@ impl Function {
_ => Type::Tuple(TupleType::new(output.iter().map(get_output_type).collect())),
};

Function { annotations, variant, identifier, input, output, output_type, block, finalize, span, id }
Function { annotations, variant, identifier, input, output, output_type, block, span, id }
}

/// Returns function name.
Expand All @@ -117,8 +111,8 @@ impl Function {
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.variant {
Variant::Inline => write!(f, "inline ")?,
Variant::Standard => write!(f, "function ")?,
Variant::Transition => write!(f, "transition ")?,
Variant::Function | Variant::AsyncFunction => write!(f, "function ")?,
Variant::Transition | Variant::AsyncTransition => write!(f, "transition ")?,
}
write!(f, "{}", self.identifier)?;

Expand All @@ -130,18 +124,12 @@ impl Function {
};
write!(f, "({parameters}) -> {returns} {}", self.block)?;

if let Some(finalize) = &self.finalize {
let parameters = finalize.input.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",");
write!(f, " finalize ({parameters}) {}", finalize.block)
} else {
Ok(())
}
Ok(())
}
}

impl From<FunctionStub> for Function {
fn from(function: FunctionStub) -> Self {
let finalize = function.finalize_stub.map(Finalize::from);
Self {
annotations: function.annotations,
variant: function.variant,
Expand All @@ -150,7 +138,6 @@ impl From<FunctionStub> for Function {
output: function.output,
output_type: function.output_type,
block: Block::default(),
finalize,
span: function.span,
id: function.id,
}
Expand Down
25 changes: 23 additions & 2 deletions compiler/ast/src/functions/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@

use serde::{Deserialize, Serialize};

/// Functions are always one of three variants.
/// Functions are always one of five variants.
/// A transition function is permitted the ability to manipulate records.
/// An asynchronous transition function is a transition function that calls an asynchronous function.
/// A regular function is not permitted to manipulate records.
/// An asynchronous function contains on-chain operations.
/// An inline function is directly copied at the call site.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum Variant {
Inline,
Standard,
Function,
Transition,
AsyncTransition,
AsyncFunction,
}

impl Variant {
/// Returns true if the variant is async.
pub fn is_async(self) -> bool {
matches!(self, Variant::AsyncFunction | Variant::AsyncTransition)
}

/// Returns true if the variant is a transition.
pub fn is_transition(self) -> bool {
matches!(self, Variant::Transition | Variant::AsyncTransition)
}

/// Returns true if the variant is a function.
pub fn is_function(self) -> bool {
matches!(self, Variant::AsyncFunction | Variant::Function)
}
}
14 changes: 1 addition & 13 deletions compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait ExpressionReconstructor {
fn reconstruct_call(&mut self, input: CallExpression) -> (Expression, Self::AdditionalOutput) {
(
Expression::Call(CallExpression {
function: Box::new(self.reconstruct_expression(*input.function).0),
function: input.function,
arguments: input.arguments.into_iter().map(|arg| self.reconstruct_expression(arg).0).collect(),
program: input.program,
span: input.span,
Expand Down Expand Up @@ -402,9 +402,6 @@ pub trait StatementReconstructor: ExpressionReconstructor {
(
Statement::Return(ReturnStatement {
expression: self.reconstruct_expression(input.expression).0,
finalize_arguments: input.finalize_arguments.map(|arguments| {
arguments.into_iter().map(|argument| self.reconstruct_expression(argument).0).collect()
}),
span: input.span,
id: input.id,
}),
Expand Down Expand Up @@ -470,15 +467,6 @@ pub trait ProgramReconstructor: StatementReconstructor {
output: input.output,
output_type: input.output_type,
block: self.reconstruct_block(input.block).0,
finalize: input.finalize.map(|finalize| Finalize {
identifier: finalize.identifier,
input: finalize.input,
output: finalize.output,
output_type: finalize.output_type,
block: self.reconstruct_block(finalize.block).0,
span: finalize.span,
id: finalize.id,
}),
span: input.span,
id: input.id,
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/ast/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {

fn visit_return(&mut self, input: &'a ReturnStatement) {
self.visit_expression(&input.expression, &Default::default());
if let Some(arguments) = &input.finalize_arguments {
arguments.iter().for_each(|argument| {
self.visit_expression(argument, &Default::default());
})
}
}
}

Expand Down Expand Up @@ -253,9 +248,6 @@ pub trait ProgramVisitor<'a>: StatementVisitor<'a> {

fn visit_function(&mut self, input: &'a Function) {
self.visit_block(&input.block);
if let Some(finalize) = &input.finalize {
self.visit_block(&finalize.block);
}
}

fn visit_function_stub(&mut self, _input: &'a FunctionStub) {}
Expand Down
2 changes: 0 additions & 2 deletions compiler/ast/src/statement/return_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use std::fmt;
pub struct ReturnStatement {
/// The expression to return to the function caller.
pub expression: Expression,
/// Arguments to the finalize block.
pub finalize_arguments: Option<Vec<Expression>>,
/// The span of `return expression` excluding the semicolon.
pub span: Span,
/// The ID of the node.
Expand Down
Loading

0 comments on commit 13b29db

Please sign in to comment.