aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeApplications.scala
Commit message (Collapse)AuthorAgeFilesLines
* Clean up config.Printers importsOlivier Blanvillain2016-09-231-1/+1
| | | | And remove the not used Printer#echo
* Take curried type lambdas into accountMartin Odersky2016-07-221-4/+3
| | | | | Adapt operations TypeApplications and TypeComparer to account for the possibilities of curried type lambdas.
* HK reduction: Remove special-case for typerefsGuillaume Martres2016-07-181-12/+7
| | | | | | | | | | | | | | | | | | | | | | | | | The special case: case stripped: TypeRef => stripped.symbol.is(BaseTypeArg) is wrong because you might still want to reduce applications involving TypeRefs which are not base class parameters, like in: class Foo[A] type Alias[X] = Foo[X] val x: Alias[Int] = ??? `Alias` is a TypeRef so before this commit `Alias[Int]` was never reduced to `Foo[Int]`. It should have been: case stripped: TypeRef if stripped.symbol.is(BaseTypeArg) => true But even this is incorrect: it assumes that we can always safely reduce HK applications involving base class parameters, this is not the case when the parameter kind is different from the rhs kind as illustrated by `i1181c.scala`. We fix this by simply dropping the special case.
* Fix bounds checking of hk applied typedMartin Odersky2016-07-141-3/+4
| | | | | Previous logic could only handle classes as constructors. Also, address other reviewers comments.
* Allow hk parameters in lower boundsMartin Odersky2016-07-131-3/+5
|
* Make rewritings of hk applications configurableMartin Odersky2016-07-131-15/+13
| | | | | | | | | Beta-reduce only if `Config.simplifyApplications` is true. Turning off beta-reduction revealed two problems which are also fixed in this commit: 1. Bad treatement of higher-kinded argyments in cyclicity checking 2. Wrong variance for higher-kinded arguments in TypeAccumulator
* Avoid dealiasing on type applicationMartin Odersky2016-07-121-33/+48
| | | | | | | | | When applying a type alias of a type lambda, keep the original application instead of reducing. But reduce anyway if - the reduced type is an application where the type constructor has the same kind as the original type constructor, or - some of the arguments are wildcards.
* Address reviewers commentsMartin Odersky2016-07-111-14/+11
|
* Fix SI-2712Martin Odersky2016-07-111-3/+3
| | | | | Allows partially instantiated types as type constrictors when inferring higher-kinded types.
* Disallow higher-kinded types that simulate general existential typesMartin Odersky2016-07-111-5/+36
| | | | | | | | | | | We cannot handle such types in general. So we now check that a hk application C[args] where some of the arguments are wildcards does not have as a supertype a hk application ([X] -> B)[args]
* Drop Config.checkKindsMartin Odersky2016-07-111-70/+5
| | | | | Allows us to drop also the involved knownHK method. Lots of other cleanups.
* Refactorings of GenericTypes and underlying/upperboundMartin Odersky2016-07-111-5/+4
| | | | | | | 1. Make genericType a trait instead of a class. 2. Make TypeLambda a type proxy 3. Split underlying in TypeProxy into underlying and superType 4. Cleanups in many other places
* Simplify appliedToMartin Odersky2016-07-111-23/+9
| | | | Only use one method instead of a succession of two.
* Remove refinement encoding of hk typesMartin Odersky2016-07-111-307/+37
| | | | | | | | | | Remove the code that implemented the encoding of hk types using refinements. Drop the notion that RefinedTypes can be type parameters. This is no longer true under the new representation. Also, refactoring MemberBinding -> TypeParamInfo
* Don't dealias when applying typesMartin Odersky2016-07-111-4/+6
| | | | | | | | | | | | Keep the higher-kinded application instead. This should be better for inference. We have to evaluate the performance impact. Maybe dealias if the kind stays the same? Also, reduce Nothing[...] to Nothing Nothing cannot be a type constructor in a HK application because it does not have type parameters. Avoid the problemn by the reduction above.
* Beta-reduce with wildcard arguments if this is safe.Martin Odersky2016-07-111-3/+45
| | | | | | | | Makes pos/partialApplications compile. - Fix appliedTo for aliasTypes Returned a general TypeBounds instance before.
* Refactor handling of unpickled type paramsMartin Odersky2016-07-111-4/+5
| | | | | | | | | | | | | | | | | | | | | | | Under the new hk scheme we discovered that type parameters are sometimes unpickled in the wrong order. The fault was always present but the previous hk schemes were somehow lenient enough in their subtyping rules to not discover the problem. E.g., when reading Coder.scala, dotc believed that parameter `A` of `TraversableOnce#BufferedCanBuildFrom` is higher-kinded and parameter `CC` is first-order where the opposite is true. This commit hardens the way we read type parameters in order to make this swap impossible by design. - Revert auto-healing in derivedAppliedType The healing hid a real error about order of type parameters in Scala2 unpickling which was fixed in the previous commits. The healing caused Map.scala to fail because it is possible that type parameters are mis-prediced to be Nil in an F-bounded context. - Smallish fixes to type applications
* Tweaks to appliedToMartin Odersky2016-07-111-4/+11
| | | | | | | | | - Allow appliedTo over TypeBounds - Difference in handling of empty type parameter lists - Always consider EtaExpansions in appliedTo EtaExpanions were not simplified before in Coder.scala and collections.scala. Need to come back and simplify appliedTo logic.
* Refactoring of PolyType and TypeLambdaMartin Odersky2016-07-111-1/+1
| | | | | | | Make them each inherit from common BaseType GenericType. That way we avoid inheriting accidentally stuff from PolyType in TypeLambda. Also, Fix adaptation of type lambdas. Don't confuse them with PolyTypes.
* Fix appliedTo and typeParams, and higher kinded subtyping testsMartin Odersky2016-07-111-13/+42
| | | | Add existential type elimination for HKApply
* Start new, direct HK schemeMartin Odersky2016-07-111-86/+137
| | | | | - Re-introduce newHK option. Label some things that will be removed with OLD.
* Remove old hk schemeMartin Odersky2016-07-111-270/+37
| | | | | | | | | | | | - Simplify RefinedType - Drop recursive definition of RefinedThis - this is now taken over by RecType. - Drop RefinedThis. - Simplify typeParams The logic avoiding forcing is no longer needed. - Remove unused code and out of date comments.
* Various tweaksMartin Odersky2016-07-111-6/+15
| | | | | | | | | | | | | | | | | | | | | | - Swap order of subtype tests 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. - Cleanups Drop some unnecessary cases; improve comments. - Smarter handling of LazyRefs in betaReduce Try to combine type constructor and arguments under a common LazyRef. - Optimize RecType/RecType comparisons - Fix compareHkLambda, make it check variances.
* Fix condition for lambda abstracting in NamerMartin Odersky2016-07-111-7/+3
| | | | | | | | | | | The previous condition could make a (derived) type a * type for a little while even though it had type parameters. This loophole caused collection/generic/MapFactory.scala and with it compile-stdlib to fail. Refinement for knownHK for PolyParams pos test t2082.scala shows that knownHK can be constructed before the binder PolyType of a PolyParam is initialized.
* Avoid infinite recursion when comparing recursive types.Martin Odersky2016-07-111-2/+2
| | | | | | | | | | | | | | | The previous scheme goes into an infinite recursion if the recursive type does not contain a reference to itself. Also, make typeParams more defensive The problematic case is something like { z => CC { type hk$0 = z.hk$0; type(param) hk$0 } Here $hk0 becomes a type parameter through CC and the type lambda. It's true that such types are eliminated later on. But we want to avoid mispredictions at all points.
* Optionally, check kinds match for & and |Martin Odersky2016-07-111-1/+29
| | | | Optionally, check kinds of operands of & and | match.
* Restrict betaReduce to hk applicationsMartin Odersky2016-07-111-1/+9
| | | | | | | | Also, handle LazyRefs conservatively in isReferredTo Without the change we risk losing RecTypes because it looks like nobody refers to them. This was observed for pos/i974.scala.
* Eta-expand unapplied types that have type parametersMartin Odersky2016-07-111-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We would like to change from a scheme where eta-expansion was prototype driven to one where unapplied parameterized types are always eta expanded. The reason is that we might miss some eta expansions due to cyclic references. run/colltest4 is an exmaple. Here, we missed an eta expansion in the type of Iterator. The class definition is: trait Iterable[+A] extends IterableOnce[A] with FromIterable[Iterable] { We'd expect that the second parent would expand to FromIterable[[X0] -> Iterable[X0]] But we miss the expansion because at the time we complete Iterable we have not completed FromIterable yet. In fact this happens in both the old and the new hk scheme. But in the old scheme we did not notice the error whereas in the new scheme we get an error in PostTyper that the type Iterable does not conform to its bound `[X0] -> Iterable[X0]`. With this commit, we change the scheme, so that eta-expansion depends on the type parameters of a type itself, instead of the expected type. We should investigate whether we can do a similar change for Scala2 classloading. Check kinds of type parameters Also, do not allow a hk type if the bound is a * type.
* Fix typeParams for abstract types under completionMartin Odersky2016-07-111-10/+11
| | | | | Their type parameters are not the type parameters in the completer, but hk type parameters with the same variances.
* Add a second betaReduceMartin Odersky2016-07-111-6/+7
| | | | | | | | | | | | | The new one only reduces straight applications of type lambdas with definite arguments. It is called very early on appliedTo, and derivedRefinedType. The old one, now renamed to normalizeHkApply also handles wildcard arguments and can garbage collect general unneeded hk-refinements. It is called later, at various places. TODO: See what functionality of normalizeHkApply should go into betaReduce instead. Maybe we can even drop normalizeHkApply? However: need to be careful to maintain aliases for hk type inference.
* Fixes to BetaReduce and asMemberOf; add a second betaReduceMartin Odersky2016-07-111-50/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new one only reduces straight applications of type lambdas with definite arguments. It is called very early on appliedTo, and derivedRefinedType. The old one, now renamed to normalizeHkApply also handles wildcard arguments and can garbage collect general unneeded hk-refinements. It is called later, at various places. TODO: See what functionality of normalizeHkApply should go into betaReduce instead. Maybe we can even drop normalizeHkApply? However: need to be careful to maintain aliases for hk type inference. Handle LazyRefs in BetaReduce Needs to be careful to not skip LazyRefs when dealiasing. - Fix^2 of asMemberOf: This fix ensures that - under the old hk scheme test succeeds for compilestdlib and tasty-new-all - under the new scheme test succeeds for i94-nada (i.e. REP[T] = T). - Try to beta-reduce bounds before adding to a constraint. - More subtle handling of LazyRefs in BetaReduce - Another refinement to asMemberOf Need to assume lastSymbol in sync with lastDenotation. - Drop isSafe test from BetaReduce Instead, track the higherkinded argument names that a type variable could potentially instantiate to.
* Make etaExpandIfHk work for non-symbol type paramsMartin Odersky2016-07-111-3/+9
| | | | Fixes a crasher in t2994.scala
* Multiple fixesMartin Odersky2016-07-111-17/+67
| | | | | | | | | | | | | | | | | | | | | | | - Swap order of tests in lookupRefined - Change joins of BindingKinds. A type parameter joint with a normal refinement represents a type parameter that has been filled in. So the Binding attribute should be removed. - Fix printing of type lambdas under new hk scheme - refine isRef for hk type The new definition avoids that a higher-kinded type "isRef" of an underlying class. I.e. `[X] -> Any` is not longer a ref to `Any`. - Fix withBindingKind for type aliases Old definition converted aliases to type bounds. - Multiple fixes to BetaReduce - Fix logic for hk subtype tests - Make isHK more precise
* Turn on new hk schemeMartin Odersky2016-07-111-107/+234
| | | | | | | For the moment under newHK flag. - avoid crasher in derivedTypeParams (NamedTypes don't always have symbols) - Revise logic in type comparer for new HK scheme
* Abstract type parameters out from type symbolsMartin Odersky2016-07-111-13/+19
| | | | | | | | In the new hk scheme, a type parameter can be represented by a refinement without a corresponding symbol. Therefore, we need to disentangle the info inherent in a type parameter from the contents of a type symbol. We achieve this by creating a common super trait "MemerInfo" of Symbol and RefinedType.
* Introduce recursive typesMartin Odersky2016-07-111-8/+32
| | | | | | | | | | | | | | | | | Map self-references in refinements to recursive types. This commit does this for refinement types appearing in source. We still have to do it for unpickled refinements. Test apply-equiv got moved to pending because it simulates the old higher-kinded type encoding in source, which relies on the old representation in terms of self-referential refinement types. The plan is not to adapt this encoding to the new representation, but to replace it with a different encoding that makes critical use of the added power of recursive types. Use recursive types also when unpickling from Scala 2.x. Add mapInfo method to Denotations.
* New type lambda scheme for hk typesMartin Odersky2016-07-111-2/+37
|
* Allow general recursion in refined types.Martin Odersky2016-07-111-11/+11
| | | | | Treat parent like refinedInfo. Introduce isBinding convenience method in TypeBounds.
* Allow refinements of new typesMartin Odersky2016-07-111-1/+1
| | | | | | 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.
* Dealias applied type constructorsMartin Odersky2016-04-151-2/+10
| | | | | | Dealias TypeRefs that get applied to type arguments. Without that precaution we get Stackoverflows in lookupRefined/betaReduce for CollectionStrawMan5.scala.
* Merge pull request #1186 from dotty-staging/fix-#1185odersky2016-04-061-0/+61
|\ | | | | Improvements to cyclic checking, avoidance, named parameters
| * Simplify widenToParentsMartin Odersky2016-03-301-4/+5
| | | | | | | | No need to form the glb.
| * Add methods for expressing named type paramsMartin Odersky2016-03-301-0/+60
| | | | | | | | | | Add methods for expressing what the named type parameters of a class or type are. Also, add a method that widens a type so that is has a specified set of named type parameters.
* | Move Mode to coreMartin Odersky2016-04-011-1/+0
|/ | | | | Mode is used from a lot of low-level code, does not just reflect Typer info. So it makes more sense top to place it in the core package.
* Fix review comment in previous PRMartin Odersky2016-02-191-2/+1
| | | | Was not fixed by accident then, so we do it here now.
* Support named type parametersMartin Odersky2016-02-191-1/+1
| | | | | Changes needed to support simple named type parameters. Not yet implemented: named arguments.
* Remove unnecessary logic in toBoundsMartin Odersky2016-02-191-0/+3
|
* Compute type params in namer without completing the whole infoMartin Odersky2016-01-161-9/+16
| | | | | | | | | Type params should be computed before computing the whole info of a type. Without the patch we get a cyclic reference in the compileMixed test. Note that compileIndexedSeq does not pass with this commit (it passed before), this is fixed in the next commit.
* Merge pull request #1006 from dotty-staging/more-testsGuillaume Martres2015-12-261-7/+3
|\ | | | | More tests
| * Don't do eta expansion on bottom typesMartin Odersky2015-12-201-7/+3
| |