Skip to content

Commit

Permalink
wip debugging: seem to have found unrelated issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljklein committed Feb 20, 2024
1 parent f4933b4 commit ce415a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
13 changes: 5 additions & 8 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ pub enum Type {
/// but it makes handling them both easier. The TypeVariableId should
/// never be bound over during type checking, but during monomorphization it
/// will be and thus needs the full TypeVariable link.
///
/// TODO: prevent_numeric before merge do we need N? here?
Forall(Generics, Box<Type>),

/// A type-level integer. Included to let an Array's size type variable
Expand Down Expand Up @@ -751,7 +749,6 @@ impl Type {
/// given type bindings, ignoring what each type variable is bound to in the TypeBindings.
pub(crate) fn generalize_from_substitutions(self, type_bindings: TypeBindings) -> Type {
let polymorphic_type_vars = vecmap(type_bindings, |(_, (type_var, binding))| {
// TODO: does this make sense?
let kind = match binding {
Type::TypeVariable(_, kind) => kind,
_ => panic!("Type of TypeVariable is non-variable"),
Expand Down Expand Up @@ -947,9 +944,6 @@ impl Type {
};

let this = self.substitute(bindings).follow_bindings();
// println!("TODO remove try_bind_to_maybe_constant: {:?} {:?} {:?} {:?} ||| {:?}", self, var, target_length, bindings, this);


match &this {
Type::Constant(length) if *length == target_length => {
bindings.insert(target_id, (var.clone(), this));
Expand All @@ -962,6 +956,9 @@ impl Type {
// A TypeVariable is less specific than a MaybeConstant, so we bind
// to the other type variable instead.
Type::TypeVariable(new_var, kind) => {
if *kind == TypeVariableKind::NotConstant {
return Err(UnificationError)
}
let borrow = new_var.borrow();
match &*borrow {
TypeBinding::Bound(typ) => {
Expand Down Expand Up @@ -1196,7 +1193,7 @@ impl Type {
// let other_follow = other.follow_bindings();
let other_follow = other.substitute(bindings).follow_bindings();

// println!("TODO remove: try_unify: {:?} {:?} {:?} {:?}", var, length, other, other_follow);
// println!("TODO remove: try_unify constant: {:?} {:?} {:?} {:?}", var, length, other, other_follow);

other.try_bind_to_maybe_constant(var, *length, bindings)
}),
Expand Down Expand Up @@ -1366,7 +1363,7 @@ impl Type {
// Don't need to issue an error here if not, it will be done in unify_with_coercions
let mut bindings = TypeBindings::new();
if element1.try_unify(element2, &mut bindings).is_ok() {
// println!("TODO remove: convert_array_expression_to_slice {:?} {:?} {:?} {:?}", expression, this, target, interner);
println!("TODO remove: convert_array_expression_to_slice {:?} {:?} {:?} {:?}", expression, this, target, bindings);

convert_array_expression_to_slice(expression, this, target, interner);
Self::apply_type_bindings(bindings);
Expand Down
6 changes: 1 addition & 5 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,7 @@ impl<'interner> Monomorphizer<'interner> {
HirType::TraitAsType(..) => {
unreachable!("All TraitAsType should be replaced before calling convert_type");
}
HirType::NamedGeneric(binding, _, prevent_numeric) => {
if *prevent_numeric {
panic!("TODO: convert_type NamedGeneric: {:?} {:?} {:?}", typ, binding, prevent_numeric);
}

HirType::NamedGeneric(binding, _, _prevent_numeric) => {
if let TypeBinding::Bound(binding) = &*binding.borrow() {
return self.convert_type(binding);
}
Expand Down
12 changes: 10 additions & 2 deletions test_programs/compile_success_empty/map_slice/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
fn foo(x: [Field]) -> [Field] {
x
}

fn main() {
let x: [Field] = [3; 4];
let _ = x.map(|y| y);
let x0: [Field] = [3333333; 444444];
let _ = foo(x0);
let x: [Field; 444444] = [3333333; 444444];
let y: [Field] = x;
let z = foo(y);
let _ = z.map(|w| w);
}

#[test]
Expand Down

0 comments on commit ce415a2

Please sign in to comment.