Remove Nat from Num

This commit is contained in:
Richard Feldman 2024-01-22 15:05:52 -05:00
parent 02bc54292f
commit c4497f2c1c
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
13 changed files with 9 additions and 45 deletions

View file

@ -25,7 +25,6 @@ interface Num
Unsigned32,
Unsigned16,
Unsigned8,
Nat,
Dec,
F64,
F32,

View file

@ -198,7 +198,6 @@ fn parse_literal_suffix(num_str: &str) -> (Option<ParsedWidth>, &str) {
"i32", ParsedWidth::Int(IntLitWidth::I32)
"i64", ParsedWidth::Int(IntLitWidth::I64)
"i128", ParsedWidth::Int(IntLitWidth::I128)
"nat", ParsedWidth::Int(IntLitWidth::Nat)
"dec", ParsedWidth::Float(FloatWidth::Dec)
"f32", ParsedWidth::Float(FloatWidth::F32)
"f64", ParsedWidth::Float(FloatWidth::F64)

View file

@ -129,7 +129,6 @@ const fn from_builtin_symbol(symbol: Symbol) -> Option<Result<FlatDecodable, Der
Symbol::NUM_DEC | Symbol::NUM_DECIMAL => Some(Ok(Immediate(Symbol::DECODE_DEC))),
Symbol::NUM_F32 | Symbol::NUM_BINARY32 => Some(Ok(Immediate(Symbol::DECODE_F32))),
Symbol::NUM_F64 | Symbol::NUM_BINARY64 => Some(Ok(Immediate(Symbol::DECODE_F64))),
Symbol::NUM_NAT | Symbol::NUM_NATURAL => Some(Err(DeriveError::Underivable)),
_ => None,
}
}

View file

@ -163,7 +163,6 @@ const fn from_builtin_symbol(symbol: Symbol) -> Option<Result<FlatEncodable, Der
Symbol::NUM_DEC | Symbol::NUM_DECIMAL => Some(Ok(Immediate(Symbol::ENCODE_DEC))),
Symbol::NUM_F32 | Symbol::NUM_BINARY32 => Some(Ok(Immediate(Symbol::ENCODE_F32))),
Symbol::NUM_F64 | Symbol::NUM_BINARY64 => Some(Ok(Immediate(Symbol::ENCODE_F64))),
Symbol::NUM_NAT | Symbol::NUM_NATURAL => Some(Err(DeriveError::Underivable)),
_ => None,
}
}

View file

@ -204,7 +204,6 @@ impl FlatInspectable {
Symbol::NUM_DEC | Symbol::NUM_DECIMAL => Some(Immediate(Symbol::INSPECT_DEC)),
Symbol::NUM_F32 | Symbol::NUM_BINARY32 => Some(Immediate(Symbol::INSPECT_F32)),
Symbol::NUM_F64 | Symbol::NUM_BINARY64 => Some(Immediate(Symbol::INSPECT_F64)),
Symbol::NUM_NAT | Symbol::NUM_NATURAL => Some(Immediate(Symbol::INSPECT_NAT)),
_ => None,
}
}

View file

@ -1192,9 +1192,9 @@ define_builtins! {
80 NUM_MUL_SATURATED: "mulSaturated"
81 NUM_INT: "Int" exposed_type=true
82 NUM_FRAC: "Frac" exposed_type=true
83 NUM_NATURAL: "Natural" exposed_type=true
84 NUM_NAT: "Nat" exposed_type=true
85 NUM_INT_CAST: "intCast"
83 NUM_E: "e"
84 NUM_PI: "pi"
85 NUM_TAU: "tau"
86 NUM_IS_MULTIPLE_OF: "isMultipleOf"
87 NUM_DECIMAL: "Decimal" exposed_type=true
88 NUM_DEC: "Dec" exposed_type=true // the Num.Dectype alias
@ -1270,11 +1270,9 @@ define_builtins! {
158 NUM_IS_FINITE: "isFinite"
159 NUM_MIN: "min"
160 NUM_MAX: "max"
161 NUM_E: "e"
162 NUM_PI: "pi"
163 NUM_TAU: "tau"
164 NUM_BITWISE_NOT: "bitwiseNot"
165 NUM_IS_APPROX_EQ: "isApproxEq"
161 NUM_BITWISE_NOT: "bitwiseNot"
162 NUM_INT_CAST: "intCast"
163 NUM_IS_APPROX_EQ: "isApproxEq"
}
4 BOOL: "Bool" => {
0 BOOL_BOOL: "Bool" exposed_type=true // the Bool.Bool type alias
@ -1631,8 +1629,7 @@ define_builtins! {
30 INSPECT_CUSTOM: "custom"
31 INSPECT_APPLY: "apply"
32 INSPECT_TO_INSPECTOR: "toInspector"
33 INSPECT_NAT: "nat"
34 INSPECT_TO_STR: "toStr"
33 INSPECT_TO_STR: "toStr"
}
15 JSON: "TotallyNotJson" => {
0 JSON_JSON: "TotallyNotJson"

View file

@ -574,12 +574,6 @@ impl<'a> RawFunctionLayout<'a> {
cacheable(Ok(Self::ZeroArgumentThunk(Layout::F32)))
}
// Nat
Alias(Symbol::NUM_NAT, args, _, _) => {
debug_assert!(args.is_empty());
cacheable(Ok(Self::ZeroArgumentThunk(Layout::usize(env.target_info))))
}
Alias(Symbol::INSPECT_ELEM_WALKER | Symbol::INSPECT_KEY_VAL_WALKER, _, var, _) => Self::from_var(env, var),
Alias(symbol, _, var, _) if symbol.is_builtin() => {
@ -2505,10 +2499,6 @@ impl<'a> Layout<'a> {
match symbol {
Symbol::NUM_DECIMAL => cacheable(Ok(Layout::DEC)),
Symbol::NUM_NAT | Symbol::NUM_NATURAL => {
cacheable(Ok(Layout::usize(env.target_info)))
}
Symbol::NUM_NUM | Symbol::NUM_INT | Symbol::NUM_INTEGER
if is_unresolved_var(env.subs, actual_var) =>
{
@ -3054,7 +3044,6 @@ impl<'a> Layout<'a> {
I32 => Layout::I32,
I64 => Layout::I64,
I128 => Layout::I128,
Nat => Layout::usize(target_info),
// f32 int literal bounded by +/- 2^24, so fit it into an i32
F32 => Layout::F32,
// f64 int literal bounded by +/- 2^53, so fit it into an i32

View file

@ -177,7 +177,6 @@ pub enum IntLitWidth {
I32,
I64,
I128,
Nat,
// An int literal can be promoted to an f32/f64/Dec if appropriate. The respective widths for
// integers that can be stored in these float types without losing precision are:
// f32: +/- 2^24
@ -204,8 +203,6 @@ impl IntLitWidth {
I32 => (Signed, 32),
I64 => (Signed, 64),
I128 => (Signed, 128),
// TODO: Nat is target specific!
Nat => (Unsigned, 64),
F32 => (Signed, 24),
F64 => (Signed, 53),
Dec => (Signed, 128),
@ -229,7 +226,6 @@ impl IntLitWidth {
I32 => "I32",
I64 => "I64",
I128 => "I128",
Nat => "Nat",
F32 => "F32",
F64 => "F64",
Dec => "Dec",
@ -249,8 +245,6 @@ impl IntLitWidth {
I32 => i32::MAX as u128,
I64 => i64::MAX as u128,
I128 => i128::MAX as u128,
// TODO: this is target specific!
Nat => u64::MAX as u128,
// Max int value without losing precision: 2^24
F32 => 16_777_216,
// Max int value without losing precision: 2^53
@ -263,7 +257,7 @@ impl IntLitWidth {
pub fn min_value(&self) -> i128 {
use IntLitWidth::*;
match self {
U8 | U16 | U32 | U64 | U128 | Nat => 0,
U8 | U16 | U32 | U64 | U128 => 0,
I8 => i8::MIN as i128,
I16 => i16::MIN as i128,
I32 => i32::MIN as i128,
@ -330,7 +324,6 @@ impl IntLitWidth {
IntLitWidth::I32 => Symbol::NUM_I32,
IntLitWidth::I64 => Symbol::NUM_I64,
IntLitWidth::I128 => Symbol::NUM_I128,
IntLitWidth::Nat => Symbol::NUM_NAT,
IntLitWidth::F32 => Symbol::NUM_F32,
IntLitWidth::F64 => Symbol::NUM_F64,
IntLitWidth::Dec => Symbol::NUM_DEC,
@ -415,7 +408,6 @@ pub const fn int_lit_width_to_variable(w: IntLitWidth) -> Variable {
IntLitWidth::I32 => Variable::I32,
IntLitWidth::I64 => Variable::I64,
IntLitWidth::I128 => Variable::I128,
IntLitWidth::Nat => Variable::NAT,
IntLitWidth::F32 => Variable::F32,
IntLitWidth::F64 => Variable::F64,
IntLitWidth::Dec => Variable::DEC,
@ -440,7 +432,6 @@ const ALL_INT_OR_FLOAT_VARIABLES: &[Variable] = &[
Variable::U32,
Variable::F64,
Variable::I64,
Variable::NAT, // FIXME: Nat's order here depends on the target
Variable::U64,
Variable::I128,
Variable::DEC,
@ -466,7 +457,6 @@ const ALL_INT_VARIABLES: &[Variable] = &[
Variable::I32,
Variable::U32,
Variable::I64,
Variable::NAT, // FIXME: Nat's order here depends on the target
Variable::U64,
Variable::I128,
Variable::U128,

View file

@ -957,7 +957,6 @@ fn write_integer<'a>(
"I32", Symbol::NUM_SIGNED32
"I64", Symbol::NUM_SIGNED64
"I128", Symbol::NUM_SIGNED128
"Nat", Symbol::NUM_NATURAL
}
}

View file

@ -1592,7 +1592,6 @@ fn define_integer_types(subs: &mut Subs) {
integer_type(
subs,
Symbol::NUM_NATURAL,
Symbol::NUM_NAT,
Variable::NATURAL,
Variable::INTEGER_NATURAL,

View file

@ -1553,7 +1553,6 @@ mod debug_types {
U32 | I32 => "32",
U64 | I64 => "64",
U128 | I128 => "128",
Nat => "Nat",
F32 => "F32",
F64 => "F64",
Dec => "Dec",

View file

@ -7,7 +7,6 @@ entry =
toI32: Num.toI32,
toI64: Num.toI64,
toI128: Num.toI128,
toNat: Num.toNat,
toU8: Num.toU8,
toU16: Num.toU16,
toU32: Num.toU32,
@ -16,4 +15,4 @@ entry =
}
main = entry
# ^^^^^ { toI128 : Int * -[[Num.toI128(125)]]-> I128, toI16 : Int w_a -[[Num.toI16(119)]]-> I16, toI32 : Int w_b -[[Num.toI32(121)]]-> I32, toI64 : Int w_c -[[Num.toI64(123)]]-> I64, toI8 : Int w_d -[[Num.toI8(117)]]-> I8, toNat : Int w_e -[[Num.toNat(137)]]-> Nat, toU128 : Int w_f -[[Num.toU128(135)]]-> U128, toU16 : Int w_g -[[Num.toU16(129)]]-> U16, toU32 : Int w_h -[[Num.toU32(131)]]-> U32, toU64 : Int w_i -[[Num.toU64(133)]]-> U64, toU8 : Int w_j -[[Num.toU8(127)]]-> U8 }
# ^^^^^ { toI128 : Int * -[[Num.toI128(125)]]-> I128, toI16 : Int w_a -[[Num.toI16(119)]]-> I16, toI32 : Int w_b -[[Num.toI32(121)]]-> I32, toI64 : Int w_c -[[Num.toI64(123)]]-> I64, toI8 : Int w_d -[[Num.toI8(117)]]-> I8, toU128 : Int w_f -[[Num.toU128(135)]]-> U128, toU16 : Int w_g -[[Num.toU16(129)]]-> U16, toU32 : Int w_h -[[Num.toU32(131)]]-> U32, toU64 : Int w_i -[[Num.toU64(133)]]-> U64, toU8 : Int w_j -[[Num.toU8(127)]]-> U8 }

View file

@ -637,9 +637,6 @@ fn check_and_merge_valid_range<M: MetaCollector>(
Symbol::NUM_I64 | Symbol::NUM_SIGNED64 => {
merge_if!(range.contains_int_width(IntLitWidth::I64))
}
Symbol::NUM_NAT | Symbol::NUM_NATURAL => {
merge_if!(range.contains_int_width(IntLitWidth::Nat))
}
Symbol::NUM_U64 | Symbol::NUM_UNSIGNED64 => {
merge_if!(range.contains_int_width(IntLitWidth::U64))
}