From adf961ba0b97b332d0d9d8b6b7cfce9365f2cdcd Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 22 Jun 2023 14:12:05 -0500 Subject: [PATCH] Use UEnv where possible --- crates/compiler/solve/src/env.rs | 6 ++++++ crates/compiler/solve/src/solve.rs | 26 ++++++++++++------------- crates/compiler/solve/src/specialize.rs | 4 ++-- crates/compiler/solve/src/to_var.rs | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/crates/compiler/solve/src/env.rs b/crates/compiler/solve/src/env.rs index 8698ae8670e..1f795046987 100644 --- a/crates/compiler/solve/src/env.rs +++ b/crates/compiler/solve/src/env.rs @@ -2,6 +2,7 @@ use bumpalo::Bump; use roc_can::{constraint::Constraints, module::ExposedByModule}; use roc_derive::SharedDerivedModule; use roc_types::subs::{Content, Descriptor, Mark, OptVariable, Rank, Subs, Variable}; +use roc_unify::unify::Env as UEnv; use crate::Pools; @@ -72,4 +73,9 @@ impl<'a> Env<'a> { var } + + /// Retrieves an environment for unification. + pub fn uenv<'r>(&'r mut self) -> UEnv<'r> { + UEnv::new(self.subs) + } } diff --git a/crates/compiler/solve/src/solve.rs b/crates/compiler/solve/src/solve.rs index fb890944efe..ea36ca5391b 100644 --- a/crates/compiler/solve/src/solve.rs +++ b/crates/compiler/solve/src/solve.rs @@ -14,7 +14,7 @@ use crate::Aliases; use bumpalo::Bump; use roc_can::abilities::{AbilitiesStore, MemberSpecializationInfo}; use roc_can::constraint::Constraint::{self, *}; -use roc_can::constraint::{Constraints, Cycle, LetConstraint, OpportunisticResolve}; +use roc_can::constraint::{Cycle, LetConstraint, OpportunisticResolve}; use roc_can::expected::{Expected, PExpected}; use roc_debug_flags::dbg_do; #[cfg(debug_assertions)] @@ -30,8 +30,8 @@ use roc_types::subs::{ }; use roc_types::types::{Category, Polarity, Reason, RecordField, Type, TypeExtension, Types, Uls}; use roc_unify::unify::{ - unify, unify_introduced_ability_specialization, Env as UEnv, Mode, Obligated, - SpecializationLsetCollector, Unified::*, + unify, unify_introduced_ability_specialization, Mode, Obligated, SpecializationLsetCollector, + Unified::*, }; mod scope; @@ -484,7 +484,7 @@ fn solve( ); match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, expected, Mode::EQ, @@ -591,7 +591,7 @@ fn solve( ); match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, expected, Mode::EQ, @@ -698,7 +698,7 @@ fn solve( }; match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, expected, mode, @@ -910,7 +910,7 @@ fn solve( ); match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, includes, Mode::PRESENT, @@ -1044,7 +1044,7 @@ fn solve( let snapshot = env.subs.snapshot(); let unify_cond_and_patterns_outcome = unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), branches_var, real_var, Mode::EQ, @@ -1094,7 +1094,7 @@ fn solve( open_tag_union(env, branches_var); let almost_eq = matches!( unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), real_var, branches_var, Mode::EQ, @@ -1112,7 +1112,7 @@ fn solve( // Case 4: incompatible types, report type error. // Re-run first failed unification to get the type diff. match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), real_var, branches_var, Mode::EQ, @@ -1311,7 +1311,7 @@ fn solve( lambda_sets_to_specialize, extra_metadata: _, } = unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, Variable::LIST_U8, Mode::EQ, @@ -1331,7 +1331,7 @@ fn solve( // We explicitly match on the last unify to get the type in the case it errors. match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), actual, Variable::STR, Mode::EQ, @@ -1574,7 +1574,7 @@ fn check_ability_specialization( deep_copy_var_in(env, Rank::toplevel(), root_signature_var, env.arena); let snapshot = env.subs.snapshot(); let unified = unify_introduced_ability_specialization( - &mut UEnv::new(env.subs), + &mut env.uenv(), root_signature_var, symbol_loc_var.value, Mode::EQ, diff --git a/crates/compiler/solve/src/specialize.rs b/crates/compiler/solve/src/specialize.rs index cec27972e68..1ea79cff59a 100644 --- a/crates/compiler/solve/src/specialize.rs +++ b/crates/compiler/solve/src/specialize.rs @@ -17,7 +17,7 @@ use roc_types::{ }, types::{AliasKind, MemberImpl, Polarity, Uls}, }; -use roc_unify::unify::{unify, Env as UEnv, Mode, MustImplementConstraints}; +use roc_unify::unify::{unify, Mode, MustImplementConstraints}; use crate::{ ability::builtin_module_with_unlisted_ability_impl, @@ -574,7 +574,7 @@ fn compact_lambda_set( // 3. Unify `t_f1 ~ t_f2`. trace_compact!(3iter_start. env.subs, this_lambda_set, t_f1, t_f2); let (vars, new_obligations, new_lambda_sets_to_specialize, _meta) = unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), t_f1, t_f2, Mode::LAMBDA_SET_SPECIALIZATION, diff --git a/crates/compiler/solve/src/to_var.rs b/crates/compiler/solve/src/to_var.rs index 7ec197cc0e3..b49cddd1c1d 100644 --- a/crates/compiler/solve/src/to_var.rs +++ b/crates/compiler/solve/src/to_var.rs @@ -17,7 +17,7 @@ use roc_types::{ Category, ExtImplicitOpenness, Polarity, TypeTag, Types, }, }; -use roc_unify::unify::{unify, Env as UEnv, Mode, Unified}; +use roc_unify::unify::{unify, Mode, Unified}; use crate::{ ability::{AbilityImplError, ObligationCache}, @@ -862,7 +862,7 @@ pub(crate) fn type_to_var_help( let category = Category::OpaqueArg; match unify( - &mut UEnv::new(env.subs), + &mut env.uenv(), var, flex_ability, Mode::EQ,