Skip to content

Direct representation of higher-kinded types #1343

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

Merged
merged 92 commits into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
5866d0d
Allow refinements of new types
odersky May 24, 2016
d30f441
Allow general recursion in refined types.
odersky Jun 29, 2016
5d03186
Better printing of skolems
odersky May 26, 2016
cdb4a1c
New type lambda scheme for hk types
odersky Jun 29, 2016
850dc6f
Introduce recursive types
odersky Jun 29, 2016
af43d32
Abstract type parameters out from type symbols
odersky Jun 29, 2016
aa7f66d
Disable checkInst in RecType
odersky Jun 29, 2016
08a0ea6
Add printing of type lambda trees
odersky Jun 29, 2016
178e90e
Remove special case in parser
odersky May 27, 2016
4bf43f8
Turn on new hk scheme
odersky Jun 29, 2016
5daae27
Multiple fixes
odersky Jun 29, 2016
e56bd1f
Beta-reduce when simplifying
odersky Jun 2, 2016
e61b80a
Refinement of cycle avoidance
odersky Jun 2, 2016
a7d61c0
Make etaExpandIfHk work for non-symbol type params
odersky Jun 2, 2016
d0f82a5
Don't map info of SkolemTypes in type maps
odersky Jun 3, 2016
c136af1
Fixes to BetaReduce and asMemberOf; add a second betaReduce
odersky Jun 29, 2016
ae1f248
Normalize RecTypes on creation to avoid cycles.
odersky Jun 4, 2016
939d9da
Add a second betaReduce
odersky Jun 4, 2016
c35f817
Adapt widenForMatchSelector to new HK scheme
odersky Jun 5, 2016
e36a36a
Fix typeParams for abstract types under completion
odersky Jun 5, 2016
6a7e466
Avoid accidental creation of hk types
odersky Jun 29, 2016
8e84fb0
Eta-expand unapplied types that have type parameters
odersky Jun 29, 2016
68e73e8
Restrict betaReduce to hk applications
odersky Jun 29, 2016
463e99a
Optionally, check kinds match for & and |
odersky Jun 7, 2016
0a5f839
Avoid infinite recursion when comparing recursive types.
odersky Jun 29, 2016
31af865
Fix condition for lambda abstracting in Namer
odersky Jun 29, 2016
5041e93
Make TypeAccumulators follow LazyRefs
odersky Jun 7, 2016
f1bf78b
Avoid creating dependent function types for closures
odersky Jun 8, 2016
830b724
Change tests
odersky Jun 29, 2016
6414f3b
Deal with nested findMember calls over the same RecType
odersky Jun 9, 2016
e749d83
Various tweaks
odersky Jun 29, 2016
d1f809f
Remove old hk scheme
odersky Jun 29, 2016
60d81f8
Start new, direct HK scheme
odersky Jun 29, 2016
3490e01
Make Constraint#bounds work for aliases
odersky Jun 14, 2016
f6efd99
Fix appliedTo and typeParams, and higher kinded subtyping tests
odersky Jun 29, 2016
97e84e6
Fix printing of type lambda trees and types
odersky Jun 18, 2016
73dd039
Various hk related fixes in types
odersky Jun 29, 2016
02ce995
Refactoring of PolyType and TypeLambda
odersky Jun 29, 2016
c28dd1b
Tweaks to appliedTo
odersky Jun 29, 2016
c1e27a0
Change underlying of HKApply
odersky Jun 29, 2016
98b466c
Ensure wildApprox maintains kinds
odersky Jun 20, 2016
0965e1a
Handle TypeLambdas in findMember
odersky Jun 20, 2016
65c26ba
Avoid cyclic errors when reading nsc.Global
odersky Jun 21, 2016
1e48758
Refactor handling of unpickled type params
odersky Jun 29, 2016
960ea75
Allow for HK types in widenForMatchSelector
odersky Jun 22, 2016
e0db04d
Drop bounds checking for type lambdas
odersky Jun 22, 2016
de5d8fe
Skip typeBounds when computing upperBound
odersky Jun 22, 2016
8805dd4
When comparing types revert eta-expansion as needed
odersky Jun 26, 2016
646bf97
Beta-reduce with wildcard arguments if this is safe.
odersky Jun 29, 2016
09f7ab1
Handle findMember for unreduced hk types.
odersky Jun 27, 2016
9a90e81
Handle WildcardType in liftToClasses
odersky Jun 29, 2016
dca1052
Don't make * types higher-kinded in avoid
odersky Jun 29, 2016
4093e13
Don't dealias when applying types
odersky Jun 29, 2016
bb59931
Fixes to hk comparisons
odersky Jun 29, 2016
dc5be65
Special case for TypeRefs in upperbound
odersky Jun 28, 2016
31ecad5
Drop assertion in TypeMap
odersky Jun 29, 2016
9d9965c
Fix parameter unpickling
odersky Jun 28, 2016
a23c1a4
Fixes for printing under -Ytest-pickler
odersky Jun 29, 2016
6bd7ba9
Remove refinement encoding of hk types
odersky Jun 29, 2016
ae360e9
Handle signatures over uninstantiated type variables
odersky Jun 29, 2016
6abde38
Get rid of BindingKind
odersky Jun 29, 2016
68abba1
Simplify appliedTo
odersky Jun 29, 2016
30e15ab
Cleanup of Signature matching
odersky Jun 30, 2016
b6a8bc7
Revert complications in asMemberOf
odersky Jun 30, 2016
32c0135
Refactorings of GenericTypes and underlying/upperbound
odersky Jun 30, 2016
34a068b
Drop Config.checkKinds
odersky Jun 30, 2016
beff8f8
Avoid orphan parameters in Constraint#replace
odersky Jul 2, 2016
eebb4b0
Fix bug in printing untyped New nodes.
odersky Jul 3, 2016
fd62c7b
Disallow higher-kinded types that simulate general existential types
odersky Jul 7, 2016
4693a78
Less eager removal of type parameters from constraint
odersky Jul 7, 2016
2ddb849
Unify aliases when taking a lub.
odersky Jul 4, 2016
c541ef9
Do the right thing for NoDenotation.mapInfo
odersky Jul 7, 2016
78b2672
Add a case where caching was missing.
odersky Jul 5, 2016
223705d
Refactor Typevar instantiation
odersky Jul 7, 2016
5e90215
Drop compareAliasedRefined
odersky Jul 8, 2016
540b38c
More tests
odersky Jul 9, 2016
a200695
Fix SI-2712
odersky Jul 11, 2016
6d7bc49
Address reviewers comments
odersky Jul 11, 2016
055726e
ExtractAPI: Do not miss value parameters of PolyTypes
smarter Jul 12, 2016
a6a142e
ExtractAPI: Add support for TypeLambdas
smarter Jul 12, 2016
1792c9e
ExtractAPI: Add support for RecType
smarter Jul 12, 2016
cdebd91
Allow definition of new types in refinements
odersky Jul 11, 2016
84a1a7a
Avoid dealiasing on type application
odersky Jul 12, 2016
c7f3b45
Drop restriction to 2nd order hk types
odersky Jul 12, 2016
7df0fa5
Enable test for fixed #1181: Typer should preserve aliases in TypeTrees
smarter Jul 12, 2016
1443fd4
Optimize hk comparisons
odersky Jul 12, 2016
f50cb20
Make rewritings of hk applications configurable
odersky Jul 13, 2016
0ff5354
Simplify variance computations
odersky Jul 13, 2016
18b3080
Allow hk parameters in lower bounds
odersky Jul 13, 2016
82fc27f
Fix bounds checking of hk applied typed
odersky Jul 14, 2016
a737b47
Add test case for hk bounds checking
odersky Jul 14, 2016
894c9fb
Bounds of type lambdas compare contravariantly
odersky Jul 15, 2016
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
7 changes: 7 additions & 0 deletions src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ object Config {
*/
final val splitProjections = false

/** If this flag is on, always rewrite an application `S[Ts]` where `S` is an alias for
* `[Xs] -> U` to `[Xs := Ts]U`. If this flag is off, the rewriting is only done if `S` is a
* reference to an instantiated parameter. Turning this flag on was observed to
* give a ~6% speedup on the JUnit test suite.
*/
final val simplifyApplications = true

/** Initial size of superId table */
final val InitialSuperIdsSize = 4096

Expand Down
28 changes: 13 additions & 15 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,21 @@ class TypeApplications(val self: Type) extends AnyVal {
case dealiased: TypeLambda =>
def tryReduce =
if (!args.exists(_.isInstanceOf[TypeBounds])) {
val reduced = dealiased.instantiate(args)
if (dealiased eq stripped) reduced
else reduced match {
case AppliedType(tycon, args) if variancesConform(typParams, tycon.typeParams) =>
// Reducing is safe for type inference, as kind of type constructor does not change
//println(i"reduced: $reduced instead of ${HKApply(self, args)}")
reduced
val followAlias = stripped match {
case stripped: TypeRef =>
stripped.symbol.is(BaseTypeArg)
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 reduction is safe/needed here? Also any reason to not turn that off when Config.simplifyApplications is false?

case _ =>
// Reducing changes kind, keep hk application instead
//println(i"fallback: ${HKApply(self, args)} instead of $reduced")
HKApply(self, args)
Config.simplifyApplications && {
dealiased.resType match {
case AppliedType(tyconBody, _) =>
variancesConform(typParams, tyconBody.typeParams)
// Reducing is safe for type inference, as kind of type constructor does not change
case _ => false
}
}
}
if ((dealiased eq stripped) || followAlias) dealiased.instantiate(args)
else HKApply(self, args)
}
else dealiased.resType match {
case AppliedType(tycon, args1) if tycon.safeDealias ne tycon =>
Expand Down Expand Up @@ -665,11 +668,6 @@ class TypeApplications(val self: Type) extends AnyVal {
}
}

final def typeConstructor(implicit ctx: Context): Type = self.stripTypeVar match {
case AppliedType(tycon, _) => tycon
case self => self
}

/** If this is the image of a type argument; recover the type argument,
* otherwise NoType.
*/
Expand Down
23 changes: 20 additions & 3 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3422,8 +3422,9 @@ object Types {
case tp: HKApply =>
def mapArg(arg: Type, tparam: TypeParamInfo): Type = {
val saved = variance
if (tparam.paramVariance < 0) variance = -variance
else if (tparam.paramVariance == 0) variance = 0
val pvariance = tparam.paramVariance
if (pvariance < 0) variance = -variance
else if (pvariance == 0) variance = 0
Copy link
Member

Choose a reason for hiding this comment

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

variance *= tparam.paramVariance instead of the if/else ? (Same in the case below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great minds think alike :-) See next commit.

try this(arg)
finally variance = saved
}
Expand Down Expand Up @@ -3629,7 +3630,23 @@ object Types {
this(x, prefix)

case tp @ HKApply(tycon, args) =>
foldOver(this(x, tycon), args)
def foldArgs(x: T, tparams: List[TypeParamInfo], args: List[Type]): T =
if (args.isEmpty) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it even possible to create a typelambda with no parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but note that foldArgs is recursive.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see.

assert(tparams.isEmpty)
x
}
else {
val tparam = tparams.head
val saved = variance
val pvariance = tparam.paramVariance
if (pvariance < 0) variance = -variance
else if (pvariance == 0) variance = 0
val acc =
try this(x, args.head)
finally variance = saved
foldArgs(acc, tparams.tail, args.tail)
}
foldArgs(this(x, tycon), tp.typeParams, args)

case tp: AndOrType =>
this(this(x, tp.tp1), tp.tp2)
Expand Down
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ object Checking {
tp.derivedRefinedType(this(parent), name, this(rinfo, nestedCycleOK, nestedCycleOK))
case tp: RecType =>
tp.rebind(this(tp.parent))
case tp @ HKApply(tycon, args) =>
tp.derivedAppliedType(this(tycon), args.map(this(_, nestedCycleOK, nestedCycleOK)))
case tp @ TypeRef(pre, name) =>
try {
// A prefix is interesting if it might contain (transitively) a reference
Expand Down