Week 10 of my Google Summer of Code journey with CircuitVerse (July 27th to August 2nd) was all about getting back on track.
Last week was a little slow because I was travelling back to college and setting everything up again. As soon as this week started, I wanted to catch up and finally turn the type-safety discussion from Week 9 into actual code.
๐ก๏ธ Making the Pipeline More Type-Safe
I spent the start of the week researching how to make the types stricter.
The main refactor ended up being:
- ๐งฉ Moving the canonical data contracts into a dedicated
canonical.types.tsfile. - ๐ Replacing loose
WireNode/CVScopestyle structures with the real simulatorNodeandScopetypes wherever possible. - ๐งฑ Defining proper shared types such as
CanonicalProject,CanonicalScope,CanonicalComponent,CanonicalNet,CanonicalLayoutand component property types. - ๐ฏ Keeping the truly dynamic component lookup at one documented boundary instead of letting
unknownand type assertions spread through the whole pipeline. - ๐๏ธ Adding typed component-constructor handling so the importer can dynamically rebuild components without falling back to
any.
The main idea was pretty simple: if the pipeline already knows the shape of something, TypeScript should know it too.
On July 29th, I raised PR #1173 with this refactor.
๐ค PR Review
Soon after opening the PR, CodeRabbit caught something much more interesting than a normal type issue.
The comparator inside canonicalSort was using interface order for some component pairs and structural fingerprints for others. That meant the comparison was not a proper total order and, in some cases, sorting could depend on the original array order.
For a normal application that might just look like a sorting bug. For a canonical format, that is dangerous because component IDs, net IDs and eventually the canonical hash all depend on deterministic ordering.
The fix was to make the rule consistent:
๐ง Compare the structural fingerprint first. Only when the fingerprints are equal, use the interface order as the tie-breaker.
I updated the comparator and also cleaned up a few unsafe non-null assumptions around wire-port and routing lookups.
CodeRabbit marked the issue as addressed after the follow-up commit. ๐
After the review fixes, PR #1173 was merged later this week!
๐ฎ What's Next
Next week, Iโll start working on tests and see how the canonical pipeline holds up on more real circuits.
Back on track. Time to test! ๐งชโก

Top comments (0)