-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[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
[WIP] Change HK encoding #1282
Conversation
7c1f511
to
775eb8a
Compare
@@ -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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not bindingKind_BYTE?
e1a4cb0
to
1aed088
Compare
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) |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This val is unused
5cd8627
to
2019307
Compare
(rt: RecType) => (b1(rt) & b2(rt)) | ||
.withBindingKind( | ||
BindingKind.fromVariance( | ||
(tparam1.memberVariance + tparam2.memberVariance) / 2)) |
There was a problem hiding this comment.
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)
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
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
4b59b1e
to
5a20984
Compare
Rebased to master |
[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.
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 => |
There was a problem hiding this comment.
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?
Superseded by #1343 |
We would like to encode HK types directly into refined types, without type projections. This PR should eventually lead to this goal. Status:
RecType
.