mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
Wrap unification subs in Env
This commit is contained in:
parent
0989b2cb82
commit
c0e976f544
8 changed files with 375 additions and 356 deletions
|
@ -7,7 +7,7 @@ use roc_region::all::{Loc, Region};
|
|||
use roc_solve_problem::{TypeError, UnderivableReason, Unfulfilled};
|
||||
use roc_types::subs::{instantiate_rigids, Content, FlatType, GetSubsSlice, Rank, Subs, Variable};
|
||||
use roc_types::types::{AliasKind, Category, PatternCategory};
|
||||
use roc_unify::unify::MustImplementConstraints;
|
||||
use roc_unify::unify::{Env, MustImplementConstraints};
|
||||
use roc_unify::unify::{MustImplementAbility, Obligated};
|
||||
|
||||
use crate::solve::type_to_var;
|
||||
|
@ -573,10 +573,15 @@ pub fn resolve_ability_specialization(
|
|||
let signature_var = member_def.signature_var();
|
||||
|
||||
instantiate_rigids(subs, signature_var);
|
||||
let (_vars, must_implement_ability, _lambda_sets_to_specialize, _meta) =
|
||||
unify(subs, specialization_var, signature_var, Mode::EQ).expect_success(
|
||||
"If resolving a specialization, the specialization must be known to typecheck.",
|
||||
);
|
||||
let (_vars, must_implement_ability, _lambda_sets_to_specialize, _meta) = unify(
|
||||
&mut Env::new(subs),
|
||||
specialization_var,
|
||||
signature_var,
|
||||
Mode::EQ,
|
||||
)
|
||||
.expect_success(
|
||||
"If resolving a specialization, the specialization must be known to typecheck.",
|
||||
);
|
||||
|
||||
subs.rollback_to(snapshot);
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ use roc_types::types::{
|
|||
OptAbleVar, Reason, TypeExtension, Uls,
|
||||
};
|
||||
use roc_unify::unify::{
|
||||
unify, unify_introduced_ability_specialization, Mode, MustImplementConstraints, Obligated,
|
||||
SpecializationLsetCollector, Unified::*,
|
||||
unify, unify_introduced_ability_specialization, Env as UEnv, Mode, MustImplementConstraints,
|
||||
Obligated, SpecializationLsetCollector, Unified::*,
|
||||
};
|
||||
|
||||
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
|
||||
|
@ -963,7 +963,7 @@ fn solve(
|
|||
let expectation = &constraints.expectations[expectation_index.index()];
|
||||
let expected = type_to_var(subs, rank, pools, aliases, expectation.get_type_ref());
|
||||
|
||||
match unify(subs, actual, expected, Mode::EQ) {
|
||||
match unify(&mut UEnv::new(subs), actual, expected, Mode::EQ) {
|
||||
Success {
|
||||
vars,
|
||||
must_implement_ability,
|
||||
|
@ -1021,7 +1021,7 @@ fn solve(
|
|||
);
|
||||
let target = *target;
|
||||
|
||||
match unify(subs, actual, target, Mode::EQ) {
|
||||
match unify(&mut UEnv::new(subs), actual, target, Mode::EQ) {
|
||||
Success {
|
||||
vars,
|
||||
// ERROR NOT REPORTED
|
||||
|
@ -1081,7 +1081,7 @@ fn solve(
|
|||
let expected =
|
||||
type_to_var(subs, rank, pools, aliases, expectation.get_type_ref());
|
||||
|
||||
match unify(subs, actual, expected, Mode::EQ) {
|
||||
match unify(&mut UEnv::new(subs), actual, expected, Mode::EQ) {
|
||||
Success {
|
||||
vars,
|
||||
must_implement_ability,
|
||||
|
@ -1165,7 +1165,7 @@ fn solve(
|
|||
_ => Mode::EQ,
|
||||
};
|
||||
|
||||
match unify(subs, actual, expected, mode) {
|
||||
match unify(&mut UEnv::new(subs), actual, expected, mode) {
|
||||
Success {
|
||||
vars,
|
||||
must_implement_ability,
|
||||
|
@ -1334,7 +1334,7 @@ fn solve(
|
|||
);
|
||||
let includes = type_to_var(subs, rank, pools, aliases, &tag_ty);
|
||||
|
||||
match unify(subs, actual, includes, Mode::PRESENT) {
|
||||
match unify(&mut UEnv::new(subs), actual, includes, Mode::PRESENT) {
|
||||
Success {
|
||||
vars,
|
||||
must_implement_ability,
|
||||
|
@ -1442,7 +1442,7 @@ fn solve(
|
|||
);
|
||||
|
||||
let snapshot = subs.snapshot();
|
||||
let outcome = unify(subs, real_var, branches_var, Mode::EQ);
|
||||
let outcome = unify(&mut UEnv::new(subs), real_var, branches_var, Mode::EQ);
|
||||
|
||||
let should_check_exhaustiveness;
|
||||
match outcome {
|
||||
|
@ -1477,7 +1477,7 @@ fn solve(
|
|||
// open_tag_union(subs, real_var);
|
||||
open_tag_union(subs, branches_var);
|
||||
let almost_eq = matches!(
|
||||
unify(subs, real_var, branches_var, Mode::EQ),
|
||||
unify(&mut UEnv::new(subs), real_var, branches_var, Mode::EQ),
|
||||
Success { .. }
|
||||
);
|
||||
|
||||
|
@ -1489,7 +1489,7 @@ fn solve(
|
|||
} else {
|
||||
// Case 4: incompatible types, report type error.
|
||||
// Re-run first failed unification to get the type diff.
|
||||
match unify(subs, real_var, branches_var, Mode::EQ) {
|
||||
match unify(&mut UEnv::new(subs), real_var, branches_var, Mode::EQ) {
|
||||
Failure(vars, actual_type, expected_type, _bad_impls) => {
|
||||
introduce(subs, rank, pools, &vars);
|
||||
|
||||
|
@ -1720,7 +1720,7 @@ fn check_ability_specialization(
|
|||
deep_copy_var_in(subs, Rank::toplevel(), pools, root_signature_var, arena);
|
||||
let snapshot = subs.snapshot();
|
||||
let unified = unify_introduced_ability_specialization(
|
||||
subs,
|
||||
&mut UEnv::new(subs),
|
||||
root_signature_var,
|
||||
symbol_loc_var.value,
|
||||
Mode::EQ,
|
||||
|
@ -2238,7 +2238,8 @@ fn compact_lambda_set<P: Phase>(
|
|||
// 3. Unify `t_f1 ~ t_f2`.
|
||||
trace_compact!(3iter_start. subs, this_lambda_set, t_f1, t_f2);
|
||||
let (vars, new_must_implement_ability, new_lambda_sets_to_specialize, _meta) =
|
||||
unify(subs, t_f1, t_f2, Mode::EQ).expect_success("ambient functions don't unify");
|
||||
unify(&mut UEnv::new(subs), t_f1, t_f2, Mode::EQ)
|
||||
.expect_success("ambient functions don't unify");
|
||||
trace_compact!(3iter_end. subs, t_f1);
|
||||
|
||||
introduce(subs, target_rank, pools, &vars);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue