Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

-Ycheck returns non-empty constraint assertion error from an inline method calling a macro #16331

Closed
jchyb opened this issue Nov 13, 2022 · 1 comment · Fixed by #16348
Closed

Comments

@jchyb
Copy link
Contributor

jchyb commented Nov 13, 2022

Compiler version

3.2.1 and previous, also tested on d3c1c4e

Minimized code

Compiled with -Ycheck:inlining (or -Ycheck:all) and -Xprint:Ycheck

//macro.scala
import scala.quoted._

object Macro {
  transparent inline def macroDef[A](): Int = ${ macroDefImpl() }
  def macroDefImpl()(using q: Quotes): Expr[Int] = '{0}
}
//main.scala
object Main {
  inline def inlineDef[A](): Any = Macro.macroDef()
  def main(args: Array[String]) = {
    inlineDef()
  }
}

Output

checking i15971/macro.scala after phase inlining
java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A while running Ycheck on i15971/macro.scala
exception occurred while compiling i15971/macro.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A while compiling i15971/main.scala, i15971/macro.scala
java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:130)
        at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:110)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:324)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:328)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:244)
        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:1321)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:260)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:268)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:277)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:277)
        at dotty.tools.dotc.Run.compileSources(Run.scala:195)
        at dotty.tools.dotc.Run.compile(Run.scala:179)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Expectation

Should not fail the checker phase. Heavily based on #15971 (the minimization), but unrelated the binding issue presented there. Tried to find the cause, unsuccessfully. For now all I found is that this seems to be related to the suspend mechanism, performed after expanding a macro. Hopefully I will be able to come back to this one day.

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 13, 2022
@KacperFKorban KacperFKorban added area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 13, 2022
@dwijnand
Copy link
Member

The stacktrace for the added constraint is:

java.lang.Exception: Stack trace
	at java.base/java.lang.Thread.dumpStack(Thread.java:1383)
	at dotty.tools.dotc.core.ConstraintHandling.addToConstraint(ConstraintHandling.scala:770)
	at dotty.tools.dotc.core.ConstraintHandling.addToConstraint$(ConstraintHandling.scala:29)
	at dotty.tools.dotc.core.TypeComparer.addToConstraint(TypeComparer.scala:30)
	at dotty.tools.dotc.core.TypeComparer$.addToConstraint(TypeComparer.scala:3009)
	at dotty.tools.dotc.typer.ProtoTypes$.constrained(ProtoTypes.scala:714)
	at dotty.tools.dotc.typer.ProtoTypes$.instantiateWithTypeVars(ProtoTypes.scala:728)
	at dotty.tools.dotc.typer.ProtoTypes$.normalize(ProtoTypes.scala:804)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.testCompat$1(ProtoTypes.scala:55)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.normalizedCompatible(ProtoTypes.scala:62)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.normalizedCompatible$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.normalizedCompatible(Typer.scala:121)
	at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.qualifies$1(ProtoTypes.scala:209)
	at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.liftedTree1$1(ProtoTypes.scala:213)
	at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:226)
	at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:2036)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:327)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1451)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:208)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:218)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
	at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:144)
	at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:2936)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:3770)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3849)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4071)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3406)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
	at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSelect(Inliner.scala:763)

I tried around the `testSubType call in adapt to either change the context it's using, or cleaning up the context on success. Neither worked. 🤷🏼

@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.0-RC1 Dec 12, 2022
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 1, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants