diff --git a/compiler/constrain/src/uniq.rs b/compiler/constrain/src/uniq.rs index b5bfc0ff5c..4420b304f4 100644 --- a/compiler/constrain/src/uniq.rs +++ b/compiler/constrain/src/uniq.rs @@ -431,16 +431,27 @@ fn unique_num(val_type: Type, uvar: Variable) -> Type { attr_type(Bool::variable(uvar), num_utype) } -fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) { +fn unique_midlevel(var_store: &mut VarStore, val_type: Type, transform: F) -> (Variable, Type) +where + F: Fn(Type) -> Type, +{ let num_uvar = var_store.fresh(); let val_utype = attr_type(Bool::variable(num_uvar), val_type); - let num_type = num_integer(val_utype); + let num_type = transform(val_utype); (num_uvar, num_type) } +fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) { + unique_midlevel(var_store, val_type, num_integer) +} + +fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) { + unique_midlevel(var_store, val_type, num_floatingpoint) +} + fn unique_int(var_store: &mut VarStore) -> (Variable, Type) { let (var1, typ) = unique_integer(var_store, num_signed64()); @@ -449,16 +460,6 @@ fn unique_int(var_store: &mut VarStore) -> (Variable, Type) { (var1, typ) } -fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) { - let num_uvar = var_store.fresh(); - - let val_utype = attr_type(Bool::variable(num_uvar), val_type); - - let num_type = num_floatingpoint(val_utype); - - (num_uvar, num_type) -} - fn unique_float(var_store: &mut VarStore) -> (Variable, Type) { let (var1, typ) = unique_floatingpoint(var_store, num_binary64());