biome icon indicating copy to clipboard operation
biome copied to clipboard

refactor: revisit type-related data structures

Open arendjr opened this issue 11 months ago • 1 comments

Summary

Another huge one, though thankfully a large part of it are snapshots :sweat_smile:

But that's not to say a lot hasn't changed, so let me elaborate what happened here:

  • Type is no longer an Arc-wrapper around TypeInner. I always knew the Arc-based solution was temporary, but I admit I hadn't entirely foreseen how big the refactor would become. The reason Arc wouldn't work going forward is because it would get in the way with full inference where types from modules would be able to reference arbitrary types, even from other modules. The problem with Arc is that it would keep alive types from those other modules, even when such another module gets replaced by the watcher in the module graph. The full inference story hasn't been completed with this PR, but at least it should pave the way for it.
  • TypeData is stored directly inside vectors managed by resolvers. This makes bulk operations on them cheaper, but more importantly: It made it a lot easier to separate type resolution and flattening into separate steps that are easier to reason about independently.
  • Type is only used through the Typed service. The new way Type works is much closer to the Scope and Binding types from the semantic model. It makes consuming the API easier, but it no longer serves a role during inference.
  • TypeReference holds an explicit reference to other types. We already had a TypeReference type, but the way it works has been heavily changed. Any type that previously held an Arc-based Type in one of its fields, now holds a TypeReference instead. That does mean we have to work through the resolvers more in order to follow those references, but this is exactly what we need so that full inference can follow references to other modules, without co-owning their types.

Test Plan

Everything should remain green.

arendjr avatar Apr 26 '25 12:04 arendjr

CodSpeed Performance Report

Merging #5777 will not alter performance

Comparing arendjr:type-refactoring (83f96f9) with main (e950ff9)

Summary

✅ 95 untouched benchmarks

codspeed-hq[bot] avatar Apr 26 '25 17:04 codspeed-hq[bot]