Remove unused while-loop
This commit is contained in:
parent
51c341450b
commit
edb2784f4a
@ -40,14 +40,15 @@ type TypeIdRef = Rc<RefCell<usize>>;
|
|||||||
pub struct TypeHints {
|
pub struct TypeHints {
|
||||||
/// Simple list of types that variables can refrence
|
/// Simple list of types that variables can refrence
|
||||||
hints: RefCell<Vec<TypeKind>>,
|
hints: RefCell<Vec<TypeKind>>,
|
||||||
types: RefCell<Vec<TypeIdRef>>,
|
/// Indirect ID-references, referring to hints-vec
|
||||||
|
type_refs: RefCell<Vec<TypeIdRef>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeHints {
|
impl TypeHints {
|
||||||
pub fn new(&self, ty: TypeKind) -> TypeIdRef {
|
pub fn new(&self, ty: TypeKind) -> TypeIdRef {
|
||||||
let idx = self.hints.borrow().len();
|
let idx = self.hints.borrow().len();
|
||||||
let typecell = Rc::new(RefCell::new(idx));
|
let typecell = Rc::new(RefCell::new(idx));
|
||||||
self.types.borrow_mut().push(typecell.clone());
|
self.type_refs.borrow_mut().push(typecell.clone());
|
||||||
self.hints.borrow_mut().push(ty);
|
self.hints.borrow_mut().push(ty);
|
||||||
typecell
|
typecell
|
||||||
}
|
}
|
||||||
@ -70,19 +71,13 @@ impl<'outer> ScopeHints<'outer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_type(&self, mut idx: usize) -> Option<TypeKind> {
|
pub fn retrieve_type(&self, idx: usize) -> Option<TypeKind> {
|
||||||
// Just make sure we have the correct idx
|
let inner_idx = self
|
||||||
let mut inner_idx = self.types.types.borrow().get(idx).map(|i| *i.borrow())?;
|
.types
|
||||||
let mut limit = 50;
|
.type_refs
|
||||||
while inner_idx != idx {
|
.borrow()
|
||||||
idx = inner_idx;
|
.get(idx)
|
||||||
inner_idx = self.types.types.borrow().get(idx).map(|i| *i.borrow())?;
|
.map(|i| *i.borrow())?;
|
||||||
limit -= 1;
|
|
||||||
if limit < 0 {
|
|
||||||
// Should never happen, but just to avoid infinite loops
|
|
||||||
panic!("Limit reached!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.types.hints.borrow().get(inner_idx).copied()
|
self.types.hints.borrow().get(inner_idx).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +128,7 @@ impl<'outer> ScopeHints<'outer> {
|
|||||||
.get_unchecked(*hint2.0.borrow())
|
.get_unchecked(*hint2.0.borrow())
|
||||||
.clone();
|
.clone();
|
||||||
self.narrow_to_type(&hint1, &ty)?;
|
self.narrow_to_type(&hint1, &ty)?;
|
||||||
for idx in self.types.types.borrow_mut().iter_mut() {
|
for idx in self.types.type_refs.borrow_mut().iter_mut() {
|
||||||
if *idx == hint2.0 {
|
if *idx == hint2.0 {
|
||||||
*idx.borrow_mut() = *hint1.0.borrow();
|
*idx.borrow_mut() = *hint1.0.borrow();
|
||||||
}
|
}
|
||||||
@ -198,7 +193,7 @@ impl<'scope> TypeRef<'scope> {
|
|||||||
Ok(ty) => TypeRef::Literal(*ty),
|
Ok(ty) => TypeRef::Literal(*ty),
|
||||||
Err(vague) => match &vague {
|
Err(vague) => match &vague {
|
||||||
super::VagueType::Hinted(idx) => TypeRef::Hint(ScopeHint(
|
super::VagueType::Hinted(idx) => TypeRef::Hint(ScopeHint(
|
||||||
unsafe { hints.types.types.borrow().get_unchecked(*idx).clone() },
|
unsafe { hints.types.type_refs.borrow().get_unchecked(*idx).clone() },
|
||||||
hints,
|
hints,
|
||||||
)),
|
)),
|
||||||
_ => TypeRef::Hint(hints.new_vague(vague)),
|
_ => TypeRef::Hint(hints.new_vague(vague)),
|
||||||
|
Loading…
Reference in New Issue
Block a user