Skip to content

Change HK types scheme #731

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 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a3f1e56
Clean up of logic in typeDefSig
odersky Jul 11, 2015
b07727b
Avoid cyclic references in containsRefinedThis
odersky Jul 12, 2015
2b75c95
Eta expand type arguments corresponding to lambdas
odersky Jul 14, 2015
c11e20d
Check argument lengths in typedAppliedTypeTree
odersky Jul 14, 2015
d02d383
Better diagnostics for failed sigName calls.
odersky Jul 14, 2015
6b5ff03
Black hole detection for LazyRefs
odersky Jul 14, 2015
fc8e20a
Turn assertion into a test in etaExpandArgs.
odersky Jul 14, 2015
ce831f8
Fix argument eta expansion
odersky Jul 14, 2015
6c992f0
Strenghten condition in EtaExpandIfLambda
odersky Jul 14, 2015
43377ad
Adapt arguments in all type applications
odersky Jul 14, 2015
35adb64
Avoid generating companion-methods for non-class types.
odersky Jul 15, 2015
38ac13a
Add EtaReduce method.
odersky Jul 16, 2015
8029f65
Add comment.
odersky Jul 17, 2015
c5958aa
Add a test that logs the classpath to pinpoint setup failures.
odersky Jul 17, 2015
24e3403
Don't eta expand in appliedTo
odersky Jul 14, 2015
5e45dc5
Always lambda abstract TempPolyTypes representing types.
odersky Jul 15, 2015
968999a
Lambda abstract all TypeRefs when unpickling.
odersky Jul 15, 2015
d474100
A non-class typeref has type parameters only if subtype of a lambda c…
odersky Jul 15, 2015
accbed2
Drop parameterizeWith
odersky Jul 17, 2015
c2a124f
Allow to use safe substitution in LambdaAbstract
odersky Jul 19, 2015
9bb3f52
Use EtaExpand instead of LambdaAbstract when unpickling typerefs
odersky Jul 19, 2015
8610b4d
Avoid cycles when eliminating existentials in unpickling
odersky Jul 19, 2015
7b751f8
Don't lambda abstract derived types
odersky Jul 19, 2015
253adb0
Temporary fix to testLifted
odersky Jul 19, 2015
f679830
Follow alias types when computing type params.
odersky Jul 19, 2015
484afef
Try to eta reduce type applications.
odersky Jul 19, 2015
5f779f6
Project all high-kinded types with #Apply
odersky Jul 19, 2015
7cb91c7
Better error reporting in TreePickler
odersky Jul 19, 2015
8b1d320
Adapt type arguments in typedAppliedTypeTree
odersky Jul 19, 2015
4b06dea
Add missing position to error
odersky Jul 19, 2015
e24d164
Rename Apply -> hkApply
odersky Jul 20, 2015
7582c0e
Simplify EtaReduce
odersky Jul 20, 2015
4a5bf98
Rename of hk args HK$x -> hk$x
odersky Jul 20, 2015
974c503
Remove magic from derivedRefinedType.
odersky Jul 20, 2015
7eaa515
Replace isLambda with ifHK
odersky Jul 20, 2015
ab55221
Rewrite compareHK to be kind-correct
odersky Jul 20, 2015
03be249
Fix problem in typeParams
odersky Jul 20, 2015
9c75b53
Generalize eta reduction to partially applied types.
odersky Jul 21, 2015
fecd591
Disallow wildcard arguments to higher-kinded types...
odersky Jul 21, 2015
140eb10
Keep track of parameter bounds in LambdaAbstract and EtaReduce
odersky Jul 21, 2015
fd0fa8e
Avoid orphan RefinedThis types in glb/lub.
odersky Jul 22, 2015
887f815
Move failing test to pending.
odersky Jul 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class Definitions {
/** The set of HigherKindedXYZ traits encountered so far */
def lambdaTraits: Set[Symbol] = myLambdaTraits

private var lambdaTraitForVariances = mutable.Map[List[Int], ClassSymbol]()
private var LambdaTraitForVariances = mutable.Map[List[Int], ClassSymbol]()

/** The HigherKinded trait corresponding to symbols `boundSyms` (which are assumed
* to be the type parameters of a higher-kided type). This is a class symbol that
Expand All @@ -512,7 +512,7 @@ class Definitions {
* - for each positive or negative variance v_i there is a parent trait Pj which
* is the same as LambdaXYZ except that it has `I` in i-th position.
*/
def lambdaTrait(vcs: List[Int]): ClassSymbol = {
def LambdaTrait(vcs: List[Int]): ClassSymbol = {
assert(vcs.nonEmpty)

def varianceFlags(v: Int) = v match {
Expand All @@ -526,17 +526,17 @@ class Definitions {
val cls = denot.asClass.classSymbol
val paramDecls = newScope
for (i <- 0 until vcs.length)
newTypeParam(cls, tpnme.lambdaArgName(i), varianceFlags(vcs(i)), paramDecls)
newTypeField(cls, tpnme.Apply, Covariant, paramDecls)
newTypeParam(cls, tpnme.LambdaArgName(i), varianceFlags(vcs(i)), paramDecls)
newTypeField(cls, tpnme.hkApply, Covariant, paramDecls)
val parentTraitRefs =
for (i <- 0 until vcs.length if vcs(i) != 0)
yield lambdaTrait(vcs.updated(i, 0)).typeRef
yield LambdaTrait(vcs.updated(i, 0)).typeRef
denot.info = ClassInfo(
ScalaPackageClass.thisType, cls, ObjectClass.typeRef :: parentTraitRefs.toList, paramDecls)
}
}

val traitName = tpnme.lambdaTraitName(vcs)
val traitName = tpnme.LambdaTraitName(vcs)

def createTrait = {
val cls = newClassSymbol(
Expand All @@ -548,7 +548,7 @@ class Definitions {
cls
}

lambdaTraitForVariances.getOrElseUpdate(vcs, createTrait)
LambdaTraitForVariances.getOrElseUpdate(vcs, createTrait)
}

// ----- primitive value class machinery ------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ object NameOps {
/** The index of the higher-kinded type parameter with this name.
* Pre: isLambdaArgName.
*/
def lambdaArgIndex: Int =
def LambdaArgIndex: Int =
name.drop(tpnme.LAMBDA_ARG_PREFIX.length).toString.toInt

/** If the name ends with $nn where nn are
Expand Down
8 changes: 4 additions & 4 deletions src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ object StdNames {
final val WILDCARD_STAR: N = "_*"
final val REIFY_TREECREATOR_PREFIX: N = "$treecreator"
final val REIFY_TYPECREATOR_PREFIX: N = "$typecreator"
final val LAMBDA_ARG_PREFIX: N = "HK$"
final val LAMBDA_ARG_PREFIX: N = "hk$"
final val LAMBDA_ARG_PREFIXhead: Char = LAMBDA_ARG_PREFIX.head

final val Any: N = "Any"
Expand Down Expand Up @@ -311,7 +311,7 @@ object StdNames {

val AnnotatedType: N = "AnnotatedType"
val AppliedTypeTree: N = "AppliedTypeTree"
val Apply: N = "Apply"
val hkApply: N = "$apply"
val ArrayAnnotArg: N = "ArrayAnnotArg"
val Constant: N = "Constant"
val ConstantType: N = "ConstantType"
Expand Down Expand Up @@ -737,8 +737,8 @@ object StdNames {
def syntheticTypeParamNames(num: Int): List[TypeName] =
(0 until num).map(syntheticTypeParamName)(breakOut)

def lambdaTraitName(vcs: List[Int]): TypeName = LambdaPrefix ++ vcs.map(varianceSuffix).mkString
def lambdaArgName(n: Int) = LAMBDA_ARG_PREFIX ++ n.toString
def LambdaTraitName(vcs: List[Int]): TypeName = LambdaPrefix ++ vcs.map(varianceSuffix).mkString
def LambdaArgName(n: Int) = LAMBDA_ARG_PREFIX ++ n.toString

final val Conforms = encode("<:<")

Expand Down
27 changes: 27 additions & 0 deletions src/dotty/tools/dotc/core/Substituters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,31 @@ trait Substituters { this: Context =>
final class SubstParamsMap(from: BindingType, to: List[Type]) extends DeepTypeMap {
def apply(tp: Type) = substParams(tp, from, to, this)
}

/** A map for "cycle safe substitutions" which do not force the denotation
* of a TypeRef unless the name matches up with one of the substituted symbols.
*/
final class SafeSubstMap(from: List[Symbol], to: List[Type]) extends TypeMap {
def apply(tp: Type): Type = tp match {
case tp: NamedType =>
try {
var sym: Symbol = null
var fs = from
var ts = to
while (fs.nonEmpty) {
if (fs.head.name == tp.name) {
if (sym == null) sym = tp.symbol
if (fs.head eq sym) return ts.head
}
fs = fs.tail
ts = ts.tail
}
tp.newLikeThis(apply(tp.prefix))
}
catch {
case ex: CyclicReference => tp.derivedSelect(apply(tp.prefix))
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment explaining why we need to deal with CyclicReference exceptions this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have noted the reason before. There was an CyclicReference error raised but I no longer remember under what circumstances.

}
case _ => mapOver(tp)
}
}
}
Loading