mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
ensure VarId always encodes root var
otherwise variables with the same root, but different values would be different once imported in another module
This commit is contained in:
parent
c589be43c6
commit
36e6950daa
4 changed files with 45 additions and 23 deletions
|
@ -62,15 +62,18 @@ pub enum SolvedBool {
|
|||
}
|
||||
|
||||
impl SolvedBool {
|
||||
pub fn from_bool(boolean: &boolean_algebra::Bool) -> Self {
|
||||
pub fn from_bool(boolean: &boolean_algebra::Bool, subs: &Subs) -> Self {
|
||||
use boolean_algebra::Bool;
|
||||
|
||||
// NOTE we blindly trust that `cvar` is a root and has a FlexVar as content
|
||||
match boolean {
|
||||
Bool::Shared => SolvedBool::SolvedShared,
|
||||
Bool::Container(cvar, mvars) => SolvedBool::SolvedContainer(
|
||||
VarId::from_var(*cvar),
|
||||
mvars.iter().map(|mvar| VarId::from_var(*mvar)).collect(),
|
||||
VarId::from_var(*cvar, subs),
|
||||
mvars
|
||||
.iter()
|
||||
.map(|mvar| VarId::from_var(*mvar, subs))
|
||||
.collect(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +158,7 @@ impl SolvedType {
|
|||
}
|
||||
|
||||
SolvedType::RecursiveTagUnion(
|
||||
VarId::from_var(rec_var),
|
||||
VarId::from_var(rec_var, solved_subs.inner()),
|
||||
solved_tags,
|
||||
Box::new(solved_ext),
|
||||
)
|
||||
|
@ -171,7 +174,7 @@ impl SolvedType {
|
|||
|
||||
SolvedType::Alias(symbol, solved_args, Box::new(solved_type))
|
||||
}
|
||||
Boolean(val) => SolvedType::Boolean(SolvedBool::from_bool(&val)),
|
||||
Boolean(val) => SolvedType::Boolean(SolvedBool::from_bool(&val, solved_subs.inner())),
|
||||
Variable(var) => Self::from_var(solved_subs.inner(), var),
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +183,7 @@ impl SolvedType {
|
|||
use crate::subs::Content::*;
|
||||
|
||||
match subs.get_without_compacting(var).content {
|
||||
FlexVar(_) => SolvedType::Flex(VarId::from_var(var)),
|
||||
FlexVar(_) => SolvedType::Flex(VarId::from_var(var, subs)),
|
||||
RigidVar(name) => SolvedType::Rigid(name),
|
||||
Structure(flat_type) => Self::from_flat_type(subs, flat_type),
|
||||
Alias(symbol, args, actual_var) => {
|
||||
|
@ -270,11 +273,15 @@ impl SolvedType {
|
|||
|
||||
let ext = Self::from_var(subs, ext_var);
|
||||
|
||||
SolvedType::RecursiveTagUnion(VarId::from_var(rec_var), new_tags, Box::new(ext))
|
||||
SolvedType::RecursiveTagUnion(
|
||||
VarId::from_var(rec_var, subs),
|
||||
new_tags,
|
||||
Box::new(ext),
|
||||
)
|
||||
}
|
||||
EmptyRecord => SolvedType::EmptyRecord,
|
||||
EmptyTagUnion => SolvedType::EmptyTagUnion,
|
||||
Boolean(val) => SolvedType::Boolean(SolvedBool::from_bool(&val)),
|
||||
Boolean(val) => SolvedType::Boolean(SolvedBool::from_bool(&val, subs)),
|
||||
Erroneous(problem) => SolvedType::Erroneous(problem),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,7 +199,8 @@ impl UnifyKey for Variable {
|
|||
pub struct VarId(u32);
|
||||
|
||||
impl VarId {
|
||||
pub fn from_var(var: Variable) -> Self {
|
||||
pub fn from_var(var: Variable, subs: &Subs) -> Self {
|
||||
let var = subs.get_root_key_without_compacting(var);
|
||||
let Variable(n) = var;
|
||||
|
||||
VarId(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue