diff --git a/Cargo.lock b/Cargo.lock index 197b806..b0e526b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,7 +264,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19be8061a06ab6f3a6cf21106c873578bf01bd42ad15e0311a9c76161cb1c753" dependencies = [ "enumset_derive", - "serde", ] [[package]] @@ -377,7 +376,6 @@ checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", "hashbrown 0.14.0", - "serde", ] [[package]] @@ -630,9 +628,6 @@ name = "rose" version = "0.0.0" dependencies = [ "enumset", - "serde", - "thiserror", - "ts-rs", ] [[package]] @@ -691,7 +686,6 @@ dependencies = [ "rose-interp", "serde", "serde-wasm-bindgen", - "ts-rs", "wasm-bindgen", ] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index ea8465a..0e70e39 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -8,12 +8,3 @@ include = ["src/lib.rs"] [dependencies] enumset = "1" -serde = { version = "1", features = ["derive"], optional = true } -thiserror = "1" - -[dev-dependencies] -ts-rs = "6" - -[features] -default = ["serde"] -serde = ["dep:serde", "enumset/serde"] diff --git a/crates/core/src/id.rs b/crates/core/src/id.rs index aace964..5774d3c 100644 --- a/crates/core/src/id.rs +++ b/crates/core/src/id.rs @@ -1,18 +1,4 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -// remember to `serde(rename)` everything here to avoid ts-rs name conflicts with non-ID types - -#[cfg(test)] -use ts_rs::TS; - /// Index of a member in a tuple. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename = "MemberId") -)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Member(usize); @@ -27,32 +13,20 @@ impl Member { } /// Index of an uninstantiated function reference in a definition context. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename = "FunctionId") -)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct Function(usize); +pub struct Func(usize); -pub fn function(id: usize) -> Function { - Function(id) +pub fn func(id: usize) -> Func { + Func(id) } -impl Function { - pub fn function(self) -> usize { +impl Func { + pub fn func(self) -> usize { self.0 } } /// Index of a generic type parameter in a definition context. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename = "GenericId") -)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Generic(usize); @@ -67,12 +41,6 @@ impl Generic { } /// Index of a type in a definition context. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename = "TyId") -)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Ty(usize); @@ -87,12 +55,6 @@ impl Ty { } /// Index of a local variable in a function definition context. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename = "VarId") -)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Var(usize); diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 73e3cb4..57e2b31 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -2,15 +2,7 @@ pub mod id; use enumset::{EnumSet, EnumSetType}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -#[cfg(test)] -use ts_rs::TS; - /// A type constraint. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[allow(clippy::derived_hash_with_manual_eq)] // `PartialEq` impl comes from enumset; should be fine #[derive(Debug, EnumSetType, Hash)] pub enum Constraint { @@ -25,8 +17,6 @@ pub enum Constraint { } /// A type. -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum Ty { Unit, @@ -55,13 +45,13 @@ pub enum Ty { elem: id::Ty, }, Tuple { - members: Vec, // TODO: change to `Box<[id::Ty]` + members: Box<[id::Ty]>, }, } /// A function definition. #[derive(Debug)] -pub struct Function { +pub struct Func { /// Generic type parameters. pub generics: Box<[EnumSet]>, /// Types used in this function definition. @@ -76,13 +66,13 @@ pub struct Function { pub body: Box<[Instr]>, } -/// Resolves `id::Function`s. +/// Resolves `id::Func`s. pub trait Refs<'a> { /// See `Node`. type Opaque; /// Resolve `id` to a function node. - fn get(&self, id: id::Function) -> Option> + fn get(&self, id: id::Func) -> Option> where Self: Sized; } @@ -95,7 +85,7 @@ pub enum Node<'a, O, T: Refs<'a, Opaque = O>> { /// To traverse the graph by resolving functions called by this one. refs: T, /// The signature and definition of this function. - def: &'a Function, + def: &'a Func, }, /// A function with an opaque body. Opaque { @@ -112,14 +102,12 @@ pub enum Node<'a, O, T: Refs<'a, Opaque = O>> { }, } -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug)] pub struct Instr { pub var: id::Var, pub expr: Expr, } -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug)] pub enum Expr { Unit, @@ -177,7 +165,7 @@ pub enum Expr { }, Call { - id: id::Function, + id: id::Func, generics: Box<[id::Ty]>, args: Box<[id::Var]>, }, @@ -223,8 +211,6 @@ pub enum Expr { }, } -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Unop { // `Bool` -> `Bool` @@ -236,8 +222,6 @@ pub enum Unop { Sqrt, } -#[cfg_attr(test, derive(TS), ts(export))] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Binop { // `Bool` -> `Bool` -> `Bool` diff --git a/crates/frontend/src/translate.rs b/crates/frontend/src/translate.rs index 153922d..30f958e 100644 --- a/crates/frontend/src/translate.rs +++ b/crates/frontend/src/translate.rs @@ -110,7 +110,7 @@ pub struct Typedef<'input> { #[derive(Debug)] pub struct Module<'input> { types: IndexMap<&'input str, Typedef<'input>>, - funcs: IndexMap<&'input str, rose::Function>, + funcs: IndexMap<&'input str, rose::Func>, } type Opaque = Infallible; @@ -118,9 +118,9 @@ type Opaque = Infallible; impl<'input, 'a> rose::Refs<'a> for &'a Module<'input> { type Opaque = Opaque; - fn get(&self, id: id::Function) -> Option> { + fn get(&self, id: id::Func) -> Option> { self.funcs - .get_index(id.function()) + .get_index(id.func()) .map(|(_, def)| ir::Node::Transparent { refs: *self, def }) } } @@ -132,7 +132,7 @@ impl Module<'_> { pub fn get_func(&self, name: &str) -> Option> { let i = self.funcs.get_index_of(name)?; - ir::Refs::get(&self, id::function(i)) + ir::Refs::get(&self, id::func(i)) } } @@ -183,7 +183,7 @@ impl<'input, 'a> BlockCtx<'input, 'a> { fn unify( &mut self, - _f: &ir::Function, + _f: &ir::Func, _args: &[id::Ty], ) -> Result<(Vec, id::Ty), TypeError> { todo!() @@ -271,7 +271,7 @@ impl<'input, 'a> BlockCtx<'input, 'a> { Ok(self.instr( ret, ir::Expr::Call { - id: id::function(i), + id: id::func(i), generics: generics.into(), args: vars, }, @@ -425,7 +425,7 @@ impl<'input> Module<'input> { ctx.bind(bind, id::var(i)); } let retvar = ctx.typecheck(body)?; // TODO: ensure this matches `ret` - let f = ir::Function { + let f = ir::Func { generics, types: ctx.t.into_iter().collect(), vars: ctx.v.into(), diff --git a/crates/interp/src/lib.rs b/crates/interp/src/lib.rs index a238f83..3a96900 100644 --- a/crates/interp/src/lib.rs +++ b/crates/interp/src/lib.rs @@ -1,5 +1,5 @@ use indexmap::IndexSet; -use rose::{id, Binop, Expr, Function, Node, Refs, Ty, Unop}; +use rose::{id, Binop, Expr, Func, Node, Refs, Ty, Unop}; use std::{cell::Cell, convert::Infallible, rc::Rc}; #[cfg(feature = "serde")] @@ -145,18 +145,13 @@ impl Opaque for Infallible { struct Interpreter<'a, 'b, O: Opaque, T: Refs<'a, Opaque = O>> { typemap: &'b mut IndexSet, refs: T, - def: &'a Function, + def: &'a Func, types: Vec, vars: Vec>, } impl<'a, 'b, O: Opaque, T: Refs<'a, Opaque = O>> Interpreter<'a, 'b, O, T> { - fn new( - typemap: &'b mut IndexSet, - refs: T, - def: &'a Function, - generics: &'b [id::Ty], - ) -> Self { + fn new(typemap: &'b mut IndexSet, refs: T, def: &'a Func, generics: &'b [id::Ty]) -> Self { let mut types = vec![]; for ty in def.types.iter() { types.push(resolve(typemap, generics, &types, ty)); @@ -346,7 +341,7 @@ pub fn interp<'a, O: Opaque, T: Refs<'a, Opaque = O>>( #[cfg(test)] mod tests { use super::*; - use rose::{Function, Instr}; + use rose::{Func, Instr}; type CustomRef<'a> = &'a dyn Fn(&IndexSet, &[id::Ty], &[Val]) -> Val; type CustomBox = Box, &[id::Ty], &[Val]) -> Val>; @@ -363,15 +358,15 @@ mod tests { struct FuncInSlice<'a> { custom: &'a [CustomBox], - funcs: &'a [Function], - id: id::Function, + funcs: &'a [Func], + id: id::Func, } impl<'a> Refs<'a> for FuncInSlice<'a> { type Opaque = Custom<'a>; - fn get(&self, id: id::Function) -> Option, Self>> { - if id.function() < self.id.function() { + fn get(&self, id: id::Func) -> Option, Self>> { + if id.func() < self.id.func() { node(self.custom, self.funcs, id) } else { None @@ -381,11 +376,11 @@ mod tests { fn node<'a>( custom: &'a [CustomBox], - funcs: &'a [Function], - id: id::Function, + funcs: &'a [Func], + id: id::Func, ) -> Option, FuncInSlice<'a>>> { let n = custom.len(); - let i = id.function(); + let i = id.func(); if i < n { Some(Node::Opaque { generics: &[], @@ -404,7 +399,7 @@ mod tests { #[test] fn test_two_plus_two() { - let funcs = vec![Function { + let funcs = vec![Func { generics: vec![].into(), types: vec![Ty::F64].into(), vars: vec![id::ty(0), id::ty(0), id::ty(0)].into(), @@ -421,7 +416,7 @@ mod tests { .into(), }]; let answer = interp( - node(&[], &funcs, id::function(0)).unwrap(), + node(&[], &funcs, id::func(0)).unwrap(), IndexSet::new(), &[], [val_f64(2.), val_f64(2.)].into_iter(), @@ -433,7 +428,7 @@ mod tests { #[test] fn test_nested_call() { let funcs = vec![ - Function { + Func { generics: vec![].into(), types: vec![Ty::F64].into(), vars: vec![id::ty(0)].into(), @@ -445,7 +440,7 @@ mod tests { }] .into(), }, - Function { + Func { generics: vec![].into(), types: vec![Ty::F64].into(), vars: vec![id::ty(0), id::ty(0)].into(), @@ -455,7 +450,7 @@ mod tests { Instr { var: id::var(0), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: vec![].into(), args: vec![].into(), }, @@ -473,7 +468,7 @@ mod tests { }, ]; let answer = interp( - node(&[], &funcs, id::function(1)).unwrap(), + node(&[], &funcs, id::func(1)).unwrap(), IndexSet::new(), &[], [].into_iter(), @@ -487,7 +482,7 @@ mod tests { let custom: [CustomBox; 1] = [Box::new(|_, _, args| { Val::F64(Cell::new(args[0].f64().powf(args[1].f64()))) })]; - let funcs = [Function { + let funcs = [Func { generics: [].into(), types: [Ty::F64].into(), vars: [id::ty(0), id::ty(0), id::ty(0)].into(), @@ -496,7 +491,7 @@ mod tests { body: [Instr { var: id::var(2), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [id::var(0), id::var(1)].into(), }, @@ -504,7 +499,7 @@ mod tests { .into(), }]; let answer = interp( - node(&custom, &funcs, id::function(1)).unwrap(), + node(&custom, &funcs, id::func(1)).unwrap(), IndexSet::new(), &[], [val_f64(std::f64::consts::E), val_f64(std::f64::consts::PI)].into_iter(), diff --git a/crates/validate/src/lib.rs b/crates/validate/src/lib.rs index 56e3b17..1876b28 100644 --- a/crates/validate/src/lib.rs +++ b/crates/validate/src/lib.rs @@ -1,6 +1,6 @@ use enumset::EnumSet; use indexmap::IndexMap; -use rose::{id, Binop, Constraint, Expr, Function, Instr, Refs, Ty, Unop}; +use rose::{id, Binop, Constraint, Expr, Func, Instr, Refs, Ty, Unop}; #[derive(Debug, Eq, thiserror::Error, PartialEq)] pub enum InstrError { @@ -286,7 +286,7 @@ enum Scope { struct Validator<'a, O, T: Refs<'a, Opaque = O>> { refs: T, - def: &'a Function, + def: &'a Func, constraints: IndexMap>, /// indices from `self.f.types` into `self.constraints` types: Vec, @@ -762,7 +762,7 @@ pub enum Error { } /// Validate `f`, assuming that all of its referenced functions are valid. -pub fn validate<'a, O, T: Refs<'a, Opaque = O>>(refs: T, def: &'a Function) -> Result<(), Error> { +pub fn validate<'a, O, T: Refs<'a, Opaque = O>>(refs: T, def: &'a Func) -> Result<(), Error> { for (i, constrs) in def.generics.iter().enumerate() { // for now we have no compatible constraints if (constrs.contains(Constraint::Index) && !constrs.contains(Constraint::Value)) @@ -836,7 +836,9 @@ pub fn validate<'a, O, T: Refs<'a, Opaque = O>>(refs: T, def: &'a Function) -> R } } ( - Ty::Tuple { members: mems }, + Ty::Tuple { + members: mems.into(), + }, EnumSet::only(Constraint::Value), ) } @@ -893,15 +895,15 @@ mod tests { use rose::Node; struct FuncInSlice<'a> { - funcs: &'a [Function], - id: id::Function, + funcs: &'a [Func], + id: id::Func, } impl<'a> Refs<'a> for FuncInSlice<'a> { type Opaque = (); - fn get(&self, id: id::Function) -> Option> { - if id.function() < self.id.function() { + fn get(&self, id: id::Func) -> Option> { + if id.func() < self.id.func() { node(self.funcs, id) } else { None @@ -909,20 +911,20 @@ mod tests { } } - fn node(funcs: &[Function], id: id::Function) -> Option> { - funcs.get(id.function()).map(|def| Node::Transparent { + fn node(funcs: &[Func], id: id::Func) -> Option> { + funcs.get(id.func()).map(|def| Node::Transparent { refs: FuncInSlice { funcs, id }, def, }) } - fn validate_in_slice(funcs: &[Function], id: id::Function) -> Result<(), Error> { - validate(FuncInSlice { funcs, id }, &funcs[id.function()]) + fn validate_in_slice(funcs: &[Func], id: id::Func) -> Result<(), Error> { + validate(FuncInSlice { funcs, id }, &funcs[id.func()]) } fn example_constraints(constraints: EnumSet) { let res = validate_in_slice( - &[Function { + &[Func { generics: [constraints].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -934,7 +936,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::ImpossibleConstraints(id::generic(0)))); } @@ -962,7 +964,7 @@ mod tests { #[test] fn test_invalid_generic() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Generic { id: id::generic(0) }].into(), vars: [id::ty(0)].into(), @@ -970,14 +972,14 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidGeneric(id::ty(0)))); } fn example_kind(kind: Constraint) { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -992,7 +994,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidKind(id::ty(1)))); } @@ -1010,7 +1012,7 @@ mod tests { #[test] fn test_scope_id() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1025,7 +1027,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidRef(id::ty(1)))); } @@ -1033,7 +1035,7 @@ mod tests { #[test] fn test_ref_scope() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1062,7 +1064,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidScope(id::ty(2)))); } @@ -1070,7 +1072,7 @@ mod tests { #[test] fn test_inner() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1099,7 +1101,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidInner(id::ty(2)))); } @@ -1107,7 +1109,7 @@ mod tests { #[test] fn test_nested_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1153,7 +1155,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InnerNotValue(id::ty(5)))); } @@ -1161,7 +1163,7 @@ mod tests { #[test] fn test_invalid_index() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::F64, @@ -1177,7 +1179,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidIndex(id::ty(1)))); } @@ -1185,7 +1187,7 @@ mod tests { #[test] fn test_invalid_elem() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1201,7 +1203,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidElem(id::ty(1)))); } @@ -1209,7 +1211,7 @@ mod tests { #[test] fn test_not_index() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::F64, @@ -1224,7 +1226,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::NotIndex(id::ty(1)))); } @@ -1232,7 +1234,7 @@ mod tests { #[test] fn test_elem_not_value() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::empty()].into(), types: [ Ty::Fin { size: 1 }, @@ -1248,7 +1250,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::ElemNotValue(id::ty(2)))); } @@ -1256,7 +1258,7 @@ mod tests { #[test] fn test_invalid_member() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Tuple { @@ -1270,7 +1272,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidMember(id::ty(0), id::member(0)))); } @@ -1278,7 +1280,7 @@ mod tests { #[test] fn test_member_not_value() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::empty()].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1292,7 +1294,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::MemberNotValue(id::ty(1), id::member(0)))); } @@ -1300,7 +1302,7 @@ mod tests { #[test] fn test_invalid_var() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [].into(), vars: [id::ty(0)].into(), @@ -1312,7 +1314,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidVar(id::var(0)))); } @@ -1320,7 +1322,7 @@ mod tests { #[test] fn test_invalid_param() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1332,7 +1334,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidParam(0))); } @@ -1340,7 +1342,7 @@ mod tests { #[test] fn test_duplicate_param() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -1352,7 +1354,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::DuplicateParam(1))); } @@ -1360,7 +1362,7 @@ mod tests { #[test] fn test_invalid_ret() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [].into(), vars: [].into(), @@ -1368,7 +1370,7 @@ mod tests { ret: id::var(0), body: [].into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, Err(Error::InvalidRet)); } @@ -1384,7 +1386,7 @@ mod tests { #[test] fn test_invalid_var() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1396,7 +1398,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, InvalidVar)); } @@ -1404,7 +1406,7 @@ mod tests { #[test] fn test_redeclare() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1416,7 +1418,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, Redeclare)); } @@ -1424,7 +1426,7 @@ mod tests { #[test] fn test_unit() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::F64].into(), vars: [id::ty(0)].into(), @@ -1436,7 +1438,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, UnitType)); } @@ -1444,7 +1446,7 @@ mod tests { #[test] fn test_bool() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1456,14 +1458,14 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, BoolType)); } #[test] fn test_f64() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1475,7 +1477,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, F64Type)); } @@ -1483,7 +1485,7 @@ mod tests { #[test] fn test_fin_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1495,7 +1497,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, FinType)); } @@ -1503,7 +1505,7 @@ mod tests { #[test] fn test_fin_too_big() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Fin { size: 2 }].into(), vars: [id::ty(0)].into(), @@ -1515,7 +1517,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, FinTooBig)); } @@ -1523,7 +1525,7 @@ mod tests { #[test] fn test_array_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1535,7 +1537,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ArrayType)); } @@ -1543,7 +1545,7 @@ mod tests { #[test] fn test_array_index() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Unit, @@ -1563,7 +1565,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ArrayIndex)); } @@ -1571,7 +1573,7 @@ mod tests { #[test] fn test_array_size() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Fin { size: 1 }, @@ -1590,7 +1592,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ArraySize)); } @@ -1598,7 +1600,7 @@ mod tests { #[test] fn test_array_invalid_elem() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Fin { size: 1 }, @@ -1619,7 +1621,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ArrayInvalidElem(0))); } @@ -1627,7 +1629,7 @@ mod tests { #[test] fn test_array_elem_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1649,7 +1651,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ArrayElemType(0))); } @@ -1657,7 +1659,7 @@ mod tests { #[test] fn test_tuple_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -1669,7 +1671,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, TupleType)); } @@ -1677,7 +1679,7 @@ mod tests { #[test] fn test_tuple_size() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1695,7 +1697,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, TupleSize)); } @@ -1703,7 +1705,7 @@ mod tests { #[test] fn test_tuple_invalid_member() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1723,7 +1725,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, TupleInvalidMember(id::member(0)))); } @@ -1731,7 +1733,7 @@ mod tests { #[test] fn test_tuple_member_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1752,7 +1754,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, TupleMemberType(id::member(0)))); } @@ -1760,7 +1762,7 @@ mod tests { #[test] fn test_index_invalid_array() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1782,7 +1784,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, IndexInvalidArray)); } @@ -1790,7 +1792,7 @@ mod tests { #[test] fn test_index_invalid_index() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1812,7 +1814,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, IndexInvalidIndex)); } @@ -1820,7 +1822,7 @@ mod tests { #[test] fn test_index_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1843,7 +1845,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, IndexType)); } @@ -1851,7 +1853,7 @@ mod tests { #[test] fn test_member_invalid_tuple() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1872,7 +1874,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, MemberInvalidTuple)); } @@ -1880,7 +1882,7 @@ mod tests { #[test] fn test_member_not_tuple() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -1895,7 +1897,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, MemberNotTuple)); } @@ -1903,7 +1905,7 @@ mod tests { #[test] fn test_member_invalid_member() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Tuple { members: [].into() }].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -1918,7 +1920,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, MemberInvalidMember)); } @@ -1926,7 +1928,7 @@ mod tests { #[test] fn test_member_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -1948,7 +1950,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, MemberType)); } @@ -1956,7 +1958,7 @@ mod tests { #[test] fn test_slice_invalid_array() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -1978,7 +1980,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceInvalidArray)); } @@ -1986,7 +1988,7 @@ mod tests { #[test] fn test_slice_invalid_index() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2008,7 +2010,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceInvalidIndex)); } @@ -2016,7 +2018,7 @@ mod tests { #[test] fn test_slice_array_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2038,7 +2040,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceArrayNotRef)); } @@ -2046,7 +2048,7 @@ mod tests { #[test] fn test_slice_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index, EnumSet::empty()].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2073,7 +2075,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceNotRef)); } @@ -2081,7 +2083,7 @@ mod tests { #[test] fn test_slice_scope() { let res = validate_in_slice( - &[Function { + &[Func { generics: [ Constraint::Value | Constraint::Index, EnumSet::empty(), @@ -2118,7 +2120,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceScope)); } @@ -2126,7 +2128,7 @@ mod tests { #[test] fn test_slice_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index, EnumSet::empty()].into(), types: [ Ty::Unit, @@ -2158,7 +2160,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SliceType)); } @@ -2166,7 +2168,7 @@ mod tests { #[test] fn test_unary_invalid_arg() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool].into(), vars: [id::ty(0)].into(), @@ -2181,14 +2183,14 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, UnaryInvalidArg)); } fn example_unary_type(types: Box<[Ty]>, op: Unop) { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types, vars: [id::ty(0), id::ty(1)].into(), @@ -2203,7 +2205,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, UnaryType)); } @@ -2231,7 +2233,7 @@ mod tests { #[test] fn test_binary_invalid_left() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool].into(), vars: [id::ty(0)].into(), @@ -2247,7 +2249,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, BinaryInvalidLeft)); } @@ -2255,7 +2257,7 @@ mod tests { #[test] fn test_binary_invalid_right() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -2271,14 +2273,14 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, BinaryInvalidRight)); } fn example_binary_type(types: Box<[Ty]>, op: Binop) { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types, vars: [id::ty(0), id::ty(1), id::ty(2)].into(), @@ -2294,7 +2296,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, BinaryType)); } @@ -2346,7 +2348,7 @@ mod tests { fn example_select_invalid(cond: usize, then: usize, els: usize, e: InstrError) { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -2362,7 +2364,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, e)); } @@ -2385,7 +2387,7 @@ mod tests { #[test] fn test_select_type_cond() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0), id::ty(0)].into(), @@ -2401,7 +2403,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SelectType)); } @@ -2409,7 +2411,7 @@ mod tests { #[test] fn test_select_type_match() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool, Ty::Unit].into(), vars: [id::ty(0), id::ty(0), id::ty(1), id::ty(0)].into(), @@ -2425,7 +2427,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SelectType)); } @@ -2433,7 +2435,7 @@ mod tests { #[test] fn test_select_type_ret() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Bool, Ty::Unit].into(), vars: [id::ty(0), id::ty(0), id::ty(0), id::ty(1)].into(), @@ -2449,7 +2451,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, SelectType)); } @@ -2457,7 +2459,7 @@ mod tests { #[test] fn test_call_function() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2466,14 +2468,14 @@ mod tests { body: [Instr { var: id::var(0), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [].into(), }, }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, CallFunction)); } @@ -2482,7 +2484,7 @@ mod tests { fn test_call_generics_count() { let res = validate_in_slice( &[ - Function { + Func { generics: [EnumSet::empty()].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2494,7 +2496,7 @@ mod tests { }] .into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2503,7 +2505,7 @@ mod tests { body: [Instr { var: id::var(0), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [].into(), }, @@ -2511,7 +2513,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallGenericsCount)); } @@ -2520,7 +2522,7 @@ mod tests { fn test_call_invalid_generic() { let res = validate_in_slice( &[ - Function { + Func { generics: [EnumSet::only(Constraint::Index)].into(), types: [Ty::Generic { id: id::generic(0) }].into(), vars: [id::ty(0)].into(), @@ -2528,7 +2530,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -2537,7 +2539,7 @@ mod tests { body: [Instr { var: id::var(1), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [id::ty(1)].into(), args: [id::var(0)].into(), }, @@ -2545,7 +2547,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallInvalidGeneric(id::generic(0)))); } @@ -2554,7 +2556,7 @@ mod tests { fn test_call_generic() { let res = validate_in_slice( &[ - Function { + Func { generics: [EnumSet::only(Constraint::Index)].into(), types: [Ty::Generic { id: id::generic(0) }].into(), vars: [id::ty(0)].into(), @@ -2562,7 +2564,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -2571,7 +2573,7 @@ mod tests { body: [Instr { var: id::var(1), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [id::ty(0)].into(), args: [id::var(0)].into(), }, @@ -2579,7 +2581,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallGeneric(id::generic(0)))); } @@ -2588,7 +2590,7 @@ mod tests { fn test_call_args_count() { let res = validate_in_slice( &[ - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2596,7 +2598,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2605,7 +2607,7 @@ mod tests { body: [Instr { var: id::var(0), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [].into(), }, @@ -2613,7 +2615,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallArgsCount)); } @@ -2622,7 +2624,7 @@ mod tests { fn test_call_invalid_arg() { let res = validate_in_slice( &[ - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2630,7 +2632,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0), id::ty(0)].into(), @@ -2639,7 +2641,7 @@ mod tests { body: [Instr { var: id::var(1), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [id::var(2)].into(), }, @@ -2647,7 +2649,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallInvalidArg(0))); } @@ -2656,7 +2658,7 @@ mod tests { fn test_call_arg() { let res = validate_in_slice( &[ - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2664,7 +2666,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit, Ty::F64].into(), vars: [id::ty(1), id::ty(0)].into(), @@ -2673,7 +2675,7 @@ mod tests { body: [Instr { var: id::var(1), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [id::var(0)].into(), }, @@ -2681,7 +2683,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallArg(0))); } @@ -2690,7 +2692,7 @@ mod tests { fn test_call_ret() { let res = validate_in_slice( &[ - Function { + Func { generics: [].into(), types: [Ty::Unit].into(), vars: [id::ty(0)].into(), @@ -2698,7 +2700,7 @@ mod tests { ret: id::var(0), body: [].into(), }, - Function { + Func { generics: [].into(), types: [Ty::Unit, Ty::F64].into(), vars: [id::ty(0), id::ty(1)].into(), @@ -2707,7 +2709,7 @@ mod tests { body: [Instr { var: id::var(1), expr: Expr::Call { - id: id::function(0), + id: id::func(0), generics: [].into(), args: [id::var(0)].into(), }, @@ -2715,7 +2717,7 @@ mod tests { .into(), }, ], - id::function(1), + id::func(1), ); assert_eq!(res, err(0, CallRet)); } @@ -2723,7 +2725,7 @@ mod tests { #[test] fn test_for_invalid_arg() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2746,7 +2748,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ForInvalidArg)); } @@ -2754,7 +2756,7 @@ mod tests { #[test] fn test_for_body() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2781,7 +2783,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ForBody(0, Box::new(UnitType)))); } @@ -2789,7 +2791,7 @@ mod tests { #[test] fn test_for_invalid_ret() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Generic { id: id::generic(0) }, @@ -2812,7 +2814,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ForInvalidRet)); } @@ -2820,7 +2822,7 @@ mod tests { #[test] fn test_for_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [Constraint::Value | Constraint::Index].into(), types: [ Ty::Unit, @@ -2848,7 +2850,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ForType)); } @@ -2856,7 +2858,7 @@ mod tests { #[test] fn test_read_invalid_var() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -2884,7 +2886,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadInvalidVar)); } @@ -2892,7 +2894,7 @@ mod tests { #[test] fn test_read_invalid_arg() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -2920,7 +2922,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadInvalidArg)); } @@ -2928,7 +2930,7 @@ mod tests { #[test] fn test_read_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -2956,7 +2958,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadNotRef)); } @@ -2964,7 +2966,7 @@ mod tests { #[test] fn test_read_not_scope() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Read)].into(), types: [ Ty::Unit, @@ -2989,7 +2991,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadNotScope)); } @@ -2997,7 +2999,7 @@ mod tests { #[test] fn test_read_scope_kind() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3025,7 +3027,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadScopeKind)); } @@ -3033,7 +3035,7 @@ mod tests { #[test] fn test_read_scope_id() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3061,7 +3063,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadScopeId)); } @@ -3069,7 +3071,7 @@ mod tests { #[test] fn test_read_inner() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3098,7 +3100,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadInner)); } @@ -3106,7 +3108,7 @@ mod tests { #[test] fn test_read_body() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3138,7 +3140,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadBody(0, Box::new(Redeclare)))); } @@ -3146,7 +3148,7 @@ mod tests { #[test] fn test_read_invalid_ret() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3174,7 +3176,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadInvalidRet)); } @@ -3182,7 +3184,7 @@ mod tests { #[test] fn test_read_escape() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3210,7 +3212,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadEscape)); } @@ -3218,7 +3220,7 @@ mod tests { #[test] fn test_read_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3247,7 +3249,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, ReadType)); } @@ -3255,7 +3257,7 @@ mod tests { #[test] fn test_accum_invalid_shape() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3283,7 +3285,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumInvalidShape)); } @@ -3291,7 +3293,7 @@ mod tests { #[test] fn test_accum_invalid_arg() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3319,7 +3321,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumInvalidArg)); } @@ -3327,7 +3329,7 @@ mod tests { #[test] fn test_accum_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3355,7 +3357,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumNotRef)); } @@ -3363,7 +3365,7 @@ mod tests { #[test] fn test_accum_not_scope() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Accum)].into(), types: [ Ty::Unit, @@ -3388,7 +3390,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumNotScope)); } @@ -3396,7 +3398,7 @@ mod tests { #[test] fn test_accum_scope_kind() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3424,7 +3426,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumScopeKind)); } @@ -3432,7 +3434,7 @@ mod tests { #[test] fn test_accum_scope_id() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3460,7 +3462,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumScopeId)); } @@ -3468,7 +3470,7 @@ mod tests { #[test] fn test_accum_inner() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3497,7 +3499,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumInner)); } @@ -3505,7 +3507,7 @@ mod tests { #[test] fn test_accum_body() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3537,7 +3539,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumBody(0, Box::new(Redeclare)))); } @@ -3545,7 +3547,7 @@ mod tests { #[test] fn test_accum_invalid_ret() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3573,7 +3575,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumInvalidRet)); } @@ -3581,7 +3583,7 @@ mod tests { #[test] fn test_accum_escape() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3609,7 +3611,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumEscape)); } @@ -3617,7 +3619,7 @@ mod tests { #[test] fn test_accum_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [].into(), types: [ Ty::Unit, @@ -3646,7 +3648,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AccumType)); } @@ -3654,7 +3656,7 @@ mod tests { #[test] fn test_ask_invalid_var() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Read)].into(), types: [ Ty::F64, @@ -3674,7 +3676,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AskInvalidVar)); } @@ -3682,7 +3684,7 @@ mod tests { #[test] fn test_ask_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Read)].into(), types: [ Ty::F64, @@ -3702,7 +3704,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AskNotRef)); } @@ -3710,7 +3712,7 @@ mod tests { #[test] fn test_ask_read() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::empty()].into(), types: [ Ty::F64, @@ -3730,7 +3732,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AskRead)); } @@ -3738,7 +3740,7 @@ mod tests { #[test] fn test_ask_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Read)].into(), types: [ Ty::F64, @@ -3758,7 +3760,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AskType)); } @@ -3766,7 +3768,7 @@ mod tests { #[test] fn add_invalid_accum() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Accum)].into(), types: [ Ty::Unit, @@ -3790,7 +3792,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AddInvalidAccum)); } @@ -3798,7 +3800,7 @@ mod tests { #[test] fn add_invalid_addend() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Accum)].into(), types: [ Ty::Unit, @@ -3822,7 +3824,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AddInvalidAddend)); } @@ -3830,7 +3832,7 @@ mod tests { #[test] fn add_not_ref() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Accum)].into(), types: [ Ty::Unit, @@ -3854,7 +3856,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AddNotRef)); } @@ -3862,7 +3864,7 @@ mod tests { #[test] fn add_accum() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::empty()].into(), types: [ Ty::Unit, @@ -3886,7 +3888,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AddAccum)); } @@ -3894,7 +3896,7 @@ mod tests { #[test] fn add_type() { let res = validate_in_slice( - &[Function { + &[Func { generics: [EnumSet::only(Constraint::Accum)].into(), types: [ Ty::Unit, @@ -3918,7 +3920,7 @@ mod tests { }] .into(), }], - id::function(0), + id::func(0), ); assert_eq!(res, err(0, AddType)); } diff --git a/crates/web/Cargo.toml b/crates/web/Cargo.toml index 5259bf9..cd29abf 100644 --- a/crates/web/Cargo.toml +++ b/crates/web/Cargo.toml @@ -10,13 +10,12 @@ crate-type = ["cdylib"] [dependencies] console_error_panic_hook = { version = "0.1", optional = true } enumset = "1" -indexmap = { version = "2", features = ["serde"] } +indexmap = "2" js-sys = "0.3" -rose = { path = "../core", features = ["serde"] } +rose = { path = "../core" } rose-interp = { path = "../interp", features = ["serde"] } serde = { version = "1", features = ["derive"] } serde-wasm-bindgen = "0.4" -ts-rs = "6" wasm-bindgen = "=0.2.87" # Must be this version of wbg [features] diff --git a/crates/web/src/lib.rs b/crates/web/src/lib.rs index d34a1b6..6d91858 100644 --- a/crates/web/src/lib.rs +++ b/crates/web/src/lib.rs @@ -34,7 +34,7 @@ pub fn layouts() -> Result { to_js_value(&[ ("Expr", layout::()), - ("Function", layout::()), + ("Func", layout::()), ("Instr", layout::()), ("Ty", layout::()), ]) @@ -88,7 +88,7 @@ impl rose_interp::Opaque for Opaque<'_> { enum Inner { Transparent { deps: Box<[Func]>, - def: rose::Function, + def: rose::Func, }, Opaque { generics: Box<[EnumSet]>, @@ -107,18 +107,20 @@ struct Refs<'a> { impl<'a> rose::Refs<'a> for Refs<'a> { type Opaque = Opaque<'a>; - fn get(&self, id: id::Function) -> Option, Self>> { - self.deps.get(id.function()).map(|f| f.node()) + fn get(&self, id: id::Func) -> Option, Self>> { + self.deps.get(id.func()).map(|f| f.node()) } } -type Stuff = (Inner, Box<[Option>]>); +// the second tuple element is indices for string keys on tuple types that represent structs; the +// actual strings are stored in JavaScript +type Pointee = (Inner, Box<[Option>]>); /// A node in a reference-counted acyclic digraph of functions. #[wasm_bindgen] #[derive(Clone)] pub struct Func { - rc: Rc, + rc: Rc, } #[wasm_bindgen] @@ -220,7 +222,7 @@ pub fn pprint(f: &Func) -> Result { fn print_instr( mut s: &mut String, - def: &rose::Function, + def: &rose::Func, spaces: usize, instr: &rose::Instr, ) -> Result<(), JsError> { @@ -282,7 +284,7 @@ pub fn pprint(f: &Func) -> Result { writeln!(&mut s, "x{} ? x{} : x{}", cond.var(), then.var(), els.var())? } rose::Expr::Call { id, generics, args } => { - write!(&mut s, "f{}<", id.function())?; + write!(&mut s, "f{}<", id.func())?; print_elems(s, 'T', generics.iter().map(|generic| generic.ty()))?; write!(&mut s, ">(")?; print_elems(s, 'x', args.iter().map(|arg| arg.var()))?; @@ -347,7 +349,7 @@ pub fn pprint(f: &Func) -> Result { fn print_block( mut s: &mut String, - def: &rose::Function, + def: &rose::Func, spaces: usize, body: &[rose::Instr], ret: id::Var, @@ -463,7 +465,7 @@ enum Ty { keys: Box<[usize]>, /// Member types of the underlying tuple. Must be the same length as `keys`. - members: Vec, + members: Box<[id::Ty]>, }, } @@ -556,7 +558,7 @@ impl FuncBuilder { rc: Rc::new(( Inner::Transparent { deps: self.functions.into(), - def: rose::Function { + def: rose::Func { generics: self.generics, types: types.into(), vars: self.vars.into_iter().map(|x| x.t).collect(), @@ -1345,7 +1347,7 @@ impl Block { args: &[usize], ) -> usize { // add the function reference to the callee - let id = id::function(f.functions.len()); + let id = id::func(f.functions.len()); f.functions.push(g.clone()); let expr = rose::Expr::Call { diff --git a/packages/core/src/impl.test.ts b/packages/core/src/impl.test.ts index 699a5ca..b233f04 100644 --- a/packages/core/src/impl.test.ts +++ b/packages/core/src/impl.test.ts @@ -35,9 +35,9 @@ test("core IR type layouts", () => { // these don't matter too much, but it's good to notice if sizes increase expect(Object.fromEntries(wasm.layouts())).toEqual({ Expr: { size: 24, align: 8 }, - Function: { size: 44, align: 4 }, + Func: { size: 44, align: 4 }, Instr: { size: 32, align: 8 }, - Ty: { size: 16, align: 4 }, + Ty: { size: 12, align: 4 }, }); });