Skip to content

Commit

Permalink
Remove arc_real/bind_arc as they are not needed with Arc everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jan 27, 2019
1 parent fb6f3e1 commit b2e8705
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 65 deletions.
2 changes: 1 addition & 1 deletion check/src/implicits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl<'a, 'b, 'c> MutVisitor<'c> for ResolveImplicitsVisitor<'a, 'b> {
.get(&id.name)
.cloned();
if let Some(implicit_bindings) = implicit_bindings {
let typ = self.tc.subs.arc_real(&id.typ).clone();
let typ = id.typ.clone();
let id = TypedIdent {
name: id.name.clone(),
typ: typ,
Expand Down
30 changes: 3 additions & 27 deletions check/src/substitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::base::{
fixed::{FixedMap, FixedVec},
kind::ArcKind,
symbol::Symbol,
types::{self, ArcType, InternerVisitor, Skolem, Type, TypeInterner, TypeVariable, Walker},
types::{self, ArcType, InternerVisitor, Skolem, Type, TypeInterner, Walker},
};
use crate::typ::RcType;

Expand Down Expand Up @@ -483,32 +483,8 @@ impl Substitution<RcType> {
)
}

pub fn arc_real(&self, typ: &ArcType) -> &RcType {
let var = match &**typ {
Type::Variable(var) => var,
_ => panic!("Expected variable"),
};
self.real(self.get_var(var.id).expect("Variable"))
}

// Stub kept in case multiple types are attempted again
pub fn bind_arc(&self, typ: &RcType) -> ArcType {
if let Some(var) = typ.get_var() {
return Type::variable(var.clone());
}
let id = self.union.borrow_mut().insert(UnionByLevel {
..UnionByLevel::default()
});
assert!(id == self.variables.len());
debug!("New arc var {}", self.variables.len());

let var = TypeVariable {
id: id as u32,
kind: typ.kind().into_owned(),
};
let var_type = (&mut &*self).variable(var.clone()); // TODO do we need to allocate a variable here?
self.variables.push(var_type);
self.insert(id as u32, typ.clone());

Type::variable(var)
typ.clone()
}
}
23 changes: 2 additions & 21 deletions check/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ impl<'a> Typecheck<'a> {
let tail = tail_expr(expr);
crate::implicits::resolve(self, tail);
self.generalize_type(0, &mut typ, tail.span);
self.generalize_variables(0, &mut [].iter_mut(), tail);
}
self.generalize_variables(0, &mut [].iter_mut(), expr);

{
struct ReplaceVisitor<'a: 'b, 'b> {
Expand Down Expand Up @@ -2939,24 +2939,5 @@ fn generalize_binding(
) {
crate::implicits::resolve(generalizer.tc, &mut binding.expr);

generalizer.tc.type_variables.enter_scope();

{
let mut type_cache = &generalizer.tc.subs;
generalizer.tc.type_variables.extend(
resolved_type
.forall_params()
.map(|param| (param.id.clone(), type_cache.hole())),
);
}

{
generalizer.generalize_type_top(resolved_type);

generalizer.generalize_variables(
&mut binding.args.iter_mut().map(|arg| &mut arg.name),
&mut binding.expr,
);
}
generalizer.tc.type_variables.exit_scope();
generalizer.generalize_type_top(resolved_type);
}
22 changes: 6 additions & 16 deletions check/src/typecheck/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,12 @@ impl<'a, 'b> TypeGeneralizer<'a, 'b> {
self.visit_ident(&mut id.value)
}
fn visit_typ(&mut self, typ: &mut ArcType) {
if let Type::Variable(var) = &**typ {
let ref typ = self.generalizer.tc.subs.arc_real(typ).clone();
{
let mut type_cache = &self.generalizer.tc.subs;
self.generalizer.tc.type_variables.extend(
typ.forall_params()
.map(|param| (param.id.clone(), type_cache.hole())),
);
}
debug!("Variable generalize {}", typ);
if let Some(typ) = self.generalizer.generalize_type(typ) {
debug!("End generalize {}", typ);
self.generalizer.tc.subs.replace(var.id, typ);
} else {
debug!("End variable generalize");
}
debug!("Variable generalize {}", typ);
if let Some(new_type) = self.generalizer.generalize_type(typ) {
*typ = new_type;
debug!("End generalize {}", typ);
} else {
debug!("End variable generalize");
}
}
}
Expand Down

0 comments on commit b2e8705

Please sign in to comment.