Skip to content

Commit

Permalink
Fix some pickling errors •ᴗ•
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Oct 28, 2024
1 parent ee0c24e commit 7142e3d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
29 changes: 18 additions & 11 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,7 @@ class Namer { typer: Typer =>
sym.owner.typeParams.foreach(_.ensureCompleted())
completeTrailingParamss(constr, sym, indexingCtor = true)
if Feature.enabled(modularity) then
// println(i"[indexConstructor] Checking if params of $constr need tracked")
constr.termParamss.foreach(_.foreach(setTracked))

/** The signature of a module valdef.
Expand Down Expand Up @@ -1931,22 +1932,26 @@ class Namer { typer: Typer =>
def wrapRefinedMethType(restpe: Type): Type =
wrapMethType(addParamRefinements(restpe, paramSymss))

def addTrackedIfNeeded(ddef: DefDef, owningSym: Symbol): Boolean =
var wasSet = false
for params <- ddef.termParamss; param <- params do
val psym = symbolOfTree(param)
if needsTracked(psym, param, owningSym) then
psym.setFlag(Tracked)
wasSet = true
wasSet

if Feature.enabled(modularity) then addTrackedIfNeeded(ddef, sym.maybeOwner)

if isConstructor then
// set result type tree to unit, but take the current class as result type of the symbol
typedAheadType(ddef.tpt, defn.UnitType)
val mt = wrapMethType(effectiveResultType(sym, paramSymss))
if sym.isPrimaryConstructor then checkCaseClassParamDependencies(mt, sym.owner)
mt
else if Feature.enabled(modularity) then
// set every context bound evidence parameter of a given companion method
// to be tracked, provided it has a type that has an abstract type member.
// Add refinements for all tracked parameters to the result type.
for params <- ddef.termParamss; param <- params do
val psym = symbolOfTree(param)
if needsTracked(psym, param, sym) then psym.setFlag(Tracked)
valOrDefDefSig(ddef, sym, paramSymss, wrapRefinedMethType)
else
valOrDefDefSig(ddef, sym, paramSymss, wrapMethType)
val paramFn = if Feature.enabled(Feature.modularity) && sym.isAllOf(Given | Method) then wrapRefinedMethType else wrapMethType
valOrDefDefSig(ddef, sym, paramSymss, paramFn)
end defDefSig

/** Complete the trailing parameters of a DefDef,
Expand Down Expand Up @@ -1998,6 +2003,7 @@ class Namer { typer: Typer =>
/** Try to infer if the parameter needs a `tracked` modifier
*/
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
// println(i"Checking if $psym needs tracked")
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
lazy val isRefInSignatures =
psym.maybeOwner.isPrimaryConstructor
Expand Down Expand Up @@ -2071,8 +2077,9 @@ class Namer { typer: Typer =>
def setTracked(param: ValDef)(using Context): Unit =
val sym = symbolOfTree(param)
sym.maybeOwner.maybeOwner.infoOrCompleter match
case info: ClassInfo if needsTracked(sym, param, sym.maybeOwner.maybeOwner) =>
typr.println(i"set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}")
case info: ClassInfo
if !sym.is(Tracked) && isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner) =>
typr.println(i"set tracked $param, $sym: ${sym.info}")
for acc <- info.decls.lookupAll(sym.name) if acc.is(ParamAccessor) do
acc.resetFlag(PrivateLocal)
acc.setFlag(Tracked)
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ parsercombinators-new-syntax.scala
hylolib-deferred-given
hylolib-cb
hylolib
infer-tracked-parsercombinators-givens.scala

# typecheckErrors method unpickling
i21415.scala
8 changes: 8 additions & 0 deletions tests/pos/infer-tracked-parent-refinements.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.language.experimental.modularity
import scala.language.future

trait WithValue { type Value = Int }

case class Year(value: Int) extends WithValue {
val x: Value = 2
}
3 changes: 1 addition & 2 deletions tests/pos/infer-tracked-parsercombinators-givens.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import scala.language.experimental.modularity
import scala.language.future

import collection.mutable

/// A parser combinator.
Expand All @@ -19,7 +18,7 @@ end Combinator
final case class Apply[C, E](action: C => Option[E])
final case class Combine[A, B](first: A, second: B)

given apply[C, E]: Combinator[Apply[C, E]] with {
given apply: [C, E] => Combinator[Apply[C, E]] {
type Context = C
type Element = E
extension(self: Apply[C, E]) {
Expand Down

0 comments on commit 7142e3d

Please sign in to comment.