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

Add code checking skeleton #82

Merged
merged 9 commits into from
Feb 2, 2024
Merged
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
21 changes: 15 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"

members = [ "crates/concrete","crates/concrete_ast", "crates/concrete_codegen_mlir", "crates/concrete_driver", "crates/concrete_parser", "crates/concrete_session", "crates/concrete_type_checker"]
members = [ "crates/concrete","crates/concrete_ast", "crates/concrete_codegen_mlir", "crates/concrete_driver", "crates/concrete_parser", "crates/concrete_session", "crates/concrete_check"]

[profile.release]
lto = true
Expand Down
8 changes: 8 additions & 0 deletions crates/concrete_ast/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Range;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Span {
pub from: usize,
Expand All @@ -10,6 +12,12 @@ impl Span {
}
}

impl From<Span> for Range<usize> {
fn from(val: Span) -> Self {
val.from..val.to
}
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct DocString {
contents: String,
Expand Down
17 changes: 11 additions & 6 deletions crates/concrete_ast/src/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
use crate::{common::Ident, statements::Statement, types::TypeSpec};
use crate::{
common::Ident,
statements::Statement,
types::{RefType, TypeSpec},
};

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Expression {
Simple(SimpleExpr),
Value(ValueExpr),
FnCall(FnCallOp),
Match(MatchExpr),
If(IfExpr),
UnaryOp(UnaryOp, Box<Self>),
BinaryOp(Box<Self>, BinaryOp, Box<Self>),
}

// needed for match variants and array accesses
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SimpleExpr {
pub enum ValueExpr {
ConstBool(bool),
ConstChar(char),
ConstInt(u64),
ConstFloat(()),
ConstStr(String),
Path(PathOp),
Deref(PathOp),
AsRef { path: PathOp, ref_type: RefType },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -83,14 +88,14 @@ pub struct IfExpr {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MatchVariant {
pub case: SimpleExpr,
pub case: ValueExpr,
pub block: Vec<Statement>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PathSegment {
FieldAccess(Ident),
ArrayIndex(SimpleExpr),
ArrayIndex(ValueExpr),
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/concrete_ast/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
common::{DocString, GenericParam, Ident},
common::{DocString, GenericParam, Ident, Span},
statements::Statement,
types::TypeSpec,
};
Expand All @@ -17,6 +17,7 @@ pub struct FunctionDecl {
pub struct FunctionDef {
pub decl: FunctionDecl,
pub body: Vec<Statement>,
pub span: Span,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/concrete_ast/src/imports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::common::Ident;
use crate::common::{Ident, Span};

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ImportStmt {
pub module: Vec<Ident>,
pub symbols: Vec<Ident>,
pub span: Span,
}
3 changes: 2 additions & 1 deletion crates/concrete_ast/src/modules.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
common::{DocString, Ident},
common::{DocString, Ident, Span},
constants::ConstantDef,
functions::FunctionDef,
imports::ImportStmt,
Expand All @@ -13,6 +13,7 @@ pub struct Module {
pub imports: Vec<ImportStmt>,
pub name: Ident,
pub contents: Vec<ModuleDefItem>,
pub span: Span,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
33 changes: 33 additions & 0 deletions crates/concrete_ast/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
use crate::common::{DocString, Ident, Span};

#[derive(Clone, Debug, Eq, Hash, PartialEq, Copy)]
pub enum RefType {
Borrow,
MutBorrow,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum TypeSpec {
Simple {
name: Ident,
is_ref: Option<RefType>,
span: Span,
},
Generic {
name: Ident,
is_ref: Option<RefType>,
type_params: Vec<TypeSpec>,
span: Span,
},
Array {
of_type: Box<Self>,
size: Option<u64>,
is_ref: Option<RefType>,
span: Span,
},
}

impl TypeSpec {
pub fn is_ref(&self) -> Option<RefType> {
match self {
TypeSpec::Simple { is_ref, .. } => *is_ref,
TypeSpec::Generic { is_ref, .. } => *is_ref,
TypeSpec::Array { is_ref, .. } => *is_ref,
}
}

pub fn get_name(&self) -> String {
match self {
TypeSpec::Simple { name, .. } => name.name.clone(),
TypeSpec::Generic { name, .. } => name.name.clone(),
TypeSpec::Array { of_type, .. } => format!("[{}]", of_type.get_name()),
}
}
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Expand Down
13 changes: 13 additions & 0 deletions crates/concrete_check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "concrete_check"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ariadne = { version = "0.4.0", features = ["auto-color"] }
concrete_ast = { version = "0.1.0", path = "../concrete_ast" }
concrete_session = { version = "0.1.0", path = "../concrete_session" }
itertools = "0.12.0"
thiserror = "1.0.56"
Loading