Skip to content

SI-7038 Deskolemize harder #3

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ trait ExistentialsAndSkolems {
def apply(tp: Type): Type = tp match {
case TypeRef(pre, sym, args) if sym.isTypeSkolem && (tparams contains sym.deSkolemize) =>
mapOver(typeRef(NoPrefix, sym.deSkolemize, args))
case TypeRef(pre, sym, args) if sym.isAliasType =>
mapOver(tp.normalize)

Choose a reason for hiding this comment

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

i'd dealias instead of normalize (and only if !(tp.dealias =:= tp) -- i.e., when arguments are supplied so that we don't have to eta-expand to a polytype)

otherwise, looks good

EDIT: I think tp.dealias match { ... } should work, no need for the case for alias types

Copy link
Owner Author

Choose a reason for hiding this comment

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

Lukas's latest PR actually removed this custom TypeMap in favour of a straight restpe.substSyms(skolems, tparams). Which got me to thinking about how this version might be expressed in the same way; which other custom type maps could be expressed in the same way, etc.

What I'm thinking of is dealiasLocals(method, restpe).substSyms(skolems, tparams), where dealiasLocals would dealias any types aliases that are local to the method. Does that sound like a reasonable approach? How would I build such a thing?

Choose a reason for hiding this comment

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

the problem is sym.deSkolemize doesn't have an inverse, so you can't easily determine the skolems list
for sym in skolems. TR(pre, sym, as) -> TR(NoPrefix, sym.deSkolemize, args)
skolems = {sym | sym.deSkolemize in tparams}

the only way I can see to express this as a substitution is to

  • generalize the from/to arguments of the substitution to a function
  • or get a list of all symbols in the type to transform

Copy link
Owner Author

Choose a reason for hiding this comment

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

Here's what @lrytz is up to.

      /* tparams already have symbols (created in enterDefDef/completerOf), namely the skolemized ones (created
       * by the PolyTypeCompleter constructor, and assigned to tparams). reenterTypeParams enters the type skolems
       * into scope and returns the non-skolems.
        */

      val tparamSyms = typer.reenterTypeParams(tparams)
       val tparamSkolems = tparams.map(_.symbol)

Choose a reason for hiding this comment

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

I think that still goes from skolem to non-skolem
i don't know how to go from non-skolem to (original) skolem

case _ =>
mapOver(tp)
}
Expand Down
25 changes: 25 additions & 0 deletions test/files/run/t7308.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Type in expressions to have them evaluated.
Type :help for more information.

scala> def foo[S] = { type X = List[S]; List():X }
foo: [S]=> List[S]

scala> val li = foo[Int]
li: List[Int] = List()

scala> li: List[Int]
res0: List[Int] = List()

scala> type TL = List[Int]
defined type alias TL

scala> def foo = null: TL
foo: TL

scala> def foo = {type TL=List[Int]; null: TL}
foo: TL

scala> foo: List[Int]
res1: List[Int] = null

scala>
14 changes: 14 additions & 0 deletions test/files/run/t7308.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.tools.partest.ReplTest

object Test extends ReplTest {

override def code = """
def foo[S] = { type X = List[S]; List():X }
val li = foo[Int]
li: List[Int]
type TL = List[Int]
def foo = null: TL
def foo = {type TL=List[Int]; null: TL}
foo: List[Int]
""".trim
}