Skip to content

Instantly share code, notes, and snippets.

@retronym
Last active December 14, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/5081754 to your computer and use it in GitHub Desktop.
Save retronym/5081754 to your computer and use it in GitHub Desktop.
types.scala refactoring notes

Typers.scala refactoring

Motivation

  • Coral mutable state in prepration for thread-safe subtyping / glb / type printing.
  • Side benefit: Impose structure on gargantuan source file.
    • Comments in the file that delimit sections are a code smell to me.

What's in there?

  • Type ADT
  • Subtyping / Equivalence
  • LUB/GLB
  • Base Class calculation
  • TypeTraverser / TypeCollector / TypeMap
    • Many instances of these for specific purposes.
    • common owner
    • adaptToNewRun
  • Type constraint solving
  • Miscellania

Proposed structure

  • Types
    • Type ADT
  • TypeComparers
    • Subtyping / Equivalence
  • LubGlbs
  • TypeMaps
    • Base classes for type-map/collect/traverse
    • Implemenatations (perhaps split non-trivial ones like common owner to separate files?)
  • TypeToStrings

New subpackage: scala.reflect.internal.types?

Refactoring methodology.

Impose Structure

  • Keep things compiling after each edit.
    • Temporarily loosen access of referenced privates to public
  • Keep methods in the same order as Types.
  • Restore private once things are grouped accordingly.
    • or private[types] if need be.
  • No other changes in the first refactoring step.

Coral State

  • Analyse the usage of each item of mutable state.
    • Record unique stack trace to the state with Origins.
  • Remove all mutable state the top level. Either.
    • move groups of methods that use them into a nested class which has a copy of that state as fields.
    • Pass the state through the call chain
      • as an extra mutable parameter
      • or an extra immutable parameter + an extra immutable return value.
@xeno-by
Copy link

xeno-by commented Mar 4, 2013

Typers.scala or Types.scala?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment