From b21a1472592c18b28733082c59a2ee9c7d353027 Mon Sep 17 00:00:00 2001 From: jonathan Date: Sat, 25 Nov 2023 20:29:49 +0100 Subject: [PATCH] Clippy pt 2 --- compiler/src/passes/atomize/atomize.rs | 10 ++-- compiler/src/passes/atomize/mod.rs | 34 +++++++------- .../src/passes/eliminate/eliminate_seq.rs | 4 +- .../src/passes/explicate/explicate_assign.rs | 6 +-- .../src/passes/explicate/explicate_tail.rs | 8 ++-- compiler/src/passes/explicate/mod.rs | 6 +-- compiler/src/passes/parse/grammar.lalrpop | 33 ++++++------- compiler/src/passes/parse/mod.rs | 8 +++- compiler/src/passes/reveal/mod.rs | 46 +++++++++---------- compiler/src/passes/reveal/reveal.rs | 8 ++-- .../passes/validate/constrain/access_field.rs | 6 +-- .../src/passes/validate/constrain/apply.rs | 8 ++-- .../src/passes/validate/constrain/assign.rs | 8 ++-- .../passes/validate/constrain/binary_op.rs | 10 ++-- .../src/passes/validate/constrain/break.rs | 6 +-- .../src/passes/validate/constrain/expr.rs | 40 +++++++++------- compiler/src/passes/validate/constrain/if.rs | 14 +++--- compiler/src/passes/validate/constrain/let.rs | 14 +++--- .../src/passes/validate/constrain/loop.rs | 6 +-- compiler/src/passes/validate/constrain/mod.rs | 6 +-- .../src/passes/validate/constrain/return.rs | 6 +-- compiler/src/passes/validate/constrain/seq.rs | 10 ++-- .../src/passes/validate/constrain/struct.rs | 6 +-- .../src/passes/validate/constrain/unary_op.rs | 6 +-- .../validate/constrain/uncover_globals.rs | 6 +-- compiler/src/passes/validate/constrain/var.rs | 4 +- compiler/src/passes/validate/mod.rs | 12 ++--- compiler/src/passes/validate/resolve.rs | 8 ++-- compiler/src/passes/validate/uniquify/expr.rs | 6 +-- compiler/src/passes/validate/uniquify/fn.rs | 14 +++--- compiler/src/passes/validate/uniquify/mod.rs | 10 ++-- compiler/src/passes/validate/uniquify/type.rs | 6 +-- .../src/passes/validate/uniquify/typedef.rs | 6 +-- 33 files changed, 197 insertions(+), 184 deletions(-) diff --git a/compiler/src/passes/atomize/atomize.rs b/compiler/src/passes/atomize/atomize.rs index 430bfcf..010ffcc 100644 --- a/compiler/src/passes/atomize/atomize.rs +++ b/compiler/src/passes/atomize/atomize.rs @@ -1,6 +1,6 @@ use crate::passes::atomize::{AExpr, Atom, DefAtomized, PrgAtomized}; use crate::passes::parse::types::Type; -use crate::passes::parse::Meta; +use crate::passes::parse::{Meta, Typed}; use crate::passes::reveal::{DefRevealed, PrgRevealed, RExpr}; use crate::utils::gen_sym::{gen_sym, UniqueSym}; @@ -37,8 +37,8 @@ fn atomize_def(def: DefRevealed) -> DefAtomized { } fn atomize_expr<'p>( - expr: Meta>, RExpr<'p>>, -) -> Meta>, AExpr<'p>> { + expr: Typed<'p, RExpr<'p>>, +) -> Typed<'p, AExpr<'p>> { // Keep track of all the priors. These are bindings that should come before evaluating the expression. let mut priors = Vec::new(); @@ -142,8 +142,8 @@ fn atomize_expr<'p>( } fn atomize_atom<'p>( - expr: Meta>, RExpr<'p>>, - priors: &mut Vec<(UniqueSym<'p>, Meta>, AExpr<'p>>)>, + expr: Typed<'p, RExpr<'p>>, + priors: &mut Vec<(UniqueSym<'p>, Typed<'p, AExpr<'p>>)>, ) -> Atom<'p> { if let RExpr::Lit { val } = expr.inner { Atom::Val { val } diff --git a/compiler/src/passes/atomize/mod.rs b/compiler/src/passes/atomize/mod.rs index c38b2be..0152c48 100644 --- a/compiler/src/passes/atomize/mod.rs +++ b/compiler/src/passes/atomize/mod.rs @@ -3,7 +3,7 @@ pub mod atomize; mod tests; use crate::passes::parse::types::Type; -use crate::passes::parse::{BinaryOp, Def, Meta, UnaryOp}; +use crate::passes::parse::{BinaryOp, Def, Meta, Typed, UnaryOp}; use crate::passes::select::std_lib::Std; use crate::passes::validate::{DefValidated, ExprValidated, PrgValidated, TLit}; use crate::utils::gen_sym::UniqueSym; @@ -15,7 +15,7 @@ pub struct PrgAtomized<'p> { pub std: Std<'p>, } -pub type DefAtomized<'p> = Def, &'p str, Meta>, AExpr<'p>>>; +pub type DefAtomized<'p> = Def, &'p str, Typed<'p, AExpr<'p>>>; pub enum AExpr<'p> { Atom { @@ -31,13 +31,13 @@ pub enum AExpr<'p> { }, Let { sym: UniqueSym<'p>, - bnd: Box>, AExpr<'p>>>, - bdy: Box>, AExpr<'p>>>, + bnd: Box>>, + bdy: Box>>, }, If { - cnd: Box>, AExpr<'p>>>, - thn: Box>, AExpr<'p>>>, - els: Box>, AExpr<'p>>>, + cnd: Box>>, + thn: Box>>, + els: Box>>, }, Apply { fun: Atom<'p>, @@ -47,22 +47,22 @@ pub enum AExpr<'p> { sym: UniqueSym<'p>, }, Loop { - bdy: Box>, AExpr<'p>>>, + bdy: Box>>, }, Break { - bdy: Box>, AExpr<'p>>>, + bdy: Box>>, }, Continue, Seq { - stmt: Box>, AExpr<'p>>>, - cnt: Box>, AExpr<'p>>>, + stmt: Box>>, + cnt: Box>>, }, Assign { sym: UniqueSym<'p>, - bnd: Box>, AExpr<'p>>>, + bnd: Box>>, }, Return { - bdy: Box>, AExpr<'p>>>, + bdy: Box>>, }, Struct { sym: UniqueSym<'p>, @@ -123,10 +123,10 @@ impl<'p> From> for DefValidated<'p> { } } -impl<'p> From>, AExpr<'p>>> - for Meta>, ExprValidated<'p>> +impl<'p> From>> + for Typed<'p, ExprValidated<'p>> { - fn from(value: Meta>, AExpr<'p>>) -> Self { + fn from(value: Typed<'p, AExpr<'p>>) -> Self { let inner = match value.inner { AExpr::Atom { atm, .. } => return atm.into(), AExpr::BinaryOp { op, exprs } => ExprValidated::BinaryOp { @@ -193,7 +193,7 @@ impl<'p> From>, AExpr<'p>>> } // Note that casting to Never here is safe because this `From` is only used by the interpreter which doesn't care about the type information. -impl<'p> From> for Meta>, ExprValidated<'p>> { +impl<'p> From> for Typed<'p, ExprValidated<'p>> { fn from(value: Atom<'p>) -> Self { Meta { meta: Type::Never, diff --git a/compiler/src/passes/eliminate/eliminate_seq.rs b/compiler/src/passes/eliminate/eliminate_seq.rs index 6c39468..59dbb38 100644 --- a/compiler/src/passes/eliminate/eliminate_seq.rs +++ b/compiler/src/passes/eliminate/eliminate_seq.rs @@ -5,14 +5,14 @@ use crate::passes::eliminate::eliminate_params::flatten_type; use crate::passes::eliminate::{EExpr, ETail}; use crate::passes::explicate::CExpr; use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, TypeDef}; +use crate::passes::parse::{Meta, Typed, TypeDef}; use crate::utils::gen_sym::UniqueSym; use std::collections::HashMap; pub fn eliminate_seq<'p>( sym: UniqueSym<'p>, ctx: &mut Ctx<'p>, - bnd: Meta>, CExpr<'p>>, + bnd: Typed<'p, CExpr<'p>>, tail: ETail<'p>, defs: &HashMap, TypeDef, &'p str>>, ) -> ETail<'p> { diff --git a/compiler/src/passes/explicate/explicate_assign.rs b/compiler/src/passes/explicate/explicate_assign.rs index 5ca3c78..495e046 100644 --- a/compiler/src/passes/explicate/explicate_assign.rs +++ b/compiler/src/passes/explicate/explicate_assign.rs @@ -1,14 +1,14 @@ use crate::passes::atomize::{AExpr, Atom}; use crate::passes::explicate::explicate::Env; use crate::passes::explicate::{explicate_pred, CExpr, CTail}; -use crate::passes::parse::types::Type; -use crate::passes::parse::Meta; + +use crate::passes::parse::{Meta, Typed}; use crate::passes::validate::TLit; use crate::utils::gen_sym::{gen_sym, UniqueSym}; pub fn explicate_assign<'p>( sym: UniqueSym<'p>, - bnd: Meta>, AExpr<'p>>, + bnd: Typed<'p, AExpr<'p>>, tail: CTail<'p>, env: &mut Env<'_, 'p>, ) -> CTail<'p> { diff --git a/compiler/src/passes/explicate/explicate_tail.rs b/compiler/src/passes/explicate/explicate_tail.rs index 4a7f126..9296e8e 100644 --- a/compiler/src/passes/explicate/explicate_tail.rs +++ b/compiler/src/passes/explicate/explicate_tail.rs @@ -2,12 +2,12 @@ use crate::passes::atomize::{AExpr, Atom}; use crate::passes::explicate::explicate::Env; use crate::passes::explicate::explicate_assign::explicate_assign; use crate::passes::explicate::CTail; -use crate::passes::parse::types::Type; -use crate::passes::parse::Meta; -use crate::utils::gen_sym::{gen_sym, UniqueSym}; + +use crate::passes::parse::{Meta, Typed}; +use crate::utils::gen_sym::{gen_sym}; pub fn explicate_tail<'p>( - expr: Meta>, AExpr<'p>>, + expr: Typed<'p, AExpr<'p>>, env: &mut Env<'_, 'p>, ) -> CTail<'p> { let tmp = gen_sym("return"); diff --git a/compiler/src/passes/explicate/mod.rs b/compiler/src/passes/explicate/mod.rs index 4069007..61ae23b 100644 --- a/compiler/src/passes/explicate/mod.rs +++ b/compiler/src/passes/explicate/mod.rs @@ -9,7 +9,7 @@ mod tests; use crate::passes::atomize::Atom; use crate::passes::parse::types::Type; -use crate::passes::parse::{BinaryOp, Meta, Param, TypeDef, UnaryOp}; +use crate::passes::parse::{BinaryOp, Param, Typed, TypeDef, UnaryOp}; use crate::passes::select::std_lib::Std; use crate::utils::gen_sym::UniqueSym; use std::collections::HashMap; @@ -24,11 +24,11 @@ pub struct PrgExplicated<'p> { pub enum CTail<'p> { Return { - expr: Meta>, Atom<'p>>, + expr: Typed<'p, Atom<'p>>, }, Seq { sym: UniqueSym<'p>, - bnd: Meta>, CExpr<'p>>, + bnd: Typed<'p, CExpr<'p>>, tail: Box>, }, IfStmt { diff --git a/compiler/src/passes/parse/grammar.lalrpop b/compiler/src/passes/parse/grammar.lalrpop index b597115..94a70ed 100644 --- a/compiler/src/passes/parse/grammar.lalrpop +++ b/compiler/src/passes/parse/grammar.lalrpop @@ -1,8 +1,9 @@ use crate::passes::parse::{ BinaryOp, Def, Expr, Lit, Meta, Param, PrgParsed, Span, Type, TypeDef, UnaryOp, }; -use crate::passes::validate::generate_constraints::PartialType; +use crate::passes::validate::partial_type::PartialType; use functor_derive::Functor; +use crate::passes::parse::Spanned; grammar; @@ -92,7 +93,7 @@ pub Program: PrgParsed<'input> = { } } -Def: Def, Meta, Meta, Meta, Lit<'input>, Span>>> = { +Def: Def, Spanned<&'input str>, Spanned, Spanned<&'input str>, Lit<'input>, Span>>> = { "struct" "{" ":" )>> "}" => Def::TypeDef { sym, def: TypeDef::Struct { fields }, @@ -109,7 +110,7 @@ Def: Def, Meta, Meta> = { +Param: Param> = { ":" => Param { mutable: mutable.is_some(), sym, @@ -117,7 +118,7 @@ Param: Param> = { } } -Type: Type> = { +Type: Type> = { "I64" => Type::I64, "U64" => Type::U64, "Bool" => Type::Bool, @@ -142,7 +143,7 @@ Type: Type> = { // Num/Bool/Ident Expr = ExprStmt; -ExprStmt: Expr, Meta, Lit<'input>, Span> = { +ExprStmt: Expr, Spanned<&'input str>, Lit<'input>, Span> = { "let" )?> "=" >> ";" > => Expr::Let { sym, mutable: mutable.is_some(), @@ -157,7 +158,7 @@ ExprStmt: Expr, Meta, Lit<'input>, Sp ExprInStmt, } -ExprInStmt: Expr, Meta, Lit<'input>, Span> = { +ExprInStmt: Expr, Spanned<&'input str>, Lit<'input>, Span> = { "=" >> => Expr::Assign { sym, bnd: Box::new(bnd), @@ -210,7 +211,7 @@ ExprInStmt: Expr, Meta, Lit<'input>, ExprLogicalOr, } -BinaryOps: Expr, Meta, Lit<'input>, Span> = { +BinaryOps: Expr, Spanned<&'input str>, Lit<'input>, Span> = { >> > => Expr::BinaryOp { op, exprs: [Box::new(e1), Box::new(e2)], @@ -250,7 +251,7 @@ UnaryOp: UnaryOp = { "!" => UnaryOp::Not, } -ExprUnary: Expr, Meta, Lit<'input>, Span> = { +ExprUnary: Expr, Spanned<&'input str>, Lit<'input>, Span> = { >> => Expr::UnaryOp { op, expr: Box::new(e), @@ -258,7 +259,7 @@ ExprUnary: Expr, Meta, Lit<'input> ExprAccess, } -ExprAccess: Expr, Meta, Lit<'input>, Span> = { +ExprAccess: Expr, Spanned<&'input str>, Lit<'input>, Span> = { >> "." => Expr::AccessField { strct: Box::new(strct), field, @@ -266,7 +267,7 @@ ExprAccess: Expr, Meta, Lit<'input ExprCall, } -ExprCall: Expr, Meta, Lit<'input>, Span> = { +ExprCall: Expr, Spanned<&'input str>, Lit<'input>, Span> = { >> "(" >> ")" => Expr::Apply { fun: Box::new(fun), args, @@ -274,7 +275,7 @@ ExprCall: Expr, Meta, Lit<'input>, ExprAtom, } -ExprAtom: Expr, Meta, Lit<'input>, Span> = { +ExprAtom: Expr, Spanned<&'input str>, Lit<'input>, Span> = { => Expr::Lit { val: Lit::Int { val, @@ -305,21 +306,21 @@ ExprAtom: Expr, Meta, Lit<'input>, , } -Struct: Expr, Meta, Lit<'input>, Span> = { +Struct: Expr, Spanned<&'input str>, Lit<'input>, Span> = { "{" > "}" => Expr::Struct { sym, fields, }, } -StructArg : (Meta, Meta, Meta, Lit<'input>, Span>>) = { +StructArg : (Spanned<&'input str>, Spanned, Spanned<&'input str>, Lit<'input>, Span>>) = { ":" >, => (sym.clone(), Meta { meta: (l, r - l), inner: Expr::Var { sym } }) } -Never: Expr, Meta, Lit<'input>, Span> = {}; +Never: Expr, Spanned<&'input str>, Lit<'input>, Span> = {}; -Ident: Meta = Spanned; +Ident: Spanned<&'input str> = Spanned; Bool: bool = { "true" => true, @@ -337,4 +338,4 @@ Comma: Vec = { } } -Spanned: Meta = => Meta { meta: (l, r - l), inner }; +Spanned: Spanned = => Meta { meta: (l, r - l), inner }; diff --git a/compiler/src/passes/parse/mod.rs b/compiler/src/passes/parse/mod.rs index de08330..5c90251 100644 --- a/compiler/src/passes/parse/mod.rs +++ b/compiler/src/passes/parse/mod.rs @@ -16,6 +16,7 @@ use functor_derive::Functor; use itertools::Itertools; use std::fmt::Display; use types::Type; +use crate::utils::gen_sym::UniqueSym; /// A parsed program with global definitions and an entry point. #[derive(Display)] @@ -47,8 +48,8 @@ pub enum Def { }, } -pub type DefParsed<'p> = Def, Meta, Meta>>; -pub type ExprParsed<'p> = Expr, Meta, Lit<'p>, Span>; +pub type DefParsed<'p> = Def, Spanned<&'p str>, Spanned>>; +pub type ExprParsed<'p> = Expr, Spanned<&'p str>, Lit<'p>, Span>; #[derive(Clone, Debug)] pub enum TypeDef { @@ -249,6 +250,9 @@ pub struct Meta { pub inner: B, } +pub type Spanned = Meta; +pub type Typed<'p, T> = Meta>, T>; + impl Functor for Meta { type Target = Meta; diff --git a/compiler/src/passes/reveal/mod.rs b/compiler/src/passes/reveal/mod.rs index 72a729b..96efc35 100644 --- a/compiler/src/passes/reveal/mod.rs +++ b/compiler/src/passes/reveal/mod.rs @@ -2,8 +2,8 @@ pub mod reveal; #[cfg(test)] mod tests; -use crate::passes::parse::types::Type; -use crate::passes::parse::{BinaryOp, Def, Meta, UnaryOp}; + +use crate::passes::parse::{BinaryOp, Def, Meta, Typed, UnaryOp}; use crate::passes::select::std_lib::Std; use crate::passes::validate::{DefValidated, ExprValidated, PrgValidated, TLit}; use crate::utils::gen_sym::UniqueSym; @@ -16,7 +16,7 @@ pub struct PrgRevealed<'p> { pub std: Std<'p>, } -pub type DefRevealed<'p> = Def, &'p str, Meta>, RExpr<'p>>>; +pub type DefRevealed<'p> = Def, &'p str, Typed<'p, RExpr<'p>>>; pub enum RExpr<'p> { Lit { @@ -30,50 +30,50 @@ pub enum RExpr<'p> { }, BinaryOp { op: BinaryOp, - exprs: [Box>, RExpr<'p>>>; 2], + exprs: [Box>>; 2], }, UnaryOp { op: UnaryOp, - expr: Box>, RExpr<'p>>>, + expr: Box>>, }, Let { sym: UniqueSym<'p>, - bnd: Box>, RExpr<'p>>>, - bdy: Box>, RExpr<'p>>>, + bnd: Box>>, + bdy: Box>>, }, If { - cnd: Box>, RExpr<'p>>>, - thn: Box>, RExpr<'p>>>, - els: Box>, RExpr<'p>>>, + cnd: Box>>, + thn: Box>>, + els: Box>>, }, Apply { - fun: Box>, RExpr<'p>>>, - args: Vec>, RExpr<'p>>>, + fun: Box>>, + args: Vec>>, }, Loop { - bdy: Box>, RExpr<'p>>>, + bdy: Box>>, }, Break { - bdy: Box>, RExpr<'p>>>, + bdy: Box>>, }, Return { - bdy: Box>, RExpr<'p>>>, + bdy: Box>>, }, Continue, Seq { - stmt: Box>, RExpr<'p>>>, - cnt: Box>, RExpr<'p>>>, + stmt: Box>>, + cnt: Box>>, }, Assign { sym: UniqueSym<'p>, - bnd: Box>, RExpr<'p>>>, + bnd: Box>>, }, Struct { sym: UniqueSym<'p>, - fields: Vec<(&'p str, Meta>, RExpr<'p>>)>, + fields: Vec<(&'p str, Typed<'p, RExpr<'p>>)>, }, AccessField { - strct: Box>, RExpr<'p>>>, + strct: Box>>, field: &'p str, }, } @@ -111,10 +111,10 @@ impl<'p> From> for DefValidated<'p> { } } -impl<'p> From>, RExpr<'p>>> - for Meta>, ExprValidated<'p>> +impl<'p> From>> + for Typed<'p, ExprValidated<'p>> { - fn from(value: Meta>, RExpr<'p>>) -> Self { + fn from(value: Typed<'p, RExpr<'p>>) -> Self { let inner = match value.inner { RExpr::Lit { val } => ExprValidated::Lit { val }, RExpr::BinaryOp { op, exprs } => ExprValidated::BinaryOp { diff --git a/compiler/src/passes/reveal/reveal.rs b/compiler/src/passes/reveal/reveal.rs index f093789..21b9722 100644 --- a/compiler/src/passes/reveal/reveal.rs +++ b/compiler/src/passes/reveal/reveal.rs @@ -1,5 +1,5 @@ -use crate::passes::parse::types::Type; -use crate::passes::parse::Meta; + +use crate::passes::parse::{Meta, Typed}; use crate::passes::reveal::{DefRevealed, PrgRevealed, RExpr}; use crate::passes::validate::{DefValidated, ExprValidated, PrgValidated}; use crate::utils::gen_sym::UniqueSym; @@ -44,9 +44,9 @@ fn reveal_def<'p>( } fn reveal_expr<'p>( - expr: Meta>, ExprValidated<'p>>, + expr: Typed<'p, ExprValidated<'p>>, scope: &mut PushMap, ()>, -) -> Meta>, RExpr<'p>> { +) -> Typed<'p, RExpr<'p>> { let inner = match expr.inner { ExprValidated::Lit { val } => RExpr::Lit { val }, ExprValidated::Var { sym } => { diff --git a/compiler/src/passes/validate/constrain/access_field.rs b/compiler/src/passes/validate/constrain/access_field.rs index c00bf01..ca59c6e 100644 --- a/compiler/src/passes/validate/constrain/access_field.rs +++ b/compiler/src/passes/validate/constrain/access_field.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span, TypeDef}; +use crate::passes::parse::{Meta, Span, Spanned, TypeDef}; use crate::passes::validate::constrain::uncover_globals::{Env, EnvEntry}; use crate::passes::validate::error::TypeError; use crate::passes::validate::partial_type::PartialType; @@ -8,8 +8,8 @@ use crate::passes::validate::constrain::expr::constrain_expr; pub fn constrain_access_field<'p>( env: &mut Env<'_, 'p>, span: Span, - strct: Meta>, - field: Meta, + strct: Spanned>, + field: Spanned<&'p str>, ) -> Result>, TypeError> { let strct = constrain_expr(strct, env)?; diff --git a/compiler/src/passes/validate/constrain/apply.rs b/compiler/src/passes/validate/constrain/apply.rs index d67872c..61b9e16 100644 --- a/compiler/src/passes/validate/constrain/apply.rs +++ b/compiler/src/passes/validate/constrain/apply.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -9,10 +9,10 @@ use crate::utils::expect::expect; pub fn constrain_apply<'p>( env: &mut Env<'_, 'p>, span: Span, - fun: Box>>, - args: Vec>>, + fun: Spanned>, + args: Vec>>, ) -> Result>, TypeError> { - let fun = expr::constrain_expr(*fun, env)?; + let fun = expr::constrain_expr(fun, env)?; let args: Vec<_> = args .into_iter() .map(|arg| expr::constrain_expr(arg, env)) diff --git a/compiler/src/passes/validate/constrain/assign.rs b/compiler/src/passes/validate/constrain/assign.rs index 5b3cb5f..fc824d2 100644 --- a/compiler/src/passes/validate/constrain/assign.rs +++ b/compiler/src/passes/validate/constrain/assign.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::{Env, EnvEntry}; use crate::passes::validate::error::TypeError; @@ -11,10 +11,10 @@ use crate::utils::gen_sym::UniqueSym; pub fn constrain_assign<'p>( env: &mut Env<'_, 'p>, span: Span, - sym: Meta>, - bnd: Box>>, + sym: Spanned>, + bnd: Spanned>, ) -> Result>, TypeError> { - let bnd = expr::constrain_expr(*bnd, env)?; + let bnd = expr::constrain_expr(bnd, env)?; let EnvEntry::Type { mutable, typ } = env.scope[&sym.inner] else { return Err(TypeError::SymbolShouldBeVariable { span: sym.meta }); diff --git a/compiler/src/passes/validate/constrain/binary_op.rs b/compiler/src/passes/validate/constrain/binary_op.rs index 7fae1cc..1fd251d 100644 --- a/compiler/src/passes/validate/constrain/binary_op.rs +++ b/compiler/src/passes/validate/constrain/binary_op.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{BinaryOp, Meta, Span}; +use crate::passes::parse::{BinaryOp, Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -9,8 +9,8 @@ pub fn constrain_binary_op<'p>( env: &mut Env<'_, 'p>, span: Span, op: BinaryOp, - lhs: Box>>, - rhs: Box>>, + lhs: Spanned>, + rhs: Spanned>, ) -> Result>, TypeError> { // input: None = Any but equal, Some = expect this // output: None = Same as input, Some = this @@ -25,8 +25,8 @@ pub fn constrain_binary_op<'p>( BinaryOp::EQ | BinaryOp::NE => (None, Some(PartialType::Bool)), }; - let e1 = expr::constrain_expr(*lhs, env)?; - let e2 = expr::constrain_expr(*rhs, env)?; + let e1 = expr::constrain_expr(lhs, env)?; + let e2 = expr::constrain_expr(rhs, env)?; // Check inputs satisfy constraints if let Some(input) = input { diff --git a/compiler/src/passes/validate/constrain/break.rs b/compiler/src/passes/validate/constrain/break.rs index bb0de38..5584a77 100644 --- a/compiler/src/passes/validate/constrain/break.rs +++ b/compiler/src/passes/validate/constrain/break.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -8,13 +8,13 @@ use crate::passes::validate::{CMeta, ExprConstrained, ExprUniquified}; pub fn constrain_break<'p>( env: &mut Env<'_, 'p>, span: Span, - bdy: Box>>, + bdy: Spanned>, ) -> Result>, TypeError> { let Some(loop_type) = env.loop_type else { return Err(TypeError::BreakOutsideLoop { span }); }; - let bdy = expr::constrain_expr(*bdy, env)?; + let bdy = expr::constrain_expr(bdy, env)?; env.uf .expect_equal(bdy.meta.index, loop_type, |got, expect| { TypeError::MismatchedLoop { diff --git a/compiler/src/passes/validate/constrain/expr.rs b/compiler/src/passes/validate/constrain/expr.rs index 2034823..6613f58 100644 --- a/compiler/src/passes/validate/constrain/expr.rs +++ b/compiler/src/passes/validate/constrain/expr.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Expr, Meta, Span}; +use crate::passes::parse::{Expr, Meta, Spanned}; use crate::passes::validate::constrain::lit::constrain_lit; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -19,51 +19,59 @@ use crate::passes::validate::constrain::unary_op::constrain_unary_op; use crate::passes::validate::constrain::var::constrain_var; pub fn constrain_expr<'p>( - expr: Meta>, + expr: Spanned>, env: &mut Env<'_, 'p>, ) -> Result>, TypeError> { let span = expr.meta; match expr.inner { - Expr::Lit { val } => constrain_lit(env, span, val), - Expr::Var { sym } => constrain_var(env, span, sym), - Expr::UnaryOp { op, expr } => constrain_unary_op(env, span, op, expr), + Expr::Lit { val } => { + constrain_lit(env, span, val) + }, + Expr::Var { sym } => { + constrain_var(env, span, sym) + }, + Expr::UnaryOp { op, expr } => { + constrain_unary_op(env, span, op, *expr) + }, Expr::BinaryOp { op, exprs: [lhs, rhs], - } => constrain_binary_op(env, span, op, lhs, rhs), + } => { + constrain_binary_op(env, span, op, *lhs, *rhs) + }, Expr::Let { sym, mutable, typ, bnd, bdy, - } => constrain_let( - env, span, sym, mutable, typ, bnd, bdy, - ), + } => { + constrain_let(env, span, sym, mutable, typ, *bnd, *bdy) + }, Expr::If { cnd, thn, els } => { - constrain_if(env, span, cnd, thn, els) + constrain_if(env, span, *cnd, *thn, *els) } Expr::Apply { fun, args } => { - constrain_apply(env, span, fun, args) + constrain_apply(env, span, *fun, args) }, Expr::Loop { bdy } => { - constrain_loop(env, span, bdy) + constrain_loop(env, span, *bdy) }, Expr::Break { bdy } => { - constrain_break(env, span, bdy) + constrain_break(env, span, *bdy) } Expr::Continue => { constrain_continue(env, span) } Expr::Return { bdy } => { - constrain_return(env, span, bdy) + constrain_return(env, span, *bdy) } Expr::Seq { stmt, cnt } => { - constrain_seq(env, span, stmt, cnt) + constrain_seq(env, span, *stmt, *cnt) }, Expr::Assign { sym, bnd } => { - constrain_assign(env, span, sym, bnd) + constrain_assign(env, span, sym, *bnd) }, Expr::Struct { sym, fields } => { constrain_struct(env, span, sym, fields) diff --git a/compiler/src/passes/validate/constrain/if.rs b/compiler/src/passes/validate/constrain/if.rs index cabf880..1a912b6 100644 --- a/compiler/src/passes/validate/constrain/if.rs +++ b/compiler/src/passes/validate/constrain/if.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -8,11 +8,11 @@ use crate::passes::validate::{CMeta, ExprConstrained, ExprUniquified}; pub fn constrain_if<'p>( env: &mut Env<'_, 'p>, span: Span, - cnd: Box>>, - thn: Box>>, - els: Box>>, + cnd: Spanned>, + thn: Spanned>, + els: Spanned>, ) -> Result>, TypeError> { - let cnd = expr::constrain_expr(*cnd, env)?; + let cnd = expr::constrain_expr(cnd, env)?; env.uf.expect_type(cnd.meta.index, Type::Bool, |got, _| { TypeError::IfExpectBool { @@ -21,8 +21,8 @@ pub fn constrain_if<'p>( } })?; - let thn = expr::constrain_expr(*thn, env)?; - let els = expr::constrain_expr(*els, env)?; + let thn = expr::constrain_expr(thn, env)?; + let els = expr::constrain_expr(els, env)?; let out_index = env .uf diff --git a/compiler/src/passes/validate/constrain/let.rs b/compiler/src/passes/validate/constrain/let.rs index 433bc97..c87fa30 100644 --- a/compiler/src/passes/validate/constrain/let.rs +++ b/compiler/src/passes/validate/constrain/let.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::{Env, EnvEntry}; use crate::passes::validate::error::TypeError; @@ -9,13 +9,13 @@ use crate::utils::gen_sym::UniqueSym; pub fn constrain_let<'p>( env: &mut Env<'_, 'p>, span: Span, - sym: Meta>, + sym: Spanned>, mutable: bool, - typ: Option>>>, - bnd: Box>>, - bdy: Box>>, + typ: Option>>>, + bnd: Spanned>, + bdy: Spanned>, ) -> Result>, TypeError> { - let bnd = expr::constrain_expr(*bnd, env)?; + let bnd = expr::constrain_expr(bnd, env)?; if let Some(typ) = &typ { env.uf.expect_type(bnd.meta.index, typ.clone(), |got, _| { @@ -34,7 +34,7 @@ pub fn constrain_let<'p>( typ: bnd.meta.index, }, ); - let bdy = expr::constrain_expr(*bdy, env)?; + let bdy = expr::constrain_expr(bdy, env)?; Ok(Meta { meta: CMeta { diff --git a/compiler/src/passes/validate/constrain/loop.rs b/compiler/src/passes/validate/constrain/loop.rs index 1255c02..7ca0d54 100644 --- a/compiler/src/passes/validate/constrain/loop.rs +++ b/compiler/src/passes/validate/constrain/loop.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -8,7 +8,7 @@ use crate::passes::validate::{CMeta, ExprConstrained, ExprUniquified}; pub fn constrain_loop<'p>( env: &mut Env<'_, 'p>, span: Span, - bdy: Box>>, + bdy: Spanned>, ) -> Result>, TypeError> { let loop_type = env.uf.add(PartialType::Never); @@ -19,7 +19,7 @@ pub fn constrain_loop<'p>( return_type: env.return_type, }; - let bdy = expr::constrain_expr(*bdy, &mut env)?; + let bdy = expr::constrain_expr(bdy, &mut env)?; Ok(Meta { meta: CMeta { diff --git a/compiler/src/passes/validate/constrain/mod.rs b/compiler/src/passes/validate/constrain/mod.rs index 9068499..5160639 100644 --- a/compiler/src/passes/validate/constrain/mod.rs +++ b/compiler/src/passes/validate/constrain/mod.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Spanned}; use crate::passes::validate::constrain::def::constrain_def; use crate::passes::validate::error::TypeError; use crate::passes::validate::partial_type::PartialType; @@ -68,7 +68,7 @@ impl<'p> UnionFind> { pub fn expect_type( &mut self, a: UnionIndex, - t: Type>>, + t: Type>>, map_err: impl FnOnce(String, String) -> TypeError, ) -> Result { let t_index = self.type_to_index(t); @@ -85,7 +85,7 @@ impl<'p> UnionFind> { self.expect_equal(a, t_index, map_err) } - pub fn type_to_index(&mut self, t: Type>>) -> UnionIndex { + pub fn type_to_index(&mut self, t: Type>>) -> UnionIndex { let pt = match t { Type::I64 => PartialType::I64, Type::U64 => PartialType::U64, diff --git a/compiler/src/passes/validate/constrain/return.rs b/compiler/src/passes/validate/constrain/return.rs index 2323e6e..63ee2b4 100644 --- a/compiler/src/passes/validate/constrain/return.rs +++ b/compiler/src/passes/validate/constrain/return.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -8,9 +8,9 @@ use crate::passes::validate::{CMeta, ExprConstrained, ExprUniquified}; pub fn constrain_return<'p>( env: &mut Env<'_, 'p>, span: Span, - bdy: Box>>, + bdy: Spanned>, ) -> Result>, TypeError> { - let bdy = expr::constrain_expr(*bdy, env)?; + let bdy = expr::constrain_expr(bdy, env)?; env.uf .expect_equal(bdy.meta.index, env.return_type.inner, |bdy_typ, rtrn| { diff --git a/compiler/src/passes/validate/constrain/seq.rs b/compiler/src/passes/validate/constrain/seq.rs index ecc6e99..4f9d85e 100644 --- a/compiler/src/passes/validate/constrain/seq.rs +++ b/compiler/src/passes/validate/constrain/seq.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -7,11 +7,11 @@ use crate::passes::validate::{CMeta, ExprConstrained, ExprUniquified}; pub fn constrain_seq<'p>( env: &mut Env<'_, 'p>, span: Span, - stmt: Box>>, - cnt: Box>>, + stmt: Spanned>, + cnt: Spanned>, ) -> Result>, TypeError> { - let stmt = expr::constrain_expr(*stmt, env)?; - let cnt = expr::constrain_expr(*cnt, env)?; + let stmt = expr::constrain_expr(stmt, env)?; + let cnt = expr::constrain_expr(cnt, env)?; Ok(Meta { meta: CMeta { diff --git a/compiler/src/passes/validate/constrain/struct.rs b/compiler/src/passes/validate/constrain/struct.rs index c115c6c..69679a5 100644 --- a/compiler/src/passes/validate/constrain/struct.rs +++ b/compiler/src/passes/validate/constrain/struct.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span, TypeDef}; +use crate::passes::parse::{Meta, Span, Spanned, TypeDef}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::{Env, EnvEntry}; use crate::passes::validate::error::TypeError; @@ -11,8 +11,8 @@ use std::collections::{HashMap, HashSet}; pub fn constrain_struct<'p>( env: &mut Env<'_, 'p>, span: Span, - sym: Meta>, - fields: Vec<(Meta, Meta>)>, + sym: Spanned>, + fields: Vec<(Spanned<&'p str>, Spanned>)>, ) -> Result>, TypeError> { // Get the `EnvEntry` from the scope. // This should exist after yeet, but could potentially not be a struct definition. diff --git a/compiler/src/passes/validate/constrain/unary_op.rs b/compiler/src/passes/validate/constrain/unary_op.rs index bbf290e..55e8e36 100644 --- a/compiler/src/passes/validate/constrain/unary_op.rs +++ b/compiler/src/passes/validate/constrain/unary_op.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, Span, UnaryOp}; +use crate::passes::parse::{Meta, Span, Spanned, UnaryOp}; use crate::passes::validate::constrain::expr; use crate::passes::validate::constrain::uncover_globals::Env; use crate::passes::validate::error::TypeError; @@ -9,13 +9,13 @@ pub fn constrain_unary_op<'p>( env: &mut Env<'_, 'p>, span: Span, op: UnaryOp, - expr: Box>>, + expr: Spanned>, ) -> Result>, TypeError> { let typ = match op { UnaryOp::Neg => Type::I64, UnaryOp::Not => Type::Bool, }; - let expr = expr::constrain_expr(*expr, env)?; + let expr = expr::constrain_expr(expr, env)?; env.uf.expect_type(expr.meta.index, typ, |got, expect| { TypeError::OperandExpect { diff --git a/compiler/src/passes/validate/constrain/uncover_globals.rs b/compiler/src/passes/validate/constrain/uncover_globals.rs index a544399..f9fc81d 100644 --- a/compiler/src/passes/validate/constrain/uncover_globals.rs +++ b/compiler/src/passes/validate/constrain/uncover_globals.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Def, Meta, Span, TypeDef}; +use crate::passes::parse::{Def, Spanned, TypeDef}; use crate::passes::validate::error::TypeError; use crate::passes::validate::partial_type::PartialType; use crate::passes::validate::uniquify::{PrgUniquified, BUILT_INS}; @@ -13,7 +13,7 @@ pub struct Env<'a, 'p> { pub uf: &'a mut UnionFind>, pub scope: &'a mut HashMap, EnvEntry<'p>>, pub loop_type: Option, - pub return_type: &'a Meta, + pub return_type: &'a Spanned, } pub enum EnvEntry<'p> { @@ -22,7 +22,7 @@ pub enum EnvEntry<'p> { typ: UnionIndex, }, Def { - def: TypeDef>, Meta>, + def: TypeDef>, Spanned<&'p str>>, }, } diff --git a/compiler/src/passes/validate/constrain/var.rs b/compiler/src/passes/validate/constrain/var.rs index 2d3c86d..ec01ce1 100644 --- a/compiler/src/passes/validate/constrain/var.rs +++ b/compiler/src/passes/validate/constrain/var.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Meta, Span, Spanned}; use crate::passes::validate::constrain::uncover_globals::{Env, EnvEntry}; use crate::passes::validate::error::TypeError; use crate::passes::validate::{CMeta, ExprConstrained}; @@ -7,7 +7,7 @@ use crate::utils::gen_sym::UniqueSym; pub fn constrain_var<'p>( env: &mut Env<'_, 'p>, span: Span, - sym: Meta>, + sym: Spanned>, ) -> Result>, TypeError> { let EnvEntry::Type { typ, .. } = env.scope[&sym.inner] else { return Err(TypeError::SymbolShouldBeVariable { span }); diff --git a/compiler/src/passes/validate/mod.rs b/compiler/src/passes/validate/mod.rs index d7f1be4..8fa031f 100644 --- a/compiler/src/passes/validate/mod.rs +++ b/compiler/src/passes/validate/mod.rs @@ -10,7 +10,7 @@ mod uniquify; pub mod validate; use crate::passes::parse::types::Type; -use crate::passes::parse::{Def, Expr, Lit, Meta, Span}; +use crate::passes::parse::{Def, Expr, Lit, Meta, Span, Spanned, Typed}; use crate::passes::select::std_lib::Std; use crate::utils::gen_sym::UniqueSym; use crate::utils::union_find::{UnionFind, UnionIndex}; @@ -34,16 +34,16 @@ pub struct PrgConstrained<'p> { } pub type DefValidated<'p> = - Def, &'p str, Meta>, ExprValidated<'p>>>; + Def, &'p str, Typed<'p, ExprValidated<'p>>>; pub type ExprValidated<'p> = Expr, &'p str, TLit, Type>>; pub type DefConstrained<'p> = - Def>, Meta, Meta>>; -pub type ExprConstrained<'p> = Expr>, Meta, Lit<'p>, CMeta>; + Def>, Spanned<&'p str>, Meta>>; +pub type ExprConstrained<'p> = Expr>, Spanned<&'p str>, Lit<'p>, CMeta>; pub type DefUniquified<'p> = - Def>, Meta, Meta>>; -pub type ExprUniquified<'p> = Expr>, Meta, Lit<'p>, Span>; + Def>, Spanned<&'p str>, Spanned>>; +pub type ExprUniquified<'p> = Expr>, Spanned<&'p str>, Lit<'p>, Span>; pub struct CMeta { pub span: Span, diff --git a/compiler/src/passes/validate/resolve.rs b/compiler/src/passes/validate/resolve.rs index af8e564..0cdb0ce 100644 --- a/compiler/src/passes/validate/resolve.rs +++ b/compiler/src/passes/validate/resolve.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Expr, Lit, Meta, Param, Span, TypeDef}; +use crate::passes::parse::{Expr, Lit, Meta, Param, Spanned, Typed, TypeDef}; use crate::passes::validate::error::TypeError; use crate::passes::validate::partial_type::PartialType; use crate::passes::validate::{ @@ -54,7 +54,7 @@ fn resolve_def<'p>( } fn resolve_typedef<'p>( - typedef: TypeDef>, Meta>, + typedef: TypeDef>, Spanned<&'p str>>, ) -> TypeDef, &'p str> { match typedef { TypeDef::Struct { fields } => TypeDef::Struct { @@ -65,7 +65,7 @@ fn resolve_typedef<'p>( } } -fn resolve_type(typ: Type>) -> Type { +fn resolve_type(typ: Type>) -> Type { match typ { Type::I64 => Type::I64, Type::U64 => Type::U64, @@ -106,7 +106,7 @@ fn partial_type_to_type<'p>( fn resolve_expr<'p>( expr: Meta>, uf: &mut UnionFind>, -) -> Result>, ExprValidated<'p>>, TypeError> { +) -> Result>, TypeError> { // Type of the expression, if `None` then type is still ambiguous. let typ = partial_type_to_type(expr.meta.index, uf); diff --git a/compiler/src/passes/validate/uniquify/expr.rs b/compiler/src/passes/validate/uniquify/expr.rs index 7892fe3..a509735 100644 --- a/compiler/src/passes/validate/uniquify/expr.rs +++ b/compiler/src/passes/validate/uniquify/expr.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Expr, ExprParsed, Meta, Span}; +use crate::passes::parse::{Expr, ExprParsed, Meta, Spanned}; use crate::passes::validate::error::TypeError; use crate::passes::validate::uniquify::gen_spanned_sym; use crate::passes::validate::uniquify::r#type::uniquify_type; @@ -7,9 +7,9 @@ use crate::utils::gen_sym::UniqueSym; use crate::utils::push_map::PushMap; pub fn uniquify_expr<'p>( - expr: Meta>, + expr: Spanned>, scope: &mut PushMap<&'p str, UniqueSym<'p>>, -) -> Result>, TypeError> { +) -> Result>, TypeError> { let inner = match expr.inner { Expr::Let { sym, diff --git a/compiler/src/passes/validate/uniquify/fn.rs b/compiler/src/passes/validate/uniquify/fn.rs index 217f5fb..bf1c8b5 100644 --- a/compiler/src/passes/validate/uniquify/fn.rs +++ b/compiler/src/passes/validate/uniquify/fn.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Def, ExprParsed, Meta, Param, Span}; +use crate::passes::parse::{Def, ExprParsed, Param, Spanned}; use crate::passes::validate::error::TypeError; use crate::passes::validate::uniquify::expr::uniquify_expr; use crate::passes::validate::uniquify::r#type::uniquify_type; @@ -11,10 +11,10 @@ use std::collections::HashMap; pub fn uniquify_fn<'p>( scope: &mut PushMap<&'p str, UniqueSym<'p>>, - sym: Meta, - params: Vec>>, - typ: Type>, - bdy: Meta>, + sym: Spanned<&'p str>, + params: Vec>>, + typ: Type>, + bdy: Spanned>, ) -> Result, TypeError> { // Generate unique names for the parameters. let iterator = params @@ -55,9 +55,9 @@ pub fn uniquify_fn<'p>( } fn uniquify_param<'p>( - param: &Param>, + param: &Param>, scope: &mut PushMap<&'p str, UniqueSym<'p>>, -) -> Result>>, TypeError> { +) -> Result>>, TypeError> { Ok(Param { sym: uniquify::try_get(param.sym.clone(), scope)?, mutable: param.mutable, diff --git a/compiler/src/passes/validate/uniquify/mod.rs b/compiler/src/passes/validate/uniquify/mod.rs index 325e8dd..7dabfff 100644 --- a/compiler/src/passes/validate/uniquify/mod.rs +++ b/compiler/src/passes/validate/uniquify/mod.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, PrgParsed, Span}; +use crate::passes::parse::{Meta, PrgParsed, Spanned}; use crate::passes::select::std_lib::Std; use crate::passes::validate::error::TypeError; use crate::passes::validate::error::TypeError::{NoMain, UndeclaredVar}; @@ -24,7 +24,7 @@ pub struct PrgUniquified<'p> { pub std: Std<'p>, } -pub static BUILT_INS: Lazy>>>> = +pub static BUILT_INS: Lazy>>>> = Lazy::new(|| { HashMap::from([ ( @@ -80,9 +80,9 @@ impl<'p> PrgParsed<'p> { } fn try_get<'p>( - sym: Meta, + sym: Spanned<&'p str>, scope: &PushMap<&'p str, UniqueSym<'p>>, -) -> Result>, TypeError> { +) -> Result>, TypeError> { scope .get(&sym.inner) .ok_or(UndeclaredVar { @@ -95,7 +95,7 @@ fn try_get<'p>( }) } -fn gen_spanned_sym(sym: Meta) -> Meta { +fn gen_spanned_sym(sym: Spanned<&str>) -> Spanned { Meta { inner: gen_sym(sym.inner), meta: sym.meta, diff --git a/compiler/src/passes/validate/uniquify/type.rs b/compiler/src/passes/validate/uniquify/type.rs index 7b57369..7cbad85 100644 --- a/compiler/src/passes/validate/uniquify/type.rs +++ b/compiler/src/passes/validate/uniquify/type.rs @@ -1,14 +1,14 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Meta, Span}; +use crate::passes::parse::{Spanned}; use crate::passes::validate::error::TypeError; use crate::passes::validate::uniquify::try_get; use crate::utils::gen_sym::UniqueSym; use crate::utils::push_map::PushMap; pub fn uniquify_type<'p>( - typ: Type>, + typ: Type>, scope: &mut PushMap<&'p str, UniqueSym<'p>>, -) -> Result>>, TypeError> { +) -> Result>>, TypeError> { let typ = match typ { Type::I64 => Type::I64, Type::U64 => Type::U64, diff --git a/compiler/src/passes/validate/uniquify/typedef.rs b/compiler/src/passes/validate/uniquify/typedef.rs index 9307f54..ed72763 100644 --- a/compiler/src/passes/validate/uniquify/typedef.rs +++ b/compiler/src/passes/validate/uniquify/typedef.rs @@ -1,4 +1,4 @@ -use crate::passes::parse::{Def, Meta, Span, TypeDef}; +use crate::passes::parse::{Def, Spanned, TypeDef}; use crate::passes::validate::error::TypeError; use crate::passes::validate::uniquify::r#type::uniquify_type; use crate::passes::validate::uniquify::try_get; @@ -8,8 +8,8 @@ use crate::utils::push_map::PushMap; pub fn uniquify_typedef<'p>( scope: &mut PushMap<&'p str, UniqueSym<'p>>, - sym: Meta, - def: TypeDef, Meta>, + sym: Spanned<&'p str>, + def: TypeDef, Spanned<&'p str>>, ) -> Result, TypeError> { let def = match def { TypeDef::Struct { fields } => TypeDef::Struct {