orc-lang / orc

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

Change linearization algorithm for Orc Objects #188

Closed arthurp closed 7 years ago

arthurp commented 7 years ago

I propose that we change the Orc linearization algorithm to enforce the ordering of "A with B". Specifically, I propose we switch to use the C3 linearization algorithm. It is used in Python among other languages.

I believe that C3 is identical with Scala's linearization in cases where they both produce a linearization. The difference is that C3 does not produce a linearization if classes being mixed together disagree in the order of superclasses in "A with B".

The reason to make this change is that lifting this restriction later is much easier that adding a restriction that may break code. Also unless we have specific cases where ordering should not matter I think requiring ordering will make combining features using mix-ins more predictable.

Lifting the Restriction

One way to lift the restriction in a clean and controlled way would be to allow "super type annotations" similar to self type annotations. These would require that the super reference have a specific type which could be an intersection type "A & B". Since intersection types are not ordered this would allow A and B to be included in the superclass (and hence supertype) in any order as long as they are both present.

dkitchin commented 7 years ago

C3 seems reasonable to me. Writing large Orc programs will be a good opportunity to discover if C3 is overly conservative for our use case, and if so we can use those results to decide whether and how to relax it.

jthywiss commented 7 years ago

Wow, Dylan. It's been a long time since I looked at that language, though I still have the language manual on my bookshelf.

Anyway, I agree that C3 looks good.

arthurp commented 7 years ago

Fixed as of 43a6c10883405b65bc884557d24e2d148777c45d