Skip to content

Commit

Permalink
Use UEnv where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Jun 22, 2023
1 parent ad20a2e commit adf961b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions crates/compiler/solve/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
}
}
26 changes: 13 additions & 13 deletions crates/compiler/solve/src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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;
Expand Down Expand Up @@ -484,7 +484,7 @@ fn solve(
);

match unify(
&mut UEnv::new(env.subs),
&mut env.uenv(),
actual,
expected,
Mode::EQ,
Expand Down Expand Up @@ -591,7 +591,7 @@ fn solve(
);

match unify(
&mut UEnv::new(env.subs),
&mut env.uenv(),
actual,
expected,
Mode::EQ,
Expand Down Expand Up @@ -698,7 +698,7 @@ fn solve(
};

match unify(
&mut UEnv::new(env.subs),
&mut env.uenv(),
actual,
expected,
mode,
Expand Down Expand Up @@ -910,7 +910,7 @@ fn solve(
);

match unify(
&mut UEnv::new(env.subs),
&mut env.uenv(),
actual,
includes,
Mode::PRESENT,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/solve/src/specialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -574,7 +574,7 @@ fn compact_lambda_set<P: Phase>(
// 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,
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/solve/src/to_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit adf961b

Please sign in to comment.