mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Specialize lookups and bool types
This commit is contained in:
parent
9868c5cfac
commit
18d817246e
5 changed files with 40 additions and 7 deletions
|
@ -20,5 +20,5 @@ pub use mono_ir::{MonoExpr, MonoExprId, MonoExprs};
|
|||
pub use mono_module::{InternedStrId, Interns};
|
||||
pub use mono_num::Number;
|
||||
pub use mono_struct::MonoFieldId;
|
||||
pub use mono_type::{MonoType, MonoTypeId, MonoTypes};
|
||||
pub use mono_type::{MonoType, MonoTypeId, MonoTypes, Primitive};
|
||||
pub use specialize_type::{MonoTypeCache, Problem, RecordFieldIds, TupleElemIds};
|
||||
|
|
|
@ -258,7 +258,7 @@ impl<'a, 'c, 'd, 'i, 's, 't, P: Push<Problem>> Env<'a, 'c, 'd, 'i, 's, 't, P> {
|
|||
// })
|
||||
// }
|
||||
// }
|
||||
// Expr::Var(symbol, var) => Some(MonoExpr::Lookup(*symbol, mono_from_var(*var)?)),
|
||||
Expr::Var(symbol, var) => MonoExpr::Lookup(*symbol, mono_from_var(*var)),
|
||||
// Expr::LetNonRec(def, loc) => {
|
||||
// let expr = self.to_mono_expr(def.loc_expr.value, stmts)?;
|
||||
// let todo = (); // TODO if this is an underscore pattern and we're doing a fn call, convert it to Stmt::CallVoid
|
||||
|
@ -276,7 +276,7 @@ impl<'a, 'c, 'd, 'i, 's, 't, P: Push<Problem>> Env<'a, 'c, 'd, 'i, 's, 't, P> {
|
|||
// todo!("split up the pattern into various Assign statements.");
|
||||
// }
|
||||
// Expr::LetRec(vec, loc, illegal_cycle_mark) => todo!(),
|
||||
_ => todo!(),
|
||||
_ => todo!("{:?}", can_expr),
|
||||
// Expr::List {
|
||||
// elem_var,
|
||||
// loc_elems,
|
||||
|
@ -405,7 +405,7 @@ fn to_num(primitive: Primitive, val: IntValue, problems: &mut impl Push<Problem>
|
|||
})),
|
||||
Primitive::U128 => MonoExpr::Number(Number::U128(val.as_u128())),
|
||||
Primitive::I128 => MonoExpr::Number(Number::I128(val.as_i128())),
|
||||
Primitive::Str | Primitive::Crash => {
|
||||
Primitive::Str | Primitive::Crash | Primitive::Bool => {
|
||||
let problem = Problem::NumSpecializedToWrongType(Some(MonoType::Primitive(primitive)));
|
||||
problems.push(problem);
|
||||
MonoExpr::CompilerBug(problem)
|
||||
|
@ -432,7 +432,8 @@ fn to_frac(primitive: Primitive, val: f64, problems: &mut impl Push<Problem>) ->
|
|||
| Primitive::U128
|
||||
| Primitive::I128
|
||||
| Primitive::Str
|
||||
| Primitive::Crash => {
|
||||
| Primitive::Crash
|
||||
| Primitive::Bool => {
|
||||
let problem = Problem::NumSpecializedToWrongType(Some(MonoType::Primitive(primitive)));
|
||||
problems.push(problem);
|
||||
MonoExpr::CompilerBug(problem)
|
||||
|
@ -455,7 +456,12 @@ fn char_to_int(primitive: Primitive, ch: char, problems: &mut impl Push<Problem>
|
|||
Primitive::I128 => MonoExpr::Number(Number::I128(ch as i128)),
|
||||
Primitive::I16 => MonoExpr::Number(Number::I16(ch as i16)),
|
||||
Primitive::I8 => MonoExpr::Number(Number::I8(ch as i8)),
|
||||
Primitive::Str | Primitive::Dec | Primitive::F32 | Primitive::F64 | Primitive::Crash => {
|
||||
Primitive::Str
|
||||
| Primitive::Dec
|
||||
| Primitive::F32
|
||||
| Primitive::F64
|
||||
| Primitive::Crash
|
||||
| Primitive::Bool => {
|
||||
let problem = Problem::CharSpecializedToWrongType(Some(MonoType::Primitive(primitive)));
|
||||
problems.push(problem);
|
||||
MonoExpr::CompilerBug(problem)
|
||||
|
|
|
@ -66,6 +66,10 @@ impl MonoTypeId {
|
|||
inner: Index::new(14),
|
||||
};
|
||||
|
||||
pub const BOOL: Self = Self {
|
||||
inner: Index::new(15),
|
||||
};
|
||||
|
||||
pub const DEFAULT_INT: Self = Self::I64; // TODO change this to I128
|
||||
pub const DEFAULT_FRAC: Self = Self::DEC;
|
||||
|
||||
|
@ -100,6 +104,7 @@ impl MonoTypes {
|
|||
MonoType::Primitive(Primitive::F32),
|
||||
MonoType::Primitive(Primitive::F64),
|
||||
MonoType::Primitive(Primitive::Dec),
|
||||
MonoType::Primitive(Primitive::Bool),
|
||||
],
|
||||
ids: Vec::new(),
|
||||
slices: Vec::new(),
|
||||
|
@ -232,6 +237,7 @@ pub enum Primitive {
|
|||
F32,
|
||||
F64,
|
||||
Dec,
|
||||
Bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
|
@ -114,6 +114,8 @@ impl<'a, 'c, 'd, 'e, 'f, 'm, 'p, P: Push<Problem>> Env<'a, 'c, 'd, 'e, 'f, 'm, '
|
|||
// .flat_map(|var_index| self.lower_var( subs, subs[var_index]));
|
||||
|
||||
// let arg = new_args.next();
|
||||
} else if symbol == Symbol::BOOL_BOOL {
|
||||
MonoTypeId::BOOL
|
||||
} else {
|
||||
todo!("implement lower_builtin for symbol {symbol:?} - or, if all the builtins are already in here, report a compiler bug instead of panicking like this.");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ mod helpers;
|
|||
|
||||
#[cfg(test)]
|
||||
mod specialize_primitives {
|
||||
use roc_specialize_types::{MonoExpr, Number};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_specialize_types::{MonoExpr, MonoType, MonoTypeId, Number, Primitive};
|
||||
|
||||
use super::helpers::{expect_mono_expr, expect_mono_expr_with_interns};
|
||||
|
||||
|
@ -170,4 +171,22 @@ mod specialize_primitives {
|
|||
MonoExpr::Number(Number::Dec(expected)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bool_true() {
|
||||
let expected = "Bool.true";
|
||||
expect_mono_expr(
|
||||
expected,
|
||||
MonoExpr::Lookup(Symbol::BOOL_TRUE, MonoTypeId::BOOL),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bool_false() {
|
||||
let expected = "Bool.false";
|
||||
expect_mono_expr(
|
||||
expected,
|
||||
MonoExpr::Lookup(Symbol::BOOL_FALSE, MonoTypeId::BOOL),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue