Skip to content

[WIP] Change HK encoding #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 86 commits into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 27, 2016

We would like to encode HK types directly into refined types, without type projections. This PR should eventually lead to this goal. Status:

  • Disentangle recursion and refinement through the introduction of RecType.
  • Drop the notion that type parameters are always symbols
  • Introduce new encoding
  • Drop superfluous code
  • Decide whether we should drop named type parameters

@odersky odersky force-pushed the change-hk-refinements branch from 7c1f511 to 775eb8a Compare May 27, 2016 09:49
@@ -129,7 +129,7 @@ Standard-Section: "ASTs" TopLevelStat*
SUPERtype Length this_Type underlying_Type
REFINEDtype Length underlying_Type refinement_NameRef info_Type
APPLIEDtype Length tycon_Type arg_Type*
TYPEBOUNDS Length low_Type high_Type
TYPEBOUNDS Length low_Type high_Type bindingKind_Nat?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not bindingKind_BYTE?

@odersky odersky force-pushed the change-hk-refinements branch from e1a4cb0 to 1aed088 Compare May 27, 2016 13:20
@odersky
Copy link
Contributor Author

odersky commented May 27, 2016

Rebased to master


/** A refined type parent { refinement }
* @param refinedName The name of the refinement declaration
* @param infoFn: A function that produces the info of the refinement declaration,
* given the refined type itself.
*/
abstract case class RefinedType(parent: Type, refinedName: Name)
extends CachedProxyType with BindingType with ValueType {
abstract case class RefinedType(private var myParent: Type, refinedName: Name, private var myRefinedInfo: Type)
Copy link
Member

@smarter smarter May 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation of the params above needs to be updated

@smarter
Copy link
Member

smarter commented May 30, 2016

Note: the introduction of RecType will require some changes to the sbt ExtractAPI phase but nothing too complicated, I'll have a look once this PR is complete.

def apply(argBindingFns: List[RecType => TypeBounds],
bodyFn: RecType => Type)(implicit ctx: Context): Type = {
assert(Config.newHK)
val argNames = argBindingFns.indices.toList.map(tpnme.hkArg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This val is unused

@odersky odersky force-pushed the change-hk-refinements branch from 5cd8627 to 2019307 Compare May 30, 2016 17:00
(rt: RecType) => (b1(rt) & b2(rt))
.withBindingKind(
BindingKind.fromVariance(
(tparam1.memberVariance + tparam2.memberVariance) / 2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tparam1.memberVariance.commonVariance(tparam2.memberVariance)

odersky added 8 commits June 8, 2016 12:15
Will be used to encode higher-kinded type parameters.
Previously a refinement could only apply to a type bound in
the parent. This restriction needs to be dropped for the new
encoding of hk type parameters.
Treat parent like refinedInfo. Introduce isBinding convenience method
in TypeBounds.
They not print similar to scalac: "?x" where `x` is a unique number.

Todo: An offline explanation what they are, similar to javac. I.e.

   ... ?3 ...

   where ?3: T
odersky added 8 commits June 8, 2016 12:19
TypeMaps do the same, so it is logical, and helps
prevent subtle errors as when we mispredicted whether
a RecType contains references that point to it.
Fixes some discrepancies in Tasty typing.
Without this step, anonymous functions can have dependent
types which causes the parameter references to "leak out"
to types in the environment in illegal ways. This caused
a tasty failure for Typer before (not sure why the failure
was not observed under the old hk scheme).
This seems to be required to make Typer compile, and it is logical
that we should do this. We still need to study how it fits in the
general context.

Also, it required neg test to be fixed. With the change, the error is
now reported earlier.
Skolem types are eliminated by pickling, so they should not appear
in the "before-pickling" output.
compileMixed failed because there was a cycle between immutable.Seq (compiled) and
parallel.ParSeq (loaded from classfile). Inspection of the completion log (turn completions
Printer on) and the stack trace showed that there's nothing we can do here. The old hk scheme
did not go into the cycle because it did not force an unrelated type. I believe with enough
tweaking we would also hva egotten a cycle in the old hk scheme.

The test is "fixed" by adding parallel.ParSeq to the files to compile.
Those tests do not work yet with the revised hk scheme.
Before trying to fix this, we should first decide what parts of
named parameters should be kept.
Updates to make dotty compile after rebase
@odersky odersky force-pushed the change-hk-refinements branch from 4b59b1e to 5a20984 Compare June 8, 2016 13:08
@odersky
Copy link
Contributor Author

odersky commented Jun 8, 2016

Rebased to master

odersky added 13 commits June 9, 2016 13:25
[This was an unncessessary and wrong fix. The real problem was in findMember]

This seems to be required to make Typer compile, and it is logical
that we should do this. We still need to study how it fits in the
general context.

Also, it required neg test to be fixed. With the change, the error is
now reported earlier. (reverted from commit a6caf1c)
Improve explanation
The theory is that if two refined types have the same refined name, then
they are likely to be of related classes. So it seems more fruitful to
check the argument before the typeconstructor because that way we test
the part that's more likely to fail first. Rough observations seem to
indicate a 3% improvement in the junit test time.
Drop some unnecessary cases; improve comments.
Try to combine type constructor and arguments under a
common LazyRef.
Make it check variances.
Drop recursive definition of RefinedThis - this is now
taken over by RecType. Drop RefinedThis.
The logic avoiding forcing is no longer needed.
@@ -264,21 +264,7 @@ class TypeApplications(val self: Type) extends AnyVal {
self.cls.typeParams
case self: TypeRef =>
val tsym = self.symbol
if (tsym.isClass) tsym.typeParams
else tsym.infoOrCompleter match {
case completer: TypeParamsCompleter =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why isn't this needed anymore? Does this mean that the TypeParamsCompleter class can be deleted?

@odersky
Copy link
Contributor Author

odersky commented Jun 29, 2016

Superseded by #1343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants