Skip to content

Commit

Permalink
Add duplicate symbol debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Dec 6, 2024
1 parent 32adda1 commit d5a99e0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
27 changes: 27 additions & 0 deletions compiler/src/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,33 @@ impl SymbolNames {
setup_constants.insert(id, constants);
}

// TODO: remove
let mut used: HashMap<String, ClassId> =
std::collections::HashMap::new();
let mut duplicates = false;
let mut pairs: Vec<(ClassId, String)> =
classes.iter().map(|(k, v)| (*k, v.clone())).collect();

pairs.sort_by(|(a, _), (b, _)| a.0.cmp(&b.0));

for (ours, name) in pairs {
if let Some(theirs) = used.get(&name) {
println!("DUPLICATE: {} ({:?} == {:?})", name, ours, theirs);
println!(
" sources = {:?} == {:?}",
ours.specialization_source(db),
theirs.specialization_source(db)
);
println!(" ours = {:?}", ours.shapes(db));
println!(" theirs = {:?}", theirs.shapes(db));
duplicates = true;
} else {
used.insert(name, ours);
}
}

assert!(!duplicates);

Self { classes, methods, constants, setup_classes, setup_constants }
}
}
Expand Down
2 changes: 1 addition & 1 deletion std/src/std/option.inko
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import std.fmt (Format, Formatter)
#
# An `Option` is is either a `Some` containing a value, or a `None` that doesn't
# contain a value.
class pub enum Option[T] {
class pub inline enum Option[T] {
# A value of type `T`.
case Some(T)

Expand Down
9 changes: 9 additions & 0 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,15 @@ impl ClassInstance {
_ if self.instance_of.is_inline_type(db) => {
let ins = self.interned(db, interned);

// TODO: remove
if ins.instance_of.is_generic(db) && self.type_arguments == 0 {
panic!(
"instance of {} without arguments, with shapes {:?}",
ins.instance_of.name(db),
ins.instance_of.shapes(db)
);
}

match default {
Shape::Mut => Shape::StackMut(ins),
Shape::Ref => Shape::StackRef(ins),
Expand Down
9 changes: 9 additions & 0 deletions types/src/specialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ impl<'a, 'b, 'c> TypeSpecializer<'a, 'b, 'c> {
fn specialize_class(&mut self, class: ClassId, key: Vec<Shape>) -> ClassId {
let new = class.clone_for_specialization(self.db);

// TODO: remove
if new.0 == 3170 || new.0 == 3165 {
println!(
"specializing {} with shapes {:?}",
class.name(self.db),
key
);
}

self.classes.push(new);
new.set_specialization_source(self.db, class);

Expand Down

0 comments on commit d5a99e0

Please sign in to comment.