Skip to content

Uniqueness of Data Type Instances

Frederik Hennig requested to merge fhennig/unique-types into backend-rework

This MR refactors the type system to avoid multiple creation of data type instances by caching them. This improves the performance of comparing types, avoids unnecessary copies, and increases general efficiency of data type handling.

  • Introduce the metaclass PsTypeMeta which keeps track of all existing instances of subclasses of PsType, and alters class instantiation to return existing instances instead of creating new ones
  • Refactor __eq__ and __hash__, which are now implemented in PsType and use an __args__ method implemented by each instantiable subclass
  • Fix constify/deconstify to no longer copy their arguments, but memoize their return values
  • Refactor and extend documentation of the type system to reflect the changes

Some minor additions come along:

  • Move create_type from types.quick to types.parsing
  • Rename types.basic_types to types.types
  • Move PsType, constify and deconstify to types.meta
  • Add an inheritance diagram to the type system documentation
Edited by Frederik Hennig

Merge request reports