Skip to content

Commit a7d9ff3

Browse files
committed
fix(visitor): fold, don't drop, definitions past the per-line cap
_add capped each (file, line) bucket at 8 entries and dropped the rest. When a type appears in many compile units (e.g. BlockType across ~160 CUs), only one copy carries a fully-defined nested type such as BlockType::NameInfo, and it could fall past the cap and be discarded, leaving the nested type referenced but never defined. Now, once the bucket is full, fold the overflow object into an existing entry it can merge with instead of dropping it, preserving the unique content it carries. The append + parameter-name sync + merge flow is otherwise untouched, so parameter names are unaffected. Also guard TypeDef.merge against a None value, which the extra merges can now reach.
1 parent d2ea23f commit a7d9ff3

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎src/dwarf2cpp/models.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ def merge(self, other: Object) -> bool:
194194
if self.kind != other.kind or self.name != other.name or type(self.value) is not type(other.value):
195195
return False
196196

197-
if isinstance(self.value, str):
197+
if self.value is None:
198+
pass
199+
elif isinstance(self.value, str):
198200
if self.value != other.value:
199201
return False
200-
else:
201-
if not self.value.merge(other.value):
202-
return False
202+
elif not self.value.merge(other.value):
203+
return False
203204

204205
self.alignment = self.alignment or other.alignment
205206
return True

‎src/dwarf2cpp/visitor.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,15 @@ def generic_visit(self, die: DWARFDie) -> None:
752752
self.visit(child)
753753

754754
def _add(self, filepath: str, lineno: int, obj: Object) -> None:
755-
file = self._files[filepath]
756-
lines = file[lineno]
755+
lines = self._files[filepath][lineno]
757756

758-
if len(lines) >= 8:
759-
# too many items on a single line (template instantiations?)
757+
if len(lines) < 8:
758+
lines.append(obj)
760759
return
761760

762-
lines.append(obj)
761+
for existing in lines:
762+
if existing.merge(obj):
763+
return
763764

764765
def _register_template(self, key: str | int, lineno: int, template: Template) -> Template | None:
765766
if not template.declaration:

0 commit comments

Comments
 (0)