Skip to content

Fix #12267: Constraints should not cross phases #12300

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 4 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
15 changes: 15 additions & 0 deletions bench/profiles/stdlib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
charts:

- name: "scala stdlib-2.13"
url: https://github.com/dotty-staging/scala/commits/stdLib213-dotty-community-build
lines:
- key: stdlib213
label: bootstrapped

scripts:

stdlib213:
- source $PROG_HOME/dotty/bench/scripts/stdlib213

config:
pr_base_url: "https://github.com/lampepfl/dotty/pull/"
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
Stats.trackTime(s"$phase ms ") {
val start = System.currentTimeMillis
val profileBefore = profiler.beforePhase(phase)
units = phase.runOn(units)

// invariant: constraint should not cross phase boundary
ctx.typerState.ensureSegregated { units = phase.runOn(units) }

profiler.afterPhase(phase, profileBefore)
if (ctx.settings.Xprint.value.containsPhase(phase))
for (unit <- units)
Expand Down
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,18 @@ class TyperState() {
s"TS[${ids(this).mkString(", ")}]"
}

/** Execute the operation with an empty constraint and make sure no leak
* of constraints.
*
* Side effect: the method will reset the constraint associated with the context.
*/
def ensureSegregated[T](op: => T)(using Context): T =
this.constraint = OrderingConstraint.empty
val res = op
// force instantiate tvars
// see tests/pos/t2619b.scala
ctx.typerState.gc()
res

def stateChainStr: String = s"$this${if (previous == null) "" else previous.stateChainStr}"
}
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,14 @@ object Types {
case tycon: TypeRef if tycon.symbol.isOpaqueAlias =>
tycon.translucentSuperType.applyIfParameterized(args)
case _ =>
tryNormalize.orElse(superType)
val x = tryNormalize
if x.exists then
record("try norm OK")
record(i"try norm OK $x")
x
else
record("try norm KO")
superType
}

inline def map(inline op: Type => Type)(using Context) =
Expand All @@ -4038,6 +4045,9 @@ object Types {
case tycon: TypeRef =>
def tryMatchAlias = tycon.info match {
case MatchAlias(alias) =>
record(i"try match alias")
record(i"try match alias $this in ${ctx.owner.ownersIterator.toList}%, %")
//new Error().printStackTrace()
trace(i"normalize $this", typr, show = true) {
MatchTypeTrace.recurseWith(this) {
alias.applyIfParameterized(args).tryNormalize
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/t2619b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
abstract class AbstractModule

object ModuleBE extends AbstractModule
object ModuleBF extends AbstractModule

object ModuleBM extends AbstractModule {
def ms: List[AbstractModule] = List(ModuleBE) ::: List(ModuleBF)
}