mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
remove variable from mono patterns
This commit is contained in:
parent
93297c0051
commit
b9359ffd71
3 changed files with 27 additions and 27 deletions
|
@ -66,7 +66,7 @@ pub enum Test<'a> {
|
||||||
union: crate::exhaustive::Union,
|
union: crate::exhaustive::Union,
|
||||||
arguments: Vec<(Pattern<'a>, Layout<'a>)>,
|
arguments: Vec<(Pattern<'a>, Layout<'a>)>,
|
||||||
},
|
},
|
||||||
IsInt(i64),
|
IsInt(i128),
|
||||||
// float patterns are stored as u64 so they are comparable/hashable
|
// float patterns are stored as u64 so they are comparable/hashable
|
||||||
IsFloat(u64),
|
IsFloat(u64),
|
||||||
IsStr(Box<str>),
|
IsStr(Box<str>),
|
||||||
|
@ -445,10 +445,10 @@ fn test_at_path<'a>(selected_path: &Path, branch: &Branch<'a>, all_tests: &mut V
|
||||||
num_alts: union.alternatives.len(),
|
num_alts: union.alternatives.len(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
IntLiteral(_, v) => {
|
IntLiteral(v) => {
|
||||||
all_tests.push(guarded(IsInt(*v)));
|
all_tests.push(guarded(IsInt(*v)));
|
||||||
}
|
}
|
||||||
FloatLiteral(_, v) => {
|
FloatLiteral(v) => {
|
||||||
all_tests.push(IsFloat(*v));
|
all_tests.push(IsFloat(*v));
|
||||||
}
|
}
|
||||||
StrLiteral(v) => {
|
StrLiteral(v) => {
|
||||||
|
@ -636,7 +636,7 @@ fn to_relevant_branch_help<'a>(
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
|
||||||
IntLiteral(_, int) => match test {
|
IntLiteral(int) => match test {
|
||||||
IsInt(is_int) if int == *is_int => {
|
IsInt(is_int) if int == *is_int => {
|
||||||
start.extend(end);
|
start.extend(end);
|
||||||
Some(Branch {
|
Some(Branch {
|
||||||
|
@ -647,7 +647,7 @@ fn to_relevant_branch_help<'a>(
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
|
||||||
FloatLiteral(_, float) => match test {
|
FloatLiteral(float) => match test {
|
||||||
IsFloat(test_float) if float == *test_float => {
|
IsFloat(test_float) if float == *test_float => {
|
||||||
start.extend(end);
|
start.extend(end);
|
||||||
Some(Branch {
|
Some(Branch {
|
||||||
|
@ -740,8 +740,8 @@ fn needs_tests(pattern: &Pattern) -> bool {
|
||||||
| AppliedTag { .. }
|
| AppliedTag { .. }
|
||||||
| BitLiteral { .. }
|
| BitLiteral { .. }
|
||||||
| EnumLiteral { .. }
|
| EnumLiteral { .. }
|
||||||
| IntLiteral(_, _)
|
| IntLiteral(_)
|
||||||
| FloatLiteral(_, _)
|
| FloatLiteral(_)
|
||||||
| StrLiteral(_) => true,
|
| StrLiteral(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1092,9 @@ fn test_to_equality<'a>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Test::IsInt(test_int) => {
|
Test::IsInt(test_int) => {
|
||||||
let lhs = Expr::Literal(Literal::Int(test_int));
|
// TODO don't downcast i128 here
|
||||||
|
debug_assert!(test_int <= i64::MAX as i128);
|
||||||
|
let lhs = Expr::Literal(Literal::Int(test_int as i64));
|
||||||
let lhs_symbol = env.unique_symbol();
|
let lhs_symbol = env.unique_symbol();
|
||||||
stores.push((lhs_symbol, Layout::Builtin(Builtin::Int64), lhs));
|
stores.push((lhs_symbol, Layout::Builtin(Builtin::Int64), lhs));
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub enum Pattern {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
Int(i64),
|
Int(i128),
|
||||||
Bit(bool),
|
Bit(bool),
|
||||||
Byte(u8),
|
Byte(u8),
|
||||||
Float(u64),
|
Float(u64),
|
||||||
|
@ -48,8 +48,8 @@ fn simplify(pattern: &crate::ir::Pattern) -> Pattern {
|
||||||
use crate::ir::Pattern::*;
|
use crate::ir::Pattern::*;
|
||||||
|
|
||||||
match pattern {
|
match pattern {
|
||||||
IntLiteral(_, v) => Literal(Literal::Int(*v)),
|
IntLiteral(v) => Literal(Literal::Int(*v)),
|
||||||
FloatLiteral(_, v) => Literal(Literal::Float(*v)),
|
FloatLiteral(v) => Literal(Literal::Float(*v)),
|
||||||
StrLiteral(v) => Literal(Literal::Str(v.clone())),
|
StrLiteral(v) => Literal(Literal::Str(v.clone())),
|
||||||
|
|
||||||
// To make sure these are exhaustive, we have to "fake" a union here
|
// To make sure these are exhaustive, we have to "fake" a union here
|
||||||
|
|
|
@ -4774,8 +4774,8 @@ fn store_pattern<'a>(
|
||||||
Underscore => {
|
Underscore => {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
IntLiteral(_, _)
|
IntLiteral(_)
|
||||||
| FloatLiteral(_, _)
|
| FloatLiteral(_)
|
||||||
| EnumLiteral { .. }
|
| EnumLiteral { .. }
|
||||||
| BitLiteral { .. }
|
| BitLiteral { .. }
|
||||||
| StrLiteral(_) => {}
|
| StrLiteral(_) => {}
|
||||||
|
@ -4814,8 +4814,8 @@ fn store_pattern<'a>(
|
||||||
Underscore => {
|
Underscore => {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
IntLiteral(_, _)
|
IntLiteral(_)
|
||||||
| FloatLiteral(_, _)
|
| FloatLiteral(_)
|
||||||
| EnumLiteral { .. }
|
| EnumLiteral { .. }
|
||||||
| BitLiteral { .. }
|
| BitLiteral { .. }
|
||||||
| StrLiteral(_) => {}
|
| StrLiteral(_) => {}
|
||||||
|
@ -4909,8 +4909,8 @@ fn store_record_destruct<'a>(
|
||||||
//
|
//
|
||||||
// internally. But `y` is never used, so we must make sure it't not stored/loaded.
|
// internally. But `y` is never used, so we must make sure it't not stored/loaded.
|
||||||
}
|
}
|
||||||
IntLiteral(_, _)
|
IntLiteral(_)
|
||||||
| FloatLiteral(_, _)
|
| FloatLiteral(_)
|
||||||
| EnumLiteral { .. }
|
| EnumLiteral { .. }
|
||||||
| BitLiteral { .. }
|
| BitLiteral { .. }
|
||||||
| StrLiteral(_) => {}
|
| StrLiteral(_) => {}
|
||||||
|
@ -5654,8 +5654,8 @@ fn call_by_name<'a>(
|
||||||
pub enum Pattern<'a> {
|
pub enum Pattern<'a> {
|
||||||
Identifier(Symbol),
|
Identifier(Symbol),
|
||||||
Underscore,
|
Underscore,
|
||||||
IntLiteral(Variable, i64),
|
IntLiteral(i128),
|
||||||
FloatLiteral(Variable, u64),
|
FloatLiteral(u64),
|
||||||
BitLiteral {
|
BitLiteral {
|
||||||
value: bool,
|
value: bool,
|
||||||
tag_name: TagName,
|
tag_name: TagName,
|
||||||
|
@ -5728,10 +5728,8 @@ fn from_can_pattern_help<'a>(
|
||||||
match can_pattern {
|
match can_pattern {
|
||||||
Underscore => Ok(Pattern::Underscore),
|
Underscore => Ok(Pattern::Underscore),
|
||||||
Identifier(symbol) => Ok(Pattern::Identifier(*symbol)),
|
Identifier(symbol) => Ok(Pattern::Identifier(*symbol)),
|
||||||
IntLiteral(precision_var, int) => Ok(Pattern::IntLiteral(*precision_var, *int)),
|
IntLiteral(_, int) => Ok(Pattern::IntLiteral(*int as i128)),
|
||||||
FloatLiteral(precision_var, float) => {
|
FloatLiteral(_, float) => Ok(Pattern::FloatLiteral(f64::to_bits(*float))),
|
||||||
Ok(Pattern::FloatLiteral(*precision_var, f64::to_bits(*float)))
|
|
||||||
}
|
|
||||||
StrLiteral(v) => Ok(Pattern::StrLiteral(v.clone())),
|
StrLiteral(v) => Ok(Pattern::StrLiteral(v.clone())),
|
||||||
Shadowed(region, ident) => Err(RuntimeError::Shadowing {
|
Shadowed(region, ident) => Err(RuntimeError::Shadowing {
|
||||||
original_region: *region,
|
original_region: *region,
|
||||||
|
@ -5744,10 +5742,10 @@ fn from_can_pattern_help<'a>(
|
||||||
}
|
}
|
||||||
NumLiteral(var, num) => {
|
NumLiteral(var, num) => {
|
||||||
match num_argument_to_int_or_float(env.subs, env.ptr_bytes, *var, false) {
|
match num_argument_to_int_or_float(env.subs, env.ptr_bytes, *var, false) {
|
||||||
IntOrFloat::SignedIntType(_) => Ok(Pattern::IntLiteral(*var, *num)),
|
IntOrFloat::SignedIntType(_) => Ok(Pattern::IntLiteral(*num as i128)),
|
||||||
IntOrFloat::UnsignedIntType(_) => Ok(Pattern::IntLiteral(*var, *num)),
|
IntOrFloat::UnsignedIntType(_) => Ok(Pattern::IntLiteral(*num as i128)),
|
||||||
IntOrFloat::BinaryFloatType(_) => Ok(Pattern::FloatLiteral(*var, *num as u64)),
|
IntOrFloat::BinaryFloatType(_) => Ok(Pattern::FloatLiteral(*num as u64)),
|
||||||
IntOrFloat::DecimalFloatType(_) => Ok(Pattern::FloatLiteral(*var, *num as u64)),
|
IntOrFloat::DecimalFloatType(_) => Ok(Pattern::FloatLiteral(*num as u64)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue