orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
40 stars 3 forks source link

Update type checker to work with OrcO objects #165

Open arthurp opened 7 years ago

arthurp commented 7 years ago

Currently (f366592a033fb97fd273f54cd17275ac13bfe3bd) the type checker does not work. It needs to be updated to handle the OrcO constructs. This could be somewhat involved and this issue only addresses making it work in a useful way not adding any advanced features.

This initial minimal working type checker will support the following:

Specifically, unsupported features are:

arthurp commented 7 years ago

If we use a type member encoding in the type checker we could use something like this:

Every type parameter is encoded as a uniquely renamed type parameter (renaming is needed so that subclass code cannot accidentally reference the superclass type parameter, this is not theoretically that relevant, but it's a big practical concern Arthur thinks.). The renaming is stored with the class so subclasses can access it. Subclasses instantiate the superclass parameter using whatever value is given in the superclass reference. Instantiating a class with a type parameter will create an anonymous subclass which binds the appropriate member.

class C[A] ...
class D[A] extends C[List[A]] ...

is encoded as:

class C {
  type _C_A
  ...
}
class D extends C {
  type _D_A
  type _C_A = List[_D_A]
}

new D[Integer] is encoded as new D { type _D_A = Integer }.

Note that because constructors are just functions at the moment this encoding will only work if the type checker can combine type members with function type parameters correctly so that the return type is as expected.