Skip to content

Assertion failed: Attempt to commit TS[...] into already committed TS[...] #14907

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
FlorianCassayre opened this issue Apr 11, 2022 · 5 comments

Comments

@FlorianCassayre
Copy link
Contributor

FlorianCassayre commented Apr 11, 2022

Compiler version

3.1.3-RC1-bin-20220410-220b753-NIGHTLY down to 3.0.1 using -Yforce-sbt-phases

Minimized code

object Module {
  class Fun[N <: Int]()
  type Fill[N <: Int] = N match {
    case 0 => EmptyTuple
    case 1 => Any *: Fill[0]
  }
  extension[N <: Int] (f: Fun[N])
    def apply: Fill[N] => Any = ???

  Fun[1]()(???)
}

Output (click arrow to expand)

scalac: Error: assertion failed: Attempt to commit TS[3046177X, 3045800X, 3030389, 3030388, 3030387] into already committed TS[3045800X, 3030389, 3030388, 3030387]
java.lang.AssertionError: assertion failed: Attempt to commit TS[3046177X, 3045800X, 3030389, 3030388, 3030387] into already committed TS[3045800X, 3030389, 3030388, 3030387]
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.TyperState.commit(TyperState.scala:154)
	at dotty.tools.dotc.typer.Inferencing$.isFullyDefined(Inferencing.scala:40)
	at dotty.tools.dotc.core.TypeOps$.simplify(TypeOps.scala:145)
	at dotty.tools.dotc.core.TypeOps$SimplifyMap.apply(TypeOps.scala:189)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5609)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2887)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5608)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2887)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5608)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2887)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:321)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1309)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:189)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:199)
	at dotty.tools.dotc.core.TypeComparer.isSubArg$1(TypeComparer.scala:1519)
	at dotty.tools.dotc.core.TypeComparer.recurArgs$1(TypeComparer.scala:1523)
	at dotty.tools.dotc.core.TypeComparer.isSubArgs(TypeComparer.scala:1526)
	at dotty.tools.dotc.core.TypeComparer.loop$1(TypeComparer.scala:1096)
	at dotty.tools.dotc.core.TypeComparer.isMatchingApply$1(TypeComparer.scala:1111)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:1181)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:559)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:492)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:378)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1309)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:189)
	at dotty.tools.dotc.core.TypeComparer.tryBaseType$1(TypeComparer.scala:749)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:1190)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:559)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:492)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:378)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1309)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:189)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:199)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:126)
	at dotty.tools.dotc.core.TypeComparer.necessarySubType(TypeComparer.scala:137)
	at dotty.tools.dotc.core.TypeComparer$.necessarySubType(TypeComparer.scala:2712)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible(ProtoTypes.scala:47)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.necessarilyCompatible(Typer.scala:119)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:97)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:119)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:117)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:119)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:438)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:735)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1052)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:119)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
	at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:978)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3081)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:989)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1027)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:119)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2809)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedTuple(Typer.scala:2720)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2846)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:462)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:386)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:463)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:544)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:609)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:447)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:735)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1052)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:119)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
	at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:978)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3081)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:989)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1027)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:119)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2809)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1075)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2817)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.caseRest$1(Typer.scala:1684)
	at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:1700)
	at dotty.tools.dotc.typer.Typer.typedCases$$anonfun$1(Typer.scala:1630)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:92)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:108)
	at dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:1632)
	at dotty.tools.dotc.typer.Typer.$anonfun$26(Typer.scala:1622)
	at dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:2187)
	at dotty.tools.dotc.typer.Applications.harmonic$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:119)
	at dotty.tools.dotc.typer.Typer.typedMatchFinish(Typer.scala:1622)
	at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1578)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.$anonfun$47(Typer.scala:2256)
	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2256)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2786)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2454)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2797)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2581)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2842)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:287)
	at dotty.tools.dotc.Run.compileSources(Run.scala:220)
	at dotty.tools.dotc.Run.compile(Run.scala:204)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
	at org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:57)
	at org.jetbrains.jps.incremental.scala.local.LocalServer.doCompile(LocalServer.scala:52)
	at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:30)
	at org.jetbrains.jps.incremental.scala.remote.Main$.compileLogic(Main.scala:207)
	at org.jetbrains.jps.incremental.scala.remote.Main$.$anonfun$handleCommand$1(Main.scala:190)
	at org.jetbrains.jps.incremental.scala.remote.Main$.decorated$1(Main.scala:180)
	at org.jetbrains.jps.incremental.scala.remote.Main$.handleCommand(Main.scala:187)
	at org.jetbrains.jps.incremental.scala.remote.Main$.serverLogic(Main.scala:163)
	at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:103)
	at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
	at jdk.internal.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

The compiler outputs additional stuff to the standard output.

This code compiles on 3.0.0, but not on 3.0.1 and later.

@FlorianCassayre FlorianCassayre added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 11, 2022
@odersky odersky removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Apr 11, 2022
@odersky odersky assigned odersky and smarter and unassigned odersky Apr 11, 2022
@smarter
Copy link
Member

smarter commented Apr 11, 2022

Can't reproduce on either 3.1.1 or 3.1.3-RC1-bin-20220410-220b753-NIGHTLY, did you minimize too much?

@FlorianCassayre
Copy link
Contributor Author

I can reproduce on Scastie and GitHub Actions. See the Actions output: FlorianCassayre/dotty-i14907

@smarter
Copy link
Member

smarter commented Apr 11, 2022

Ah thanks, to reproduce when using the compiler directly requires adding the flag -Yforce-sbt-phases.

@FlorianCassayre
Copy link
Contributor Author

Ah thanks, to reproduce when using the compiler directly requires adding the flag -Yforce-sbt-phases.

Good to know, thanks for the precisions, I'll keep that in mind for the next time.

FlorianCassayre added a commit to FlorianCassayre/master-project that referenced this issue Apr 13, 2022
smarter added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2022
If the added test case is run with `-Yforce-sbt-phases`, a LazyRef (created in
the LazyRef case of TypeMap#mapOver) captures a Context. Later, that LazyRef is
forced, but at that point the TyperState of the captured Context is already
committed, so we're not allowed to commit anything in it anymore. But forcing
the LazyRef ends up calling `isFullyDefined` which unconditionally creates a
temporary TyperState and commit it, thus triggering the assertion.

We fix this by relaxing the assertion to allow committing into a TyperState if
there's nothing to commit. This should handle all LazyRefs since they never wrap
uninstantiated type variables in practice.

Fixes scala#14907.
@odersky odersky closed this as completed in 87c97e7 May 2, 2022
@FlorianCassayre
Copy link
Contributor Author

With the latest nightly, I'm now getting a different assertion error (from a piece of code containing a similar snippet). I'll try to produce a minimization.

bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
If the added test case is run with `-Yforce-sbt-phases`, a LazyRef (created in
the LazyRef case of TypeMap#mapOver) captures a Context. Later, that LazyRef is
forced, but at that point the TyperState of the captured Context is already
committed, so we're not allowed to commit anything in it anymore. But forcing
the LazyRef ends up calling `isFullyDefined` which unconditionally creates a
temporary TyperState and commit it, thus triggering the assertion.

We fix this by relaxing the assertion to allow committing into a TyperState if
there's nothing to commit. This should handle all LazyRefs since they never wrap
uninstantiated type variables in practice.

Fixes scala#14907.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants