diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 0088fe6de7..42e27f49ed 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -1,12 +1,12 @@ use crate::def::Def; use crate::expr::{self, ClosureData, Expr::*}; use crate::expr::{Expr, Field, Recursive}; +use crate::num::{FloatWidth, IntWidth, NumWidth, NumericBound}; use crate::pattern::Pattern; use roc_collections::all::SendMap; use roc_module::called_via::CalledVia; use roc_module::ident::{Lowercase, TagName}; use roc_module::low_level::LowLevel; -use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::{VarStore, Variable}; diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 60be157fe1..1f12b281ce 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -4,7 +4,7 @@ use crate::def::{can_defs_with_return, Def}; use crate::env::Env; use crate::num::{ finish_parsing_base, finish_parsing_float, finish_parsing_num, float_expr_from_result, - int_expr_from_result, num_expr_from_result, + int_expr_from_result, num_expr_from_result, FloatWidth, IntWidth, NumWidth, NumericBound, }; use crate::pattern::{canonicalize_pattern, Pattern}; use crate::procedure::References; @@ -13,7 +13,6 @@ use roc_collections::all::{ImSet, MutMap, MutSet, SendMap}; use roc_module::called_via::CalledVia; use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::low_level::LowLevel; -use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_module::symbol::Symbol; use roc_parse::ast::{self, EscapedChar, StrLiteral}; use roc_parse::pattern::PatternType::*; diff --git a/compiler/can/src/num.rs b/compiler/can/src/num.rs index e134cace5a..cffbec95db 100644 --- a/compiler/can/src/num.rs +++ b/compiler/can/src/num.rs @@ -1,6 +1,5 @@ use crate::env::Env; use crate::expr::Expr; -use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_parse::ast::Base; use roc_problem::can::Problem; use roc_problem::can::RuntimeError::*; @@ -336,6 +335,46 @@ fn from_str_radix( Ok((result, bound)) } +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum IntWidth { + U8, + U16, + U32, + U64, + U128, + I8, + I16, + I32, + I64, + I128, + Nat, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum FloatWidth { + Dec, + F32, + F64, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum NumWidth { + Int(IntWidth), + Float(FloatWidth), +} + +/// Describes a bound on the width of a numeric literal. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum NumericBound +where + W: Copy, +{ + /// There is no bound on the width. + None, + /// Must have exactly the width `W`. + Exact(W), +} + /// An error which can be returned when parsing an integer. /// /// This error is used as the error type for the `from_str_radix()` functions diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index 797dbc961a..eeb8c4b7ce 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -1,9 +1,11 @@ use crate::env::Env; use crate::expr::{canonicalize_expr, unescape_char, Expr, Output}; -use crate::num::{finish_parsing_base, finish_parsing_float, finish_parsing_num, ParsedNumResult}; +use crate::num::{ + finish_parsing_base, finish_parsing_float, finish_parsing_num, FloatWidth, IntWidth, NumWidth, + NumericBound, ParsedNumResult, +}; use crate::scope::Scope; use roc_module::ident::{Ident, Lowercase, TagName}; -use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_module::symbol::Symbol; use roc_parse::ast::{self, StrLiteral, StrSegment}; use roc_parse::pattern::PatternType; diff --git a/compiler/constrain/src/builtins.rs b/compiler/constrain/src/builtins.rs index 2b769eae8a..020d5b4564 100644 --- a/compiler/constrain/src/builtins.rs +++ b/compiler/constrain/src/builtins.rs @@ -1,9 +1,9 @@ use roc_can::constraint::Constraint::{self, *}; use roc_can::constraint::LetConstraint; use roc_can::expected::Expected::{self, *}; +use roc_can::num::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_collections::all::SendMap; use roc_module::ident::{Lowercase, TagName}; -use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound}; use roc_module::symbol::Symbol; use roc_region::all::Region; use roc_types::subs::Variable; @@ -331,7 +331,9 @@ impl TypedNumericBound for NumericBound { match self { NumericBound::None => None, NumericBound::Exact(NumWidth::Int(iw)) => NumericBound::Exact(*iw).concrete_num_type(), - NumericBound::Exact(NumWidth::Float(fw)) => NumericBound::Exact(*fw).concrete_num_type(), + NumericBound::Exact(NumWidth::Float(fw)) => { + NumericBound::Exact(*fw).concrete_num_type() + } } } } diff --git a/compiler/module/src/lib.rs b/compiler/module/src/lib.rs index f9f10fd02f..044f697a07 100644 --- a/compiler/module/src/lib.rs +++ b/compiler/module/src/lib.rs @@ -6,7 +6,6 @@ pub mod called_via; pub mod ident; pub mod low_level; pub mod module_err; -pub mod numeric; pub mod symbol; #[macro_use] diff --git a/compiler/module/src/numeric.rs b/compiler/module/src/numeric.rs deleted file mode 100644 index 0db0c45fc5..0000000000 --- a/compiler/module/src/numeric.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! Module `numeric` has utilities for numeric values in the Roc surface syntax. - -use std::fmt::Display; - -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum IntWidth { - U8, - U16, - U32, - U64, - U128, - I8, - I16, - I32, - I64, - I128, - Nat, -} - -impl Display for IntWidth { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use IntWidth::*; - f.write_str(match self { - U8 => "u8", - U16 => "u16", - U32 => "u32", - U64 => "u64", - U128 => "u128", - I8 => "i8", - I16 => "i16", - I32 => "i32", - I64 => "i64", - I128 => "i128", - Nat => "nat", - }) - } -} - -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum FloatWidth { - Dec, - F32, - F64, -} - -impl Display for FloatWidth { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use FloatWidth::*; - f.write_str(match self { - Dec => "dec", - F32 => "f32", - F64 => "f64", - }) - } -} - -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum NumWidth { - Int(IntWidth), - Float(FloatWidth), -} - -impl Display for NumWidth { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use NumWidth::*; - match self { - Int(iw) => iw.fmt(f), - Float(fw) => fw.fmt(f), - } - } -} - -/// Describes a bound on the width of a numeric literal. -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum NumericBound -where - W: Copy, -{ - /// There is no bound on the width. - None, - /// Must have exactly the width `W`. - Exact(W), -}