diff --git a/crates/aqua-ls/Cargo.toml b/crates/aqua-ls/Cargo.toml new file mode 100644 index 0000000..a94ca4f --- /dev/null +++ b/crates/aqua-ls/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "aqua-ls" +version.workspace = true +edition.workspace = true + +[dependencies] +compiler = { path = "../compiler" } + +lsp-server = "0.7.6" +lsp-types = "0.95.0" +serde_json = "1.0.113" +serde = { version = "1.0.113", features = ["derive"] } diff --git a/crates/aqua-ls/src/main.rs b/crates/aqua-ls/src/main.rs new file mode 100644 index 0000000..5c7795d --- /dev/null +++ b/crates/aqua-ls/src/main.rs @@ -0,0 +1,91 @@ +use std::error::Error; + +use lsp_types::request::GotoDefinition; +use lsp_types::DiagnosticOptions; +use lsp_types::DiagnosticServerCapabilities; +use lsp_types::GotoDefinitionResponse; +use lsp_types::InitializeParams; +use lsp_types::ServerCapabilities; + +use lsp_server::Connection; +use lsp_server::ExtractError; +use lsp_server::Message; +use lsp_server::Request; +use lsp_server::RequestId; +use lsp_server::Response; + +fn main() -> Result<(), Box> { + let (connection, io_threads) = Connection::stdio(); + let server_capabilities = serde_json::to_value(ServerCapabilities { + diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions { + identifier: None, + inter_file_dependencies: true, + workspace_diagnostics: false, + work_done_progress_options: lsp_types::WorkDoneProgressOptions { + work_done_progress: None, + }, + })), + ..ServerCapabilities::default() + }) + .unwrap(); + let initialization_params = match connection.initialize(server_capabilities) { + Ok(it) => it, + Err(e) => { + if e.channel_is_disconnected() { + io_threads.join()?; + } + return Err(e.into()); + } + }; + main_loop(connection, initialization_params)?; + io_threads.join()?; + Ok(()) +} + +fn main_loop( + connection: Connection, + params: serde_json::Value, +) -> Result<(), Box> { + let _params: InitializeParams = serde_json::from_value(params).unwrap(); + for msg in &connection.receiver { + match msg { + Message::Request(req) => { + if connection.handle_shutdown(&req)? { + return Ok(()); + } + match cast::(req) { + Ok((id, params)) => { + eprintln!("got gotoDefinition request #{id}: {params:?}"); + let result = Some(GotoDefinitionResponse::Array(Vec::new())); + let result = serde_json::to_value(&result).unwrap(); + let resp = Response { + id, + result: Some(result), + error: None, + }; + connection.sender.send(Message::Response(resp))?; + continue; + } + Err(err @ ExtractError::JsonError { .. }) => panic!("{err:?}"), + Err(ExtractError::MethodMismatch(req)) => req, + }; + // ... + } + Message::Response(resp) => { + eprintln!("got response: {resp:?}"); + } + Message::Notification(not) => { + eprintln!("got notification: {not:?}"); + } + } + } + Ok(()) +} + +fn cast(req: Request) -> Result<(RequestId, R::Params), ExtractError> +where + R: lsp_types::request::Request, + R::Params: serde::de::DeserializeOwned, +{ + req.extract(R::METHOD) +} diff --git a/crates/compiler/src/annotate.rs b/crates/compiler/src/annotate.rs index e89f2d3..5a25f58 100644 --- a/crates/compiler/src/annotate.rs +++ b/crates/compiler/src/annotate.rs @@ -19,7 +19,7 @@ use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; use crate::ast::TraitBound; -use crate::ast::TraitDef; +use crate::ast::StmtTraitDef; use crate::ast::Type; use crate::ast::UnresolvedPatField; use crate::infer::Context; @@ -252,15 +252,15 @@ impl StmtTrait { } } -impl TraitDef { - pub fn annotate(&self, ctx: &mut Context) -> TraitDef { +impl StmtTraitDef { + pub fn annotate(&self, ctx: &mut Context) -> StmtTraitDef { let span = self.span; let name = self.name; let generics = self.generics.clone(); let where_clause = self.where_clause.iter().map(|p| p.annotate(ctx)).collect(); let params = self.params.map_values(|t| t.annotate(ctx)); let ty = self.ty.annotate(ctx); - TraitDef::new(span, name, generics, params, ty, where_clause) + StmtTraitDef::new(span, name, generics, params, ty, where_clause) } } diff --git a/crates/compiler/src/apply.rs b/crates/compiler/src/apply.rs index cbeb2a4..0afefd6 100644 --- a/crates/compiler/src/apply.rs +++ b/crates/compiler/src/apply.rs @@ -18,7 +18,7 @@ use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; use crate::ast::TraitBound; -use crate::ast::TraitDef; +use crate::ast::StmtTraitDef; use crate::ast::Type; use crate::map::Map; @@ -76,6 +76,44 @@ impl Type { } } + pub fn expand_assoc(&self) -> Type { + match self { + Type::Cons(x, ts) => { + let ts = ts.iter().map(|t| t.expand_assoc()).collect::>(); + Type::Cons(*x, ts) + } + Type::Assoc(b, x1, _) => b.xts.get(x1).unwrap().expand_assoc(), + Type::Err => Type::Err, + Type::Generic(x) => Type::Generic(*x), + Type::Fun(ts, t) => { + let ts = ts.iter().map(|t| t.expand_assoc()).collect(); + let t = t.expand_assoc(); + Type::Fun(ts, Rc::new(t)) + } + Type::Tuple(ts) => { + let ts = ts.iter().map(|t| t.expand_assoc()).collect(); + Type::Tuple(ts) + } + Type::Record(xts) => { + let xts = xts.iter().map(|(x, t)| (*x, t.expand_assoc())).collect(); + Type::Record(xts) + } + Type::Alias(x, ts) => { + let ts = ts.iter().map(|t| t.expand_assoc()).collect(); + Type::Alias(*x, ts) + } + Type::Array(t, n) => { + let t = Rc::new(t.expand_assoc()); + let n = *n; + Type::Array(t, n) + } + Type::Never => Type::Never, + Type::Unresolved(_) => unreachable!(), + Type::Var(_) => unreachable!(), + Type::Hole => unreachable!(), + } + } + pub fn instantiate(&self, sub: &[(Name, Type)]) -> Type { match self { Type::Cons(x, ts) => { @@ -234,15 +272,15 @@ impl StmtTrait { } } -impl TraitDef { - pub fn map_type(&self, f: &impl Fn(&Type) -> Type) -> TraitDef { +impl StmtTraitDef { + pub fn map_type(&self, f: &impl Fn(&Type) -> Type) -> StmtTraitDef { let span = self.span; let name = self.name; let generics = self.generics.clone(); let params = self.params.iter().map(|(x, t)| (*x, f(t))).collect(); let ty = f(&self.ty); let where_clause = self.where_clause.iter().map(|b| b.map_type(f)).collect(); - TraitDef::new(span, name, generics, params, ty, where_clause) + StmtTraitDef::new(span, name, generics, params, ty, where_clause) } } diff --git a/crates/compiler/src/ast.rs b/crates/compiler/src/ast.rs index 9a397c9..fdc16a1 100644 --- a/crates/compiler/src/ast.rs +++ b/crates/compiler/src/ast.rs @@ -155,8 +155,8 @@ pub struct StmtTrait { pub name: Name, pub generics: Vec, pub where_clause: Vec, - pub defs: Vec>, - pub types: Vec>, + pub defs: Vec>, + pub types: Vec>, } // A trait is like a predicate @@ -325,14 +325,14 @@ impl Stmt { } #[derive(Debug, Clone, Eq, PartialEq)] -pub struct TraitType { +pub struct StmtTraitType { pub span: Span, pub name: Name, pub generics: Vec, } #[derive(Debug, Clone, Eq, PartialEq)] -pub struct TraitDef { +pub struct StmtTraitDef { pub span: Span, pub name: Name, pub generics: Vec, @@ -515,8 +515,8 @@ pub enum Pat { Struct(Span, Type, Name, Vec, Map), Record(Span, Type, Map), Enum(Span, Type, Name, Vec, Name, Rc), - Int(Span, Type, String), - String(Span, Type, String), + Int(Span, Type, Symbol), + String(Span, Type, Symbol), Char(Span, Type, char), Bool(Span, Type, bool), Wildcard(Span, Type), @@ -582,8 +582,8 @@ impl StmtTrait { name: Name, generics: Vec, bounds: Vec, - defs: Vec>, - types: Vec>, + defs: Vec>, + types: Vec>, ) -> StmtTrait { StmtTrait { span, @@ -596,7 +596,7 @@ impl StmtTrait { } } -impl TraitType { +impl StmtTraitType { pub fn new(span: Span, name: Name, generics: Vec) -> Self { Self { span, @@ -661,7 +661,7 @@ impl StmtEnum { } } -impl TraitDef { +impl StmtTraitDef { pub fn new( span: Span, name: Name, diff --git a/crates/compiler/src/builtins/decls.rs b/crates/compiler/src/builtins/decls.rs index 952bb51..1ad33d2 100644 --- a/crates/compiler/src/builtins/decls.rs +++ b/crates/compiler/src/builtins/decls.rs @@ -82,7 +82,7 @@ impl Compiler { // self.declare_duration(); // self.declare_encoding(); self.declare_f32(); - // self.declare_f64(); + self.declare_f64(); // self.declare_file(); // self.declare_function(); // self.declare_i128(); diff --git a/crates/compiler/src/builtins/decls/f32.rs b/crates/compiler/src/builtins/decls/f32.rs index e2ecdd9..cb4b983 100644 --- a/crates/compiler/src/builtins/decls/f32.rs +++ b/crates/compiler/src/builtins/decls/f32.rs @@ -6,18 +6,18 @@ impl Compiler { pub(super) fn declare_f32(&mut self) { self.declare_type("type f32;", BuiltinType { rust: "f32" }); - // self.declare_def( - // "def add_f32(a:f32,b:f32): f32;", - // BuiltinDef { - // rust: "f32::add_f32", - // fun: |_ctx, _t, v| { - // let v0 = v[0].as_f32(); - // let v1 = v[1].as_f32(); - // (v0 + v1).into() - // }, - // }, - // ); - // + self.declare_def( + "def add_f32(a:f32,b:f32): f32;", + BuiltinDef { + rust: "f32::add_f32", + fun: |_ctx, _t, v| { + let v0 = v[0].as_f32(); + let v1 = v[1].as_f32(); + (v0 + v1).into() + }, + }, + ); + // self.declare_def( // "def sub_f32(a:f32,b:f32): f32;", // BuiltinDef { diff --git a/crates/compiler/src/builtins/decls/f64.rs b/crates/compiler/src/builtins/decls/f64.rs index a8851b4..baa4cc1 100644 --- a/crates/compiler/src/builtins/decls/f64.rs +++ b/crates/compiler/src/builtins/decls/f64.rs @@ -5,25 +5,25 @@ use crate::Compiler; impl Compiler { pub(super) fn declare_f64(&mut self) { self.declare_type("type f64;", BuiltinType { rust: "f64" }); - self.declare_def( - "def neg_f64(a:f64): f64;", - BuiltinDef { - rust: "(|v|-v)", - fun: |_ctx, _t, v| { - let v0 = v[0].as_f64(); - (-v0).into() - }, - }, - ); - self.declare_def( - "def pos_f64(a:f64): f64;", - BuiltinDef { - rust: "(|v|v)", - fun: |_ctx, _t, v| { - let v0 = v[0].as_f64(); - v0.into() - }, - }, - ); + // self.declare_def( + // "def neg_f64(a:f64): f64;", + // BuiltinDef { + // rust: "(|v|-v)", + // fun: |_ctx, _t, v| { + // let v0 = v[0].as_f64(); + // (-v0).into() + // }, + // }, + // ); + // self.declare_def( + // "def pos_f64(a:f64): f64;", + // BuiltinDef { + // rust: "(|v|v)", + // fun: |_ctx, _t, v| { + // let v0 = v[0].as_f64(); + // v0.into() + // }, + // }, + // ); } } diff --git a/crates/compiler/src/codegen.rs b/crates/compiler/src/codegen.rs index e10bba2..bfaf741 100644 --- a/crates/compiler/src/codegen.rs +++ b/crates/compiler/src/codegen.rs @@ -18,8 +18,8 @@ use crate::ast::StmtTrait; use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; -use crate::ast::TraitDef; -use crate::ast::TraitType; +use crate::ast::StmtTraitDef; +use crate::ast::StmtTraitType; use crate::ast::Type; use crate::print::Print; @@ -194,7 +194,7 @@ impl<'a, 'b> Rust<'a, 'b> { }) } - fn stmt_def_decl(&mut self, s: &TraitDef) -> std::fmt::Result { + fn stmt_def_decl(&mut self, s: &StmtTraitDef) -> std::fmt::Result { self.kw("def")?; self.space()?; self.name(&s.name)?; @@ -206,7 +206,7 @@ impl<'a, 'b> Rust<'a, 'b> { self.punct(";") } - fn stmt_type_decl(&mut self, s: &TraitType) -> std::fmt::Result { + fn stmt_type_decl(&mut self, s: &StmtTraitType) -> std::fmt::Result { self.kw("type")?; self.space()?; self.name(&s.name)?; diff --git a/crates/compiler/src/display.rs b/crates/compiler/src/display.rs index 8ffb6b4..3d42d79 100644 --- a/crates/compiler/src/display.rs +++ b/crates/compiler/src/display.rs @@ -17,61 +17,103 @@ use crate::ast::StmtEnum; use crate::ast::StmtImpl; use crate::ast::StmtStruct; use crate::ast::StmtTrait; +use crate::ast::StmtTraitDef; +use crate::ast::StmtTraitType; use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; use crate::ast::TraitBound; -use crate::ast::TraitDef; -use crate::ast::TraitType; use crate::ast::Type; use crate::ast::UnresolvedPatField; use crate::builtins::Value; use crate::print::Print; -pub struct Wrapper(T); +pub struct Verbose(T); impl Program { - pub fn display_types(&self) -> Wrapper<&Self> { - Wrapper(self) + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) } } impl StmtImpl { - pub fn display_types(&self) -> Wrapper<&Self> { - Wrapper(self) + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) } } impl Expr { - pub fn display_types(&self) -> Wrapper<&Self> { - Wrapper(self) + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) } } -impl<'a> std::fmt::Display for Wrapper<&'a Program> { +impl Pat { + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) + } +} + +impl Stmt { + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) + } +} + +impl Type { + pub fn verbose(&self) -> Verbose<&Self> { + Verbose(self) + } +} + +impl<'a> std::fmt::Display for Verbose<&'a Program> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut p = Pretty::new(f); - p.type_info = true; + p.verbose = true; p.program(self.0) } } -impl std::fmt::Display for Wrapper<&StmtImpl> { +impl std::fmt::Display for Verbose<&StmtImpl> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut p = Pretty::new(f); - p.type_info = true; + p.verbose = true; p.stmt_impl(self.0) } } -impl std::fmt::Display for Wrapper<&Expr> { +impl std::fmt::Display for Verbose<&Expr> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut p = Pretty::new(f); - p.type_info = true; + p.verbose = true; p.expr(self.0) } } +impl std::fmt::Display for Verbose<&Pat> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut p = Pretty::new(f); + p.verbose = true; + p.pat(self.0) + } +} + +impl std::fmt::Display for Verbose<&Stmt> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut p = Pretty::new(f); + p.verbose = true; + p.stmt(self.0) + } +} + +impl std::fmt::Display for Verbose<&Type> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut p = Pretty::new(f); + p.verbose = true; + p.ty(self.0) + } +} + impl std::fmt::Display for Expr { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { Pretty::new(f).expr(self) @@ -186,7 +228,7 @@ pub struct Pretty<'a, 'b> { f: &'a mut std::fmt::Formatter<'b>, noindent: bool, indent_level: usize, - type_info: bool, + verbose: bool, } impl<'a, 'b> Pretty<'a, 'b> { @@ -195,7 +237,7 @@ impl<'a, 'b> Pretty<'a, 'b> { f, noindent: false, indent_level: 0, - type_info: false, + verbose: false, } } @@ -282,13 +324,12 @@ impl<'a, 'b> Pretty<'a, 'b> { } fn where_clause(&mut self, ts: &[Bound]) -> std::fmt::Result { - if !ts.is_empty() { - self.space()?; - self.kw("where")?; - self.space()?; - self.comma_sep(ts, Self::bound)?; - } - Ok(()) + self.if_nonempty(ts, |this, ts| { + this.space()?; + this.kw("where")?; + this.space()?; + this.comma_sep(ts, Self::bound) + }) } fn stmt_expr(&mut self, s: &Expr) -> std::fmt::Result { @@ -312,11 +353,10 @@ impl<'a, 'b> Pretty<'a, 'b> { self.generics(&s.generics)?; self.space()?; self.brace(|this| { - if !s.variants.is_empty() { - this.indented(|this| this.newline_comma_sep(s.variants.as_ref(), Self::variant))?; - this.newline()?; - } - Ok(()) + this.if_nonempty(&s.variants, |this, s| { + this.indented(|this| this.newline_sep(s, Self::variant))?; + this.newline() + }) }) } @@ -362,7 +402,7 @@ impl<'a, 'b> Pretty<'a, 'b> { }) } - fn stmt_def_decl(&mut self, s: &TraitDef) -> std::fmt::Result { + fn stmt_def_decl(&mut self, s: &StmtTraitDef) -> std::fmt::Result { self.kw("def")?; self.space()?; self.name(&s.name)?; @@ -374,27 +414,24 @@ impl<'a, 'b> Pretty<'a, 'b> { self.punct(";") } - fn stmt_type_decl(&mut self, s: &TraitType) -> std::fmt::Result { + fn stmt_type_decl(&mut self, s: &StmtTraitType) -> std::fmt::Result { self.kw("type")?; self.space()?; self.name(&s.name)?; self.generics(&s.generics)?; - self.space()?; self.punct(";") } fn generics(&mut self, gs: &[Name]) -> std::fmt::Result { - if !gs.is_empty() { - self.brack(|this| this.comma_sep(gs, Self::name))?; - } - Ok(()) + self.if_nonempty(gs, |this, gs| { + this.brack(|this| this.comma_sep(gs, Self::name)) + }) } fn type_args(&mut self, ts: &[Type]) -> std::fmt::Result { - if !ts.is_empty() { - self.brack(|this| this.comma_sep(ts, Self::ty))?; - } - Ok(()) + self.if_nonempty(ts, |this, ts| { + this.brack(|this| this.comma_sep(ts, Self::ty)) + }) } fn expr_args(&mut self, es: &[Expr]) -> std::fmt::Result { @@ -533,9 +570,7 @@ impl<'a, 'b> Pretty<'a, 'b> { self.block(b)?; } Expr::Char(_, _, c) => { - self.lit("'")?; - self.lit(c)?; - self.lit("'")?; + self.char(*c)?; } } Ok(()) @@ -564,20 +599,18 @@ impl<'a, 'b> Pretty<'a, 'b> { self.name(&b.name)?; if !b.ts.is_empty() || !b.xts.is_empty() { self.brack(|this| { - if !b.ts.is_empty() { - this.comma_sep(&b.ts, Self::ty)?; - } - if !b.xts.is_empty() { - if !b.ts.is_empty() { + this.if_nonempty(&b.ts, |this, ts| this.comma_sep(ts, Self::ty))?; + this.if_nonempty(&b.xts, |this, xts| { + this.if_nonempty(&b.ts, |this, ts| { this.punct(",")?; - this.space()?; - } - this.comma_sep(b.xts.as_ref(), |this, (x, t)| { + this.space() + })?; + this.comma_sep(xts, |this, (x, t)| { this.name(x)?; this.punct("=")?; this.ty(t) - })?; - } + }) + })?; Ok(()) })?; } @@ -585,7 +618,7 @@ impl<'a, 'b> Pretty<'a, 'b> { } fn expr(&mut self, expr: &Expr) -> std::fmt::Result { - if self.type_info { + if self.verbose { self.paren(|this| { this._expr(expr)?; this.punct(":")?; @@ -719,7 +752,7 @@ impl<'a, 'b> Pretty<'a, 'b> { } Ok(()) } - + fn agg(&mut self, (x, e0, e1): &(Name, Expr, Expr)) -> std::fmt::Result { self.name(x)?; self.punct("=")?; @@ -792,11 +825,10 @@ impl<'a, 'b> Pretty<'a, 'b> { Type::Array(t, n) => { self.brack(|ctx| { ctx.ty(t)?; - if let Some(n) = n { + ctx.if_some(n, |ctx, n| { ctx.punct(";")?; - ctx.lit(n)?; - } - Ok(()) + ctx.lit(n) + }) })?; } Type::Never => { @@ -807,7 +839,7 @@ impl<'a, 'b> Pretty<'a, 'b> { } fn pat(&mut self, p: &Pat) -> std::fmt::Result { - if self.type_info { + if self.verbose { self.paren(|this| { this._pat(p)?; this.punct(":")?; @@ -822,8 +854,8 @@ impl<'a, 'b> Pretty<'a, 'b> { match p { Pat::Unresolved(_, _, path, args) => { self.unresolved_path(path)?; - if let Some(args) = &args { - self.paren(|this| { + self.if_some(args, |this, args| { + this.paren(|this| { this.sep(",", true, args, |this, p| match p { UnresolvedPatField::Named(x, p) => { this.name(x)?; @@ -832,8 +864,8 @@ impl<'a, 'b> Pretty<'a, 'b> { } UnresolvedPatField::Unnamed(p) => this.pat(p), }) - })?; - } + }) + })?; } Pat::Var(_, _, x) => { self.name(x)?; @@ -889,21 +921,18 @@ impl<'a, 'b> Pretty<'a, 'b> { self.name(&seg.name)?; if !seg.ts.is_empty() || !seg.xts.is_empty() { self.brack(|this| { - if !seg.ts.is_empty() { - this.comma_sep(&seg.ts, Self::ty)?; - } - if !seg.xts.is_empty() { - if !seg.ts.is_empty() { + this.if_nonempty(&seg.ts, |this, ts| this.comma_sep(ts, Self::ty))?; + this.if_nonempty(&seg.xts, |this, xts| { + this.if_nonempty(&seg.ts, |this, ts| { this.punct(",")?; - this.space()?; - } - this.comma_sep(seg.xts.as_ref(), |this, (x, t)| { + this.space() + })?; + this.comma_sep(xts, |this, (x, t)| { this.name(x)?; this.punct("=")?; this.ty(t) - })?; - } - Ok(()) + }) + }) })?; } Ok(()) diff --git a/crates/compiler/src/infer.rs b/crates/compiler/src/infer.rs index aabbc58..5616078 100644 --- a/crates/compiler/src/infer.rs +++ b/crates/compiler/src/infer.rs @@ -103,11 +103,11 @@ impl Context { .unwrap_or_else(|| panic!("Unknown variable {x1}")) } - pub fn bind(&mut self, name: Name, b: Binding) { - self.stack.last_mut().unwrap().binds.insert(name, b); + pub fn bind(&mut self, x: Name, b: Binding) { + self.stack.last_mut().unwrap().binds.insert(x, b); } - pub fn scope(&mut self, f: impl FnOnce(&mut Context) -> T) -> T { + pub fn scoped(&mut self, f: impl FnOnce(&mut Context) -> T) -> T { self.stack.push(Scope::new()); let v = f(self); self.stack.pop(); @@ -135,7 +135,9 @@ impl Context { .err(goal.span(), "Unsolved goal", "Could not solve goal"); } } - Program::new(stmts).map_type(&|t| t.apply(&sub)) + let p = Program::new(stmts).map_type(&|t| t.apply(&sub)); + println!("{}", p.verbose()); + p } pub fn declare_stmt(&mut self, s: &Stmt) { @@ -205,7 +207,7 @@ impl Context { } pub fn stmt_def(&mut self, s: &StmtDef) -> StmtDef { - self.scope(|ctx| { + self.scoped(|ctx| { match &s.body { StmtDefBody::UserDefined(e) => { let mut sub = Map::new(); @@ -259,15 +261,13 @@ impl Context { Expr::Unresolved(..) => unreachable!(), Expr::Int(_, t0, v) => { let t1 = Type::i32(); - let v = v.clone(); self.recover(s, s, unify(sub, t0, &t1)); - Expr::Int(s, t0.apply(sub), v) + Expr::Int(s, t0.apply(sub), *v) } Expr::Float(_, t0, v) => { let t1 = Type::f64(); - let v = v.clone(); self.recover(s, s, unify(sub, t0, &t1)); - Expr::Float(s, t0.apply(sub), v) + Expr::Float(s, t0.apply(sub), *v) } Expr::Bool(_, t0, v) => { let t1 = Type::bool(); @@ -277,9 +277,8 @@ impl Context { } Expr::String(_, t0, v) => { let t1 = Type::string(); - let v = v.clone(); self.recover(s, s, unify(sub, t0, &t1)); - Expr::String(s, t0.apply(sub), v) + Expr::String(s, t0.apply(sub), *v) } Expr::Struct(_, t0, x, ts, xes) => { let stmt = self.structs.get(x).unwrap().clone(); @@ -444,7 +443,10 @@ impl Context { Expr::Index(s, t0.apply(sub), e.into(), *i) } Expr::Assoc(span, t0, b, x1, ts1) => { - let stmt = self.traits.get(&b.name).unwrap_or_else(|| panic!("Unknown trait {b}")); + let stmt = self + .traits + .get(&b.name) + .unwrap_or_else(|| panic!("Unknown trait {b}")); let d = stmt.defs.iter().find(|d| &d.name == x1).unwrap(); let gs0 = stmt.generics.clone(); let gs1 = d.generics.clone(); @@ -453,7 +455,7 @@ impl Context { .chain(gs1) .zip(b.ts.clone().into_iter().chain(ts1.clone())) .collect::>(); - let param_ts = d.params.values().map(|t| t.clone()).collect::>(); + let param_ts = d.params.values().cloned().collect::>(); let return_t = d.ty.clone(); let fun_t = Type::Fun(param_ts, Rc::new(return_t)).instantiate(&gsub0); self.recover(s, e.span(), unify(sub, t0, &fun_t)); @@ -547,6 +549,14 @@ fn matches(s: &mut Map, b0: &Bound, b1: &Bound) -> bool { .iter() .zip(b0.ts.iter()) .all(|(t0, t1)| unify(s, t0, t1).is_ok()) + && b0 + .xts + .iter() + .zip(b1.xts.iter()) + .all(|((x0, t0), (x1, t1))| { + assert!(x0 == x1); + unify(s, t0, t1).is_ok() + }) } (Bound::Unresolved(..), _) | (_, Bound::Unresolved(..)) => unreachable!(), (Bound::Err(..), _) | (_, Bound::Err(..)) => true, @@ -609,11 +619,7 @@ fn mgu(t0: &Type, t1: &Type) -> Option> { (Type::Err, _) | (_, Type::Err) => Some(Map::new()), (Type::Generic(x0), Type::Generic(x1)) => (x0 == x1).then(Map::new), (Type::Assoc(tb, x, _), t2) | (t2, Type::Assoc(tb, x, _)) => { - let t3 = tb - .xts - .iter() - .find_map(|(x0, t0)| (x0 == x).then_some(t0)) - .unwrap(); + let t3 = tb.xts.get(x).unwrap(); mgu(t2, t3) } (Type::Hole, _) | (_, Type::Hole) => unreachable!(), diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index 718a34a..ca15f1f 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -34,6 +34,7 @@ pub mod map; pub mod monomorphise; #[cfg(feature = "optimiser")] pub mod opt; +pub mod ordmap; pub mod symbol; // pub mod union_find; // mod visitor; @@ -104,8 +105,8 @@ impl Compiler { pub fn parse( &mut self, - name: impl ToString, input: &str, + name: impl ToString, f: impl for<'a> FnOnce(&mut Parser<'a, &mut Lexer<'a>>) -> T, ) -> Result> { let input: Rc = unindent::unindent(input).into(); diff --git a/crates/compiler/src/lift.rs b/crates/compiler/src/lift.rs index b342516..3b3656b 100644 --- a/crates/compiler/src/lift.rs +++ b/crates/compiler/src/lift.rs @@ -22,8 +22,8 @@ use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; use crate::ast::TraitBound; -use crate::ast::TraitDef; -use crate::ast::TraitType; +use crate::ast::StmtTraitDef; +use crate::ast::StmtTraitType; use crate::ast::Type; use crate::diag::Report; @@ -220,7 +220,7 @@ impl Context { }) } - fn trait_def(&mut self, d: &TraitDef) -> TraitDef { + fn trait_def(&mut self, d: &StmtTraitDef) -> StmtTraitDef { let name = d.name; self.scoped(|ctx| { let span = d.span; @@ -228,16 +228,16 @@ impl Context { let params = d.params.map_values(|t| ctx.ty(&t)); let ty = ctx.ty(&d.ty); let where_clause = d.where_clause.iter().map(|b| ctx.bound(b)).collect(); - TraitDef::new(span, name, generics, params, ty, where_clause) + StmtTraitDef::new(span, name, generics, params, ty, where_clause) }) } - fn trait_type(&mut self, t: &TraitType) -> TraitType { + fn trait_type(&mut self, t: &StmtTraitType) -> StmtTraitType { self.scoped(|ctx| { let span = t.span; let name = t.name; let generics = t.generics.iter().map(|g| ctx.stack.bind(*g)).collect(); - TraitType::new(span, name, generics) + StmtTraitType::new(span, name, generics) }) } diff --git a/crates/compiler/src/opt.rs b/crates/compiler/src/opt.rs index a8a502b..7b1b629 100644 --- a/crates/compiler/src/opt.rs +++ b/crates/compiler/src/opt.rs @@ -6,7 +6,7 @@ use egglog::ast::GenericRunConfig; use egglog::ast::GenericSchedule; use symbol_table::GlobalSymbol; -const LIB: &'static str = include_str!("opt/lib.egg"); +const LIB: &str = include_str!("opt/lib.egg"); pub struct Optimiser { egraph: egglog::EGraph, diff --git a/crates/compiler/src/ordmap.rs b/crates/compiler/src/ordmap.rs new file mode 100644 index 0000000..50ee712 --- /dev/null +++ b/crates/compiler/src/ordmap.rs @@ -0,0 +1,36 @@ +use std::collections::HashMap; +use std::hash::Hash; + +struct OrdMap { + keys: HashMap, + values: Vec, +} + +impl OrdMap { + fn new() -> Self { + OrdMap { + keys: HashMap::new(), + values: Vec::new(), + } + } + + fn insert(&mut self, key: K, value: V) + where + K: Eq + Hash, + { + let index = self.values.len(); + self.keys.insert(key, index); + self.values.push(value); + } + + fn get(&self, key: &K) -> Option<&V> + where + K: Eq + Hash, + { + self.keys.get(key).map(|&index| &self.values[index]) + } + + fn values(&self) -> impl Iterator { + self.values.iter() + } +} diff --git a/crates/compiler/src/parser.rs b/crates/compiler/src/parser.rs index d20a651..51d3d14 100644 --- a/crates/compiler/src/parser.rs +++ b/crates/compiler/src/parser.rs @@ -51,8 +51,8 @@ use crate::ast::StmtTrait; use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; -use crate::ast::TraitDef; -use crate::ast::TraitType; +use crate::ast::StmtTraitDef; +use crate::ast::StmtTraitType; use crate::ast::Type; use crate::ast::UnresolvedPatField; use crate::diag::Report; @@ -586,7 +586,7 @@ where Ok(Spanned::new(s, StmtTrait::new(s, x.v, gs, bs, defs, tys))) } - fn stmt_def_decl(&mut self, follow: Token) -> Result, Span> { + fn stmt_def_decl(&mut self, follow: Token) -> Result, Span> { let t0 = self.expect(Token::Def, follow)?; let x = self.name(follow)?; let gs = self.generics(follow | Token::LParen)?; @@ -596,16 +596,16 @@ where let bs = self.where_clause(follow | Token::SemiColon)?; let t1 = self.expect(Token::SemiColon, follow)?; let s = t0.s + t1.s; - Ok(Spanned::new(s, TraitDef::new(s, x.v, gs, xts.v, t.v, bs))) + Ok(Spanned::new(s, StmtTraitDef::new(s, x.v, gs, xts.v, t.v, bs))) } - fn stmt_type_decl(&mut self, follow: Token) -> Result, Span> { + fn stmt_type_decl(&mut self, follow: Token) -> Result, Span> { let t0 = self.expect(Token::Type, follow)?; let x = self.name(follow)?; let gs = self.generics(follow | Token::Eq | Token::SemiColon)?; let t1 = self.expect(Token::SemiColon, follow)?; let s = t0.s + t1.s; - Ok(Spanned::new(s, TraitType::new(s, x.v, gs))) + Ok(Spanned::new(s, StmtTraitType::new(s, x.v, gs))) } pub fn stmt_impl(&mut self, follow: Token) -> Result, Span> { @@ -946,12 +946,12 @@ where } Token::Int => { let t = self.next(); - let v = self.text(t).to_owned(); + let v = self.text(t).into(); Pat::Int(t.s, Type::Hole, v) } Token::String => { let t = self.next(); - let v = self.text(t).to_owned(); + let v = self.text(t).into(); Pat::String(t.s, Type::Hole, v) } Token::Char => { diff --git a/crates/compiler/src/print.rs b/crates/compiler/src/print.rs index 8bc9f02..066e408 100644 --- a/crates/compiler/src/print.rs +++ b/crates/compiler/src/print.rs @@ -167,6 +167,30 @@ pub trait Print<'b> { self.group(fun, "[", "]") } + fn if_nonempty( + &mut self, + items: &[T], + f: impl Fn(&mut Self, &[T]) -> std::fmt::Result, + ) -> std::fmt::Result { + if items.is_empty() { + Ok(()) + } else { + f(self, items) + } + } + + fn if_some( + &mut self, + item: &Option, + f: impl Fn(&mut Self, &T) -> std::fmt::Result, + ) -> std::fmt::Result { + if let Some(item) = item { + f(self, item) + } else { + Ok(()) + } + } + fn name(&mut self, s: &Name) -> std::fmt::Result { write!(self.fmt(), "{}", &s.data) } @@ -185,6 +209,12 @@ pub trait Print<'b> { self.punct("\"") } + fn char(&mut self, c: char) -> std::fmt::Result { + self.punct("'")?; + self.lit(c)?; + self.punct("'") + } + fn scope( &mut self, items: &[T], diff --git a/crates/compiler/src/resolve.rs b/crates/compiler/src/resolve.rs index 8fa92d6..42856fb 100644 --- a/crates/compiler/src/resolve.rs +++ b/crates/compiler/src/resolve.rs @@ -20,8 +20,8 @@ use crate::ast::StmtType; use crate::ast::StmtTypeBody; use crate::ast::StmtVar; use crate::ast::TraitBound; -use crate::ast::TraitDef; -use crate::ast::TraitType; +use crate::ast::StmtTraitDef; +use crate::ast::StmtTraitType; use crate::ast::Type; use crate::ast::UnresolvedPatField; use crate::diag::Report; @@ -290,7 +290,7 @@ impl Context { }) } - fn trait_def(&mut self, s: &TraitDef) -> TraitDef { + fn trait_def(&mut self, s: &StmtTraitDef) -> StmtTraitDef { self.scoped(|ctx| { s.generics .iter() @@ -301,7 +301,7 @@ impl Context { let params = s.params.iter().map(|p| ctx.param(p)).collect(); let ty = ctx.ty(&s.ty); let where_clause = s.where_clause.iter().map(|p| ctx.bound(p)).collect(); - TraitDef::new(span, name, generics, params, ty, where_clause) + StmtTraitDef::new(span, name, generics, params, ty, where_clause) }) } @@ -1199,7 +1199,7 @@ impl Segment { } } - fn try_instantiate_named(&self, expected: &[Rc]) -> Option> { + fn try_instantiate_named(&self, expected: &[Rc]) -> Option> { if self .xts .iter() @@ -1231,7 +1231,7 @@ fn fields_are_defined(expected: &Map, provided: &Map) -> && expected.keys().all(|x| provided.contains_key(x)) } -fn types_are_defined(expected: &[Rc], provided: &[Rc]) -> bool { +fn types_are_defined(expected: &[Rc], provided: &[Rc]) -> bool { provided.iter().all(|x| { expected .iter() @@ -1243,7 +1243,7 @@ fn types_are_defined(expected: &[Rc], provided: &[Rc]) -> b }) } -fn defs_are_defined(expected: &[Rc], provided: &[Rc]) -> bool { +fn defs_are_defined(expected: &[Rc], provided: &[Rc]) -> bool { provided.iter().all(|x| { expected .iter() diff --git a/crates/compiler/tests/common/mod.rs b/crates/compiler/tests/common/mod.rs index 22f953f..d8e4766 100644 --- a/crates/compiler/tests/common/mod.rs +++ b/crates/compiler/tests/common/mod.rs @@ -23,8 +23,8 @@ use compiler::ast::StmtType; use compiler::ast::StmtTypeBody; use compiler::ast::StmtVar; use compiler::ast::TraitBound; -use compiler::ast::TraitDef; -use compiler::ast::TraitType; +use compiler::ast::StmtTraitDef; +use compiler::ast::StmtTraitType; use compiler::ast::Type; use compiler::lexer::Span; @@ -32,52 +32,31 @@ use compiler::lexer::Span; #[macro_export] macro_rules! check { ($a:expr, $b:expr) => { - assert!($a == $b, "\n(a) {}\n\n(b) {}", $a, $b); + assert!($a == $b, "{}", { + let a_str = format!("{}", $a); + let b_str = format!("{}", $b); + if a_str != b_str { + common::diff(a_str, b_str) + } else { + let a_str = format!("{}", $a.verbose()); + let b_str = format!("{}", $b.verbose()); + if a_str != b_str { + common::diff(a_str, b_str) + } else { + let a_str = format!("{:#?}", $a); + let b_str = format!("{:#?}", $b); + common::diff(a_str, b_str) + } + } + }); }; - (@debug; $a:expr, $b:expr) => { + ($a:expr, $b:expr, $msg:literal) => {{ + let msg = indoc::indoc!($msg); + check!($a.val, $b); assert!( - $a == $b, - "\n{}", - common::diff(format!("{:#?}", $a), format!("{:#?}", $b)) - ); - }; - ($a:expr, $b:expr, $b_msg:literal) => {{ - let b_msg = indoc::indoc!($b_msg); - assert!( - $a.val == $b, - "{}", - common::diff(format!("{:#?}", $a.val), format!("{:#?}", $b)) - ); - assert!( - $a.msg == b_msg, - "{}", - common::diff($a.msg, b_msg.to_string()) - ); - }}; - (@typed; $a:expr, $b:expr) => {{ - assert!( - $a == $b, - "\n{}", - common::diff( - $a.display_types().to_string(), - $b.display_types().to_string() - ) - ); - }}; - (@typed; $a:expr, $b:expr, $b_msg:literal) => {{ - let b_msg = indoc::indoc!($b_msg); - assert!( - $a.val == $b, - "{}", - common::diff( - $a.val.display_types().to_string(), - $b.display_types().to_string() - ) - ); - assert!( - $a.msg == b_msg, + $a.msg == msg, "{}", - common::diff($a.msg, b_msg.to_string()) + common::diff($a.msg, msg.to_string()) ); }}; } @@ -104,8 +83,8 @@ pub fn stmt_trait Stmt { StmtTrait::new( span(), @@ -646,12 +625,12 @@ pub fn tr_def( xts: [(&'static str, Type); K], t: Type, qs: [Bound; M], -) -> TraitDef { - TraitDef::new(span(), name(x), app(gs, name), params(xts), t, vec(qs)) +) -> StmtTraitDef { + StmtTraitDef::new(span(), name(x), app(gs, name), params(xts), t, vec(qs)) } -pub fn tr_type(x: &'static str, gs: [&'static str; N]) -> TraitType { - TraitType::new(span(), name(x), app(gs, name)) +pub fn tr_type(x: &'static str, gs: [&'static str; N]) -> StmtTraitType { + StmtTraitType::new(span(), name(x), app(gs, name)) } pub fn stmt_struct( diff --git a/crates/compiler/tests/infer.rs b/crates/compiler/tests/infer.rs index b7a989e..c9bd0ad 100644 --- a/crates/compiler/tests/infer.rs +++ b/crates/compiler/tests/infer.rs @@ -4,21 +4,21 @@ use compiler::ast::Program; #[test] fn test_infer_literal0() { let a = Program::infer("1;").unwrap(); - let b = Program::resolve("1:i32;").unwrap(); + let b = Program::infer("1:i32;").unwrap(); check!(a, b); } #[test] fn test_infer_def0() { let a = Program::infer("def f(): i32 = 0;").unwrap(); - let b = Program::resolve("def f(): i32 = 0:i32;").unwrap(); + let b = Program::infer("def f(): i32 = 0:i32;").unwrap(); check!(a, b); } #[test] fn test_infer_def1() { let a = Program::infer("def f(x: i32): i32 = 0;").unwrap(); - let b = Program::resolve("def f(x: i32): i32 = 0:i32;").unwrap(); + let b = Program::infer("def f(x: i32): i32 = 0:i32;").unwrap(); check!(a, b); } @@ -29,12 +29,12 @@ fn test_infer_def2() { f(0);", ) .unwrap(); - let b = Program::resolve( + let b = Program::infer( "def f(x: i32): i32 = x:i32; (f:fun(i32):i32)(0:i32):i32;", ) .unwrap(); - check!(@typed; a, b); + check!(a, b); } #[test] @@ -42,7 +42,6 @@ fn test_infer_def3() { let a = Program::infer("def f(x: i32): f32 = x;").unwrap_err(); let b = Program::resolve("def f(x: i32): f32 = x:i32;").unwrap(); check!( - @typed; a, b, "Error: Type mismatch @@ -57,252 +56,286 @@ fn test_infer_def3() { ) } -// #[test] -// fn test_infer_def4() { -// let a = Program::infer("def f[T](x: T): T = x;"); -// let b = program([ -// // "def f[T](x: T): T = x:T;"]); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_def5() { -// let a = ok!(" -// def f[T](x: T): T = x; -// f(0); -// "); -// let b = ty!(" -// def f[T](x: T): T = x:T; -// (f[i32]:(fun(i32):i32))(0:i32):i32; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_def6() { -// let a = ok!(" -// def f[T](x: T): T = x; -// f(0); -// f(0.0); -// "); -// let b = ty!(" -// def f[T](x: T): T = x:T; -// (f[i32]:(fun(i32):i32))(0:i32):i32; -// (f[f32]:(fun(f32):f32))(0.0:f32):f32; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_def7() { -// let a = ok!(" -// def f[T](x: T): T = x; -// def g[T](x: T): T = f(x); -// f(0); -// "); -// let b = ty!(" -// def f[T](x: T): T = x:T; -// def g[T](x: T): T = (f[T]:fun(T):T)(x:T):T; -// (f[i32]:(fun(i32):i32))(0:i32):i32; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_def8() { -// let a = ok!(" -// def f[T](x: T): T = f(x); -// "); -// let b = ty!(" -// def f[T](x: T): T = (f[T]:fun(T):T)(x:T):T; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_struct0() { -// let a = ok!(" -// struct Foo(x:i32); -// Foo(x=0); -// "); -// let b = ty!(" -// struct Foo(x:i32); -// Foo(x=(0:i32)):Foo; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_struct1() { -// let a = ok!(" -// struct Foo[T](x:T); -// Foo(x=0); -// "); -// let b = ty!(" -// struct Foo[T](x:T); -// Foo[i32](x=(0:i32)):Foo[i32]; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_struct2() { -// let a = ok!(" -// Foo(x=0); -// struct Foo[T](x:T); -// "); -// let b = ty!(" -// Foo[i32](x=(0:i32)):Foo[i32]; -// struct Foo[T](x:T); -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_struct3() { -// let a = ok!(" -// struct Foo[T](x:T); -// var s = Foo(x=0); -// s.x; -// "); -// let b = ty!(" -// struct Foo[T](x:T); -// var s:Foo[i32] = Foo[i32](x=(0:i32)):Foo[i32]; -// ((s:Foo[i32]).x):i32; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_enum0() { -// let a = ok!(" -// enum Foo { Bar(i32), Baz(f32) } -// Foo::Bar(0); -// "); -// let b = ty!(" -// enum Foo { Bar(i32), Baz(f32) } -// Foo::Bar(0:i32):Foo; -// "); -// assert!(a == b, "{a}\n\n{b}"); -// } -// -// #[test] -// fn test_infer_enum1() { -// let a = ok!(" -// enum Foo[T] { Bar(T), Baz(T) } -// Foo::Bar(0); -// "); -// let b = ty!(" -// enum Foo[T] { Bar(T), Baz(T) } -// Foo[i32]::Bar(0:i32):Foo[i32]; -// "); -// assert!(a == b, "{a}\n\n{b}"); -// } -// -// #[test] -// fn test_infer_impl0() { -// let a = ok!(" -// trait Foo[T] { def f(x: T): T; } -// impl Foo[i32] { def f(x: i32): i32 = x; } -// f(0); -// "); -// let b = ty!(" -// trait Foo[T] { def f(x: T): T; } -// impl Foo[i32] { def f(x: i32): i32 = x:i32; } -// ((Foo[i32]::f):(fun(i32):i32))(0:i32):i32; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_impl1() { -// let (_, msg) = ng!(" -// trait Foo[T] { def f(x: T): T; } -// impl Foo[f32] { def f(x: i32): i32 = x; } -// f(0);"); -// assert_eq!( -// msg, -// indoc::indoc! {" -// Error: Unsolved goal -// ╭─[test:1:7] -// │ -// 1 │ trait Foo[T] { def f(x: T): T; } -// │ ─┬─ -// │ ╰─── Could not solve goal -// ───╯"} -// ); -// } -// -// #[test] -// fn test_infer_impl2() { -// let a = ok!(" -// trait Foo[T] {} -// def f[T](x: T): T where Foo[T] = x; -// "); -// let b = ty!(" -// trait Foo[T] {} -// def f[T](x: T): T where Foo[T] = x:T; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_impl3() { -// let a = ok!(" -// trait Foo[T] { def f(x: T): T; } -// def g[T](x: T): T where Foo[T] = g(x); -// "); -// let b = ty!(" -// trait Foo[T] { def f(x: T): T; } -// def g[T](x: T): T where Foo[T] = (g[T]:fun(T):T)(x:T):T; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_impl4() { -// let a = ok!(" -// trait Foo[T] { def f(x: T): T; } -// impl[T] Foo[T] { def f(x: T): T = x; } -// "); -// let b = ty!(" -// trait Foo[T] { def f(x: T): T; } -// impl[T] Foo[T] { def f(x: T): T = x:T; } -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_impl5() { -// let a = ok!(" -// trait Foo[T] { def f(x: T): T; } -// def g[T](x: T): T where Foo[T] = f(x); -// "); -// let b = ty!(" -// trait Foo[T] { def f(x: T): T; } -// def g[T](x: T): T where Foo[T] = (Foo[T]::f:fun(T):T)(x:T):T; -// "); -// assert!(a == b, "{}\n\n{}", a.display_types(), b.display_types()); -// } -// -// #[test] -// fn test_infer_impl6() { -// let a = ok!(" -// trait Foo[T] { def f(x: T): T; } -// impl Foo[i32] { def f(x: i32): i32 = x; } -// def g[T](x: T): T where Foo[T] = Foo[T]::f(x); -// "); -// let b = ty!(" -// trait Foo[T] { def f(x: T): T; } -// impl Foo[i32] { def f(x: i32): i32 = x:i32; } -// def g[T](x: T): T where Foo[T] = (Foo[T]::f:fun(T):T)(x:T):T; -// "); -// assert_eq!(a, b, "{a}\n\n{b}"); -// } -// -// // #[test] -// // fn test_infer_add2() { -// // let a = ok!("1 + 1;"); -// // let b = ty!("Add[i32](1:i32, 1:i32):i32"); -// // assert_eq!(a, b, "{a}\n\n{b}"); -// // } +#[test] +fn test_infer_def4() { + let a = Program::infer("def f[T](x: T): T = x;").unwrap(); + let b = Program::infer("def f[T](x: T): T = x:T;").unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_def5() { + let a = Program::infer( + "def f[T](x: T): T = x; + f(0);", + ) + .unwrap(); + let b = Program::infer( + "def f[T](x: T): T = x:T; + (f[i32]:(fun(i32):i32))(0:i32):i32;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_def6() { + let a = Program::infer( + "def f[T](x: T): T = x; + f(0); + f(0.0);", + ) + .unwrap(); + let b = Program::infer( + "def f[T](x: T): T = x:T; + (f[i32]:(fun(i32):i32))(0:i32):i32; + (f[f64]:(fun(f64):f64))(0.0:f64):f64;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_def7() { + let a = Program::infer( + "def f[T](x: T): T = x; + def g[T](x: T): T = f(x); + f(0);", + ) + .unwrap(); + let b = Program::infer( + "def f[T](x: T): T = x:T; + def g[T](x: T): T = (f[T]:fun(T):T)(x:T):T; + (f[i32]:(fun(i32):i32))(0:i32):i32;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_def8() { + let a = Program::infer("def f[T](x: T): T = f(x);").unwrap(); + let b = Program::infer("def f[T](x: T): T = (f[T]:fun(T):T)(x:T):T;").unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_struct0() { + let a = Program::infer( + "struct Foo(x:i32); + Foo(x=0);", + ) + .unwrap(); + let b = Program::infer( + "struct Foo(x:i32); + Foo(x=(0:i32)):Foo;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_struct1() { + let a = Program::infer( + "struct Foo[T](x:T); + Foo(x=0);", + ) + .unwrap(); + let b = Program::infer( + "struct Foo[T](x:T); + Foo[i32](x=(0:i32)):Foo[i32];", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_struct2() { + let a = Program::infer( + "Foo(x=0); + struct Foo[T](x:T);", + ) + .unwrap(); + let b = Program::infer( + "Foo[i32](x=(0:i32)):Foo[i32]; + struct Foo[T](x:T);", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_struct3() { + let a = Program::infer( + "struct Foo[T](x:T); + var s = Foo(x=0); + s.x;", + ) + .unwrap(); + let b = Program::infer( + "struct Foo[T](x:T); + var s:Foo[i32] = Foo[i32](x=(0:i32)):Foo[i32]; + ((s:Foo[i32]).x):i32;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_enum0() { + let a = Program::infer( + "enum Foo { Bar(i32), Baz(f32) } + Foo::Bar(0);", + ) + .unwrap(); + let b = Program::infer( + "enum Foo { Bar(i32), Baz(f32) } + Foo::Bar(0:i32):Foo;", + ) + .unwrap(); + assert!(a == b, "{a}\n\n{b}"); +} + +#[test] +fn test_infer_enum1() { + let a = Program::infer( + "enum Foo[T] { Bar(T), Baz(T) } + Foo::Bar(0);", + ) + .unwrap(); + let b = Program::infer( + "enum Foo[T] { Bar(T), Baz(T) } + Foo[i32]::Bar(0:i32):Foo[i32];", + ) + .unwrap(); + assert!(a == b, "{a}\n\n{b}"); +} + +#[test] +fn test_infer_impl0() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl Foo[i32] { def f(x: i32): i32 = x; } + f(0);", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl Foo[i32] { def f(x: i32): i32 = x:i32; } + ((Foo[i32]::f):(fun(i32):i32))(0:i32):i32; + ", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_impl1() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl Foo[f32] { def f(x: i32): i32 = x; } + f(0);", + ) + .unwrap_err(); + let b = Program::resolve( + "trait Foo[T] { def f(x: T): T; } + impl Foo[f32] { def f(x: i32): i32 = x:i32; } + ((Foo[i32]::f):(fun(i32):i32))(0:i32):i32;", + ) + .unwrap(); + check!( + a, + b, + "Error: Unsolved goal + ╭─[test:3:1] + │ + 3 │ f(0); + │ ┬ + │ ╰── Could not solve goal + ───╯" + ); +} + +#[test] +fn test_infer_impl2() { + let a = Program::infer( + "trait Foo[T] {} + def f[T](x: T): T where Foo[T] = x;", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] {} + def f[T](x: T): T where Foo[T] = x:T;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_impl3() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + def g[T](x: T): T where Foo[T] = g(x);", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] { def f(x: T): T; } + def g[T](x: T): T where Foo[T] = (g[T]:fun(T):T)(x:T):T;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_impl4() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl[T] Foo[T] { def f(x: T): T = x; }", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl[T] Foo[T] { def f(x: T): T = x:T; }", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_impl5() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + def g[T](x: T): T where Foo[T] = f(x);", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] { def f(x: T): T; } + def g[T](x: T): T where Foo[T] = (Foo[T]::f:fun(T):T)(x:T):T;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_impl6() { + let a = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl Foo[i32] { def f(x: i32): i32 = x; } + def g[T](x: T): T where Foo[T] = Foo[T]::f(x);", + ) + .unwrap(); + let b = Program::infer( + "trait Foo[T] { def f(x: T): T; } + impl Foo[i32] { def f(x: i32): i32 = x:i32; } + def g[T](x: T): T where Foo[T] = (Foo[T]::f:fun(T):T)(x:T):T;", + ) + .unwrap(); + check!(a, b); +} + +#[test] +fn test_infer_add0() { + let a = Program::infer("1 + 1;").unwrap(); + let b = Program::infer("Add[i32,i32]::add(1:i32, 1:i32);").unwrap(); + check!(a, b); +} diff --git a/crates/compiler/tests/resolve.rs b/crates/compiler/tests/resolve.rs index 8dc1506..ae5f2c4 100644 --- a/crates/compiler/tests/resolve.rs +++ b/crates/compiler/tests/resolve.rs @@ -69,7 +69,7 @@ fn test_resolve_def0() { stmt_def("f", [], [], Type::i32(), [], expr_int("0")), stmt_expr(expr_call(expr_def("f", []), [])), ]); - check!(@debug; a, b); + check!(a, b); } #[test] diff --git a/experiments/nexmark/output-2m/experiment1-io-plot.pdf b/experiments/nexmark/output-2m/experiment1-io-plot.pdf new file mode 100644 index 0000000..3d9e520 Binary files /dev/null and b/experiments/nexmark/output-2m/experiment1-io-plot.pdf differ diff --git a/experiments/nexmark/output-2m/experiment1-plot.pdf b/experiments/nexmark/output-2m/experiment1-plot.pdf new file mode 100644 index 0000000..c14ae03 Binary files /dev/null and b/experiments/nexmark/output-2m/experiment1-plot.pdf differ diff --git a/experiments/nexmark/output-2m/experiment1-results.json b/experiments/nexmark/output-2m/experiment1-results.json new file mode 100644 index 0000000..3d059c6 --- /dev/null +++ b/experiments/nexmark/output-2m/experiment1-results.json @@ -0,0 +1,186 @@ +{ + "Q1": { + "Flink": [ + 6.805400000000001, + 0.019520245900090754, + 5.636, + 0.03113840072964582 + ], + "Shark (Rust)": [ + 3.3268, + 0.010647065323365044, + 2.831, + 0.015401298646542827 + ] + }, + "Q2": { + "Flink": [ + 5.6196, + 0.019314243448812624, + 5.636, + 0.03113840072964582 + ], + "Shark (Rust)": [ + 2.89, + 0.01001998003990031, + 2.831, + 0.015401298646542827 + ] + }, + "Q3": { + "Flink": [ + 20.3782, + 0.17872481640779458, + 8.0474, + 0.02279122638209743 + ], + "Shark (Rust)": [ + 7.8646, + 0.028959281759049067, + 4.575200000000001, + 0.0074672618810376935 + ], + "FlinkOpt": [ + 8.783199999999999, + 0.05767980582491579, + 8.0474, + 0.02279122638209743 + ], + "SharkOpt (Rust)": [ + 5.291600000000001, + 0.03856734369904147, + 4.575200000000001, + 0.0074672618810376935 + ] + }, + "Q4": { + "Flink": [ + 20.221, + 0.10949885844153784, + 5.438, + 0.022063544592834643 + ], + "Shark (Rust)": [ + 7.8506, + 0.03238271143681466, + 2.9737999999999998, + 0.02029187029329714 + ], + "FlinkOpt": [ + 11.346, + 0.04800416648583752, + 5.438, + 0.022063544592834643 + ], + "SharkOpt (Rust)": [ + 6.0238, + 0.011496086290559988, + 2.9737999999999998, + 0.02029187029329714 + ] + }, + "Q5": { + "Flink": [ + 11.6146, + 0.17044717656799133, + 5.636, + 0.03113840072964582 + ], + "Shark (Rust)": [ + 5.4488, + 0.01549709650224839, + 2.831, + 0.015401298646542827 + ], + "FlinkOpt": [ + 9.811600000000002, + 0.185455762919355, + 5.636, + 0.03113840072964582 + ], + "SharkOpt (Rust)": [ + 4.996999999999999, + 0.005176871642217927, + 2.831, + 0.015401298646542827 + ] + }, + "Q6": { + "Flink": [ + 13.5048, + 0.10746980971417061, + 5.438, + 0.022063544592834643 + ], + "Shark (Rust)": [ + 6.0148, + 0.037058872082134243, + 2.9737999999999998, + 0.02029187029329714 + ], + "FlinkOpt": [ + 11.4832, + 0.10129639677698327, + 5.438, + 0.022063544592834643 + ], + "SharkOpt (Rust)": [ + 5.7978000000000005, + 0.025253910588263515, + 2.9737999999999998, + 0.02029187029329714 + ] + }, + "Q7": { + "Flink": [ + 7.271800000000001, + 0.013347658970771037, + 5.636, + 0.03113840072964582 + ], + "Shark (Rust)": [ + 4.5446, + 0.013544002362669668, + 2.831, + 0.015401298646542827 + ], + "FlinkOpt": [ + 6.5312, + 0.018691174387929728, + 5.636, + 0.03113840072964582 + ], + "SharkOpt (Rust)": [ + 4.486800000000001, + 0.012671227249165681, + 2.831, + 0.015401298646542827 + ] + }, + "Q8": { + "Flink": [ + 15.4208, + 0.19187850322534816, + 8.0474, + 0.02279122638209743 + ], + "Shark (Rust)": [ + 8.602, + 0.031843366656181676, + 4.575200000000001, + 0.0074672618810376935 + ], + "FlinkOpt": [ + 10.4656, + 0.04601999565406335, + 8.0474, + 0.02279122638209743 + ], + "SharkOpt (Rust)": [ + 7.011999999999999, + 0.02905856156109586, + 4.575200000000001, + 0.0074672618810376935 + ] + } +} diff --git a/experiments/nexmark/output-2m/experiment2-plot.pdf b/experiments/nexmark/output-2m/experiment2-plot.pdf new file mode 100644 index 0000000..209f748 Binary files /dev/null and b/experiments/nexmark/output-2m/experiment2-plot.pdf differ diff --git a/experiments/nexmark/output-2m/experiment2-results.json b/experiments/nexmark/output-2m/experiment2-results.json new file mode 100644 index 0000000..8a90551 --- /dev/null +++ b/experiments/nexmark/output-2m/experiment2-results.json @@ -0,0 +1,94 @@ +{ + "Size 100": { + "Flink": [ + 6.957599999999999, + 0.014974645237868097, + 5.636, + 0.03113840072964582 + ], + "Shark": [ + 2.9227999999999996, + 0.008795453370918388, + 2.831, + 0.015401298646542827 + ], + "FlinkOpt": [ + 6.9642, + 0.02607987730032464, + 5.636, + 0.03113840072964582 + ], + "SharkOpt": [ + 2.8915999999999995, + 0.004029888335921996, + 2.831, + 0.015401298646542827 + ] + }, + "Size 1000": { + "Flink": [ + 6.9201999999999995, + 0.03198374587192676, + 5.636, + 0.03113840072964582 + ], + "Shark": [ + 3.0412, + 0.011373653766490388, + 2.831, + 0.015401298646542827 + ], + "FlinkOpt": [ + 6.9384, + 0.03484594667963547, + 5.636, + 0.03113840072964582 + ], + "SharkOpt": [ + 2.9013999999999998, + 0.005885575587824928, + 2.831, + 0.015401298646542827 + ] + }, + "Size 10000": { + "Flink": [ + 40.704, + 0.09903332772355132, + 5.636, + 0.03113840072964582 + ], + "Shark": [ + 4.9766, + 0.15360026041644592, + 2.831, + 0.015401298646542827 + ], + "FlinkOpt": [ + 37.0842, + 0.2870396488292148, + 5.636, + 0.03113840072964582 + ], + "SharkOpt": [ + 2.9167999999999994, + 0.021018087448671445, + 2.831, + 0.015401298646542827 + ] + }, + "Size 100000": { + "Shark": [ + 30.774399999999996, + 0.09207301450479456, + 2.831, + 0.015401298646542827 + ], + "SharkOpt": [ + 2.9406, + 0.015781001235663155, + 2.831, + 0.015401298646542827 + ] + } +} diff --git a/experiments/nexmark/queries/rust/Cargo.lock b/experiments/nexmark/queries/rust/Cargo.lock index ac0ca7c..6b7de26 100644 --- a/experiments/nexmark/queries/rust/Cargo.lock +++ b/experiments/nexmark/queries/rust/Cargo.lock @@ -71,12 +71,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "btree-slab" version = "0.6.1" @@ -149,76 +143,12 @@ dependencies = [ "serde", ] -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - [[package]] name = "futures-core" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "futures-sink" version = "0.3.30" @@ -237,16 +167,11 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -268,20 +193,11 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "halfbrown" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5681137554ddff44396e5f149892c769d45301dd9aa19c51602a89ee214cb0ec" -dependencies = [ - "hashbrown 0.13.2", -] - -[[package]] -name = "hashbrown" -version = "0.13.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +checksum = "8588661a8607108a5ca69cab034063441a0413a0b041c13618a7dd348021ef6f" dependencies = [ - "ahash", + "hashbrown", ] [[package]] @@ -348,23 +264,13 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "macros" version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -413,40 +319,6 @@ dependencies = [ "serde", ] -[[package]] -name = "num" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-complex" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" -dependencies = [ - "num-traits", -] - [[package]] name = "num-conv" version = "0.1.0" @@ -455,34 +327,10 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", - "num-bigint", - "num-integer", "num-traits", ] @@ -520,29 +368,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -615,15 +440,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags", -] - [[package]] name = "runtime" version = "0.0.0" @@ -632,17 +448,15 @@ dependencies = [ "atoi", "btree-slab", "csv-core", - "derive_more", - "futures", + "futures-util", "halfbrown", "itoa", "lexical-parse-float", "macros", - "num", + "num-integer", "rustc-hash", "ryu", "serde", - "serde_derive", "serde_json", "smallvec", "smol_str", @@ -684,12 +498,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.197" @@ -707,7 +515,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -721,15 +529,6 @@ dependencies = [ "serde", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -781,17 +580,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.48" @@ -865,9 +653,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", @@ -881,7 +667,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] [[package]] @@ -903,12 +689,8 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", - "futures-util", - "hashbrown 0.14.3", "pin-project-lite", - "slab", "tokio", "tracing", ] @@ -920,21 +702,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "tracing-core" version = "0.1.32" @@ -1045,5 +815,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn", ] diff --git a/experiments/nexmark/run.py b/experiments/nexmark/run.py index bd440cb..0b5420e 100644 --- a/experiments/nexmark/run.py +++ b/experiments/nexmark/run.py @@ -141,11 +141,15 @@ def f(program, query, data): obj = { 'Q1': { 'Flink': f(flink, 'q1', generate('b')), - 'Rust': f(rust, 'q1', generate('b')) + 'Rust': f(rust, 'q1', generate('b')), + 'FlinkOpt': f(flink, 'q1-opt', generate('b')), + 'RustOpt': f(rust, 'q1-opt', generate('b')) }, 'Q2': { 'Flink': f(flink, 'q2', generate('b')), 'Rust': f(rust, 'q2', generate('b')), + 'FlinkOpt': f(flink, 'q2-opt', generate('b')), + 'RustOpt': f(rust, 'q2-opt', generate('b')) }, 'Q3': { 'Flink': f(flink, 'q3', generate('ap')),