From d5a99e09335a9a00b7eac56cf4062b5a4c348efd Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 6 Dec 2024 19:36:27 +0100 Subject: [PATCH] Add duplicate symbol debugging code --- compiler/src/symbol_names.rs | 27 +++++++++++++++++++++++++++ std/src/std/option.inko | 2 +- types/src/lib.rs | 9 +++++++++ types/src/specialize.rs | 9 +++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/compiler/src/symbol_names.rs b/compiler/src/symbol_names.rs index 47df3a1fd..6442bd789 100644 --- a/compiler/src/symbol_names.rs +++ b/compiler/src/symbol_names.rs @@ -177,6 +177,33 @@ impl SymbolNames { setup_constants.insert(id, constants); } + // TODO: remove + let mut used: HashMap = + 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 } } } diff --git a/std/src/std/option.inko b/std/src/std/option.inko index e78e96d87..6de1e5117 100644 --- a/std/src/std/option.inko +++ b/std/src/std/option.inko @@ -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) diff --git a/types/src/lib.rs b/types/src/lib.rs index d4d376b41..46f6c7452 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -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), diff --git a/types/src/specialize.rs b/types/src/specialize.rs index b5ecd1caf..a5265843f 100644 --- a/types/src/specialize.rs +++ b/types/src/specialize.rs @@ -321,6 +321,15 @@ impl<'a, 'b, 'c> TypeSpecializer<'a, 'b, 'c> { fn specialize_class(&mut self, class: ClassId, key: Vec) -> 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);