Skip to content

Commit

Permalink
Merge pull request #4602 from dotty-staging/drop-withFilter-filter-re…
Browse files Browse the repository at this point in the history
…write

Stop rewriting withFilter to filter
  • Loading branch information
Blaisorblade authored May 31, 2018
2 parents be6ae0e + 7b9853a commit 76363fb
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 36 deletions.
16 changes: 2 additions & 14 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
import language.higherKinds
import typer.FrontEnd
import collection.mutable.ListBuffer
import util.Property
import reporting.diagnostic.messages._
import reporting.trace

object desugar {
import untpd._
import DesugarEnums._

/** Tags a .withFilter call generated by desugaring a for expression.
* Such calls can alternatively be rewritten to use filter.
*/
val MaybeFilter = new Property.Key[Unit]

/** Info of a variable in a pattern: The named tree and its type */
private type VarInfo = (NameTree, Tree)

Expand Down Expand Up @@ -992,12 +986,6 @@ object desugar {
(Bind(name, pat), Ident(name))
}

/** Add MaybeFilter attachment */
def orFilter(tree: Tree): tree.type = {
tree.putAttachment(MaybeFilter, ())
tree
}

/** Make a pattern filter:
* rhs.withFilter { case pat => true case _ => false }
*
Expand Down Expand Up @@ -1028,7 +1016,7 @@ object desugar {
val cases = List(
CaseDef(pat, EmptyTree, Literal(Constant(true))),
CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false))))
Apply(orFilter(Select(rhs, nme.withFilter)), makeCaseLambda(cases))
Apply(Select(rhs, nme.withFilter), makeCaseLambda(cases))
}

/** Is pattern `pat` irrefutable when matched against `rhs`?
Expand Down Expand Up @@ -1085,7 +1073,7 @@ object desugar {
val vfrom1 = new IrrefutableGenFrom(makeTuple(allpats), rhs1)
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)
case (gen: GenFrom) :: test :: rest =>
val filtered = Apply(orFilter(rhsSelect(gen, nme.withFilter)), makeLambda(gen.pat, test))
val filtered = Apply(rhsSelect(gen, nme.withFilter), makeLambda(gen.pat, test))
val genFrom =
if (isIrrefutableGenFrom(gen)) new IrrefutableGenFrom(gen.pat, filtered)
else GenFrom(gen.pat, filtered)
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,6 @@ class Typer extends Namer
// SI-3120 Java uses the same syntax, A.B, to express selection from the
// value A and from the type A. We have to try both.
selectWithFallback(tryJavaSelectOnType(_)) // !!! possibly exponential bcs of qualifier retyping
else if (tree.name == nme.withFilter && tree.getAttachment(desugar.MaybeFilter).isDefined)
selectWithFallback {
implicit ctx =>
typedSelect(untpd.cpy.Select(tree)(tree.qualifier, nme.filter), pt) // !!! possibly exponential bcs of qualifier retyping
}
else
typeSelectOnTerm(ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/untried/neg/t6455.scala → tests/neg/t6455.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ object O { def filter(p: Int => Boolean): O.type = this }

class Test {
// should not compile because we no longer rewrite withFilter => filter under -Xfuture
O.withFilter(f => true)
O.withFilter(f => true) // error // error
}
12 changes: 0 additions & 12 deletions tests/pos/for-filter.scala

This file was deleted.

4 changes: 0 additions & 4 deletions tests/untried/neg/t6455.check

This file was deleted.

0 comments on commit 76363fb

Please sign in to comment.