remove aliases and gcs

This commit is contained in:
gluax 2022-03-28 07:47:05 -07:00
parent 78b04ff000
commit 877674230a
23 changed files with 3 additions and 176 deletions

View File

@ -1,42 +0,0 @@
// Copyright (C) 2019-2022 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 crate::{Identifier, Type};
use leo_span::Span;
use std::fmt;
use serde::{Deserialize, Serialize};
/// A type alias `type name = represents;`.
///
/// That is, `name` will become another name for `represents`.
/// This does not create a new type, that is, `name` is the same type as `represents`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Alias {
/// The new name for `represents`.
pub name: Identifier,
/// A span for the entire `type name = represents;`.
pub span: Span,
/// The type that `name` will evaluate and is equal to.
pub represents: Type,
}
impl fmt::Display for Alias {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} : {}", self.name.name, self.represents)
}
}

View File

@ -1,18 +0,0 @@
// Copyright (C) 2019-2022 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/>.
pub mod alias;
pub use self::alias::*;

View File

@ -25,9 +25,6 @@
pub mod accesses;
pub use self::accesses::*;
pub mod aliases;
pub use self::aliases::*;
pub mod chars;
pub use self::chars::*;

View File

@ -17,7 +17,7 @@
//! A Leo program consists of import, circuit, and function definitions.
//! Each defined type consists of ast statements and expressions.
use crate::{Alias, DefinitionStatement, Function, FunctionInput, Identifier};
use crate::{Function, FunctionInput, Identifier};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
@ -32,11 +32,6 @@ pub struct Program {
/// Expected main function inputs.
/// Empty after parsing.
pub expected_input: Vec<FunctionInput>,
/// A map from alias names to type aliases.
pub aliases: IndexMap<Identifier, Alias>,
/// A map from constant names to their definitions.
#[serde(with = "crate::common::global_consts_json")]
pub global_consts: IndexMap<Vec<Identifier>, DefinitionStatement>,
/// A map from function names to their definitions.
pub functions: IndexMap<Identifier, Function>,
}
@ -49,11 +44,6 @@ impl AsRef<Program> for Program {
impl fmt::Display for Program {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (_, alias) in self.aliases.iter() {
alias.fmt(f)?;
writeln!(f,)?;
}
writeln!(f,)?;
for (_, function) in self.functions.iter() {
function.fmt(f)?;
writeln!(f,)?;
@ -68,8 +58,6 @@ impl Program {
Self {
name,
expected_input: vec![],
aliases: IndexMap::new(),
global_consts: IndexMap::new(),
functions: IndexMap::new(),
}
}

View File

@ -319,31 +319,12 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
inputs.push(self.reduce_function_input(input)?);
}
let mut aliases = IndexMap::new();
for (name, alias) in program.aliases.iter() {
let represents = self.reduce_type(&alias.represents, &alias.name.span)?;
aliases.insert(
name.clone(),
Alias {
name: alias.name.clone(),
span: alias.span.clone(),
represents,
},
);
}
let mut functions = IndexMap::new();
for (name, function) in program.functions.iter() {
functions.insert(name.clone(), self.reduce_function(function)?);
}
let mut global_consts = IndexMap::new();
for (name, definition) in program.global_consts.iter() {
global_consts.insert(name.clone(), self.reduce_definition(definition)?);
}
self.reducer
.reduce_program(program, inputs, aliases, functions, global_consts)
self.reducer.reduce_program(program, inputs, functions)
}
pub fn reduce_function_input_variable(

View File

@ -291,16 +291,12 @@ pub trait ReconstructingReducer {
&mut self,
program: &Program,
expected_input: Vec<FunctionInput>,
aliases: IndexMap<Identifier, Alias>,
functions: IndexMap<Identifier, Function>,
global_consts: IndexMap<Vec<Identifier>, DefinitionStatement>,
) -> Result<Program> {
Ok(Program {
name: program.name.clone(),
expected_input,
aliases,
functions,
global_consts,
})
}

View File

@ -24,9 +24,7 @@ impl ParserContext<'_> {
/// Returns a [`Program`] AST if all tokens can be consumed and represent a valid Leo program.
///
pub fn parse_program(&mut self) -> Result<Program> {
let mut aliases = IndexMap::new();
let mut functions = IndexMap::new();
let mut global_consts = IndexMap::new();
while self.has_next() {
let token = self.peek()?;
@ -37,27 +35,17 @@ impl ParserContext<'_> {
let (id, function) = self.parse_function_declaration()?;
functions.insert(id, function);
}
Token::Const => {
let (name, global_const) = self.parse_global_const_declaration()?;
global_consts.insert(name, global_const);
}
Token::Function => {
let (id, function) = self.parse_function_declaration()?;
functions.insert(id, function);
}
Token::Type => {
let (name, alias) = self.parse_type_alias()?;
aliases.insert(name, alias);
}
_ => return Err(Self::unexpected_item(token).into()),
}
}
Ok(Program {
name: String::new(),
expected_input: Vec::new(),
aliases,
functions,
global_consts,
})
}
@ -147,17 +135,4 @@ impl ParserContext<'_> {
Ok((variable_names, statement))
}
///
/// Returns a [`(String, Alias)`] AST node if the next tokens represent a type alias declaration.
///
pub fn parse_type_alias(&mut self) -> Result<(Identifier, Alias)> {
let start = self.expect(Token::Type)?;
let name = self.expect_ident()?;
self.expect(Token::Assign)?;
let (represents, _) = self.parse_type()?;
let span = start + self.expect(Token::Semicolon)?;
Ok((name.clone(), Alias { represents, span, name }))
}
}

View File

@ -4,6 +4,4 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions: {}

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const function x() {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const function x() {\\\"}\"}"

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370003]: unexpected EOF\n --> test:3:1\n |\n 3 | const\n | ^^^^^"
- "Error [EPAR0370005]: expected 'function', 'test' -- got 'const'\n --> test:3:1\n |\n 3 | const\n | ^^^^^"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {}\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {}\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}":
identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: (u32, i32)) {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: (u32, i32)) {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> u32 {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> u32 {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> (u32, u32) {\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> (u32, u32) {\\\"}\"}"

View File

@ -4,8 +4,6 @@ expectation: Pass
outputs:
- name: ""
expected_input: []
aliases: {}
global_consts: {}
functions:
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}":
identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}"

View File

@ -1,10 +0,0 @@
/*
namespace: Parse
expectation: Pass
*/
type a = u32;
type b = string;
type c = a;

View File

@ -1,14 +0,0 @@
/*
namespace: Parse
expectation: Pass
*/
const x: u32 = 1u32;
const f: u32 = x;
const x: i32 = 1i32;
const y: string = "hello world";
const x: char = 'b';