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 d3cff96
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
23 changes: 23 additions & 0 deletions compiler/src/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ impl SymbolNames {
setup_constants.insert(id, constants);
}

// TODO: remove
let mut used: HashMap<String, ClassId> =
std::collections::HashMap::new();
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) {
panic!(
"DUPLICATE: {}\n {}: {:?}\n {}: {:?}",
name,
ours.0,
ours.shapes(db),
theirs.0,
theirs.shapes(db),
);
} else {
used.insert(name, ours);
}
}

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
7 changes: 3 additions & 4 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,10 +2048,9 @@ impl ClassInstance {
interned: &mut InternedTypeArguments,
) -> ClassInstance {
let targs = if self.instance_of.is_generic(db) {
// We need to make sure that for different references to the
// same type (e.g. `SomeType[Int]`), the type arguments ID
// is the same so we can reliable compare and hash the
// returned Shape.
// We need to make sure that for different references to the same
// type (e.g. `SomeType[Int]`), the type arguments ID is the same so
// we can reliable compare and hash the returned Shape.
interned.intern(db, self)
} else {
0
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 d3cff96

Please sign in to comment.