Skip to content

call of inline method of result of other inline method produce a tree with incorrect ownity, (crashed with -Ycheck:macros) #11251

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
rssh opened this issue Jan 29, 2021 · 5 comments · Fixed by #11335
Assignees
Milestone

Comments

@rssh
Copy link
Contributor

rssh commented Jan 29, 2021

Compiler version

Latest Dotty nightly build version: 3.0.0-RC1-bin-20210128-ce684de-NIGHTLY

Minimized code

class X.scala

package x

import scala.quoted._

class SL:

  inline def foo(inline step: Int => Int): SL =
     val f = step
     this

  def run1(): Unit = ???

  inline def run(): Unit =
    run1()


object X:

 inline def process[T](inline f:T) = ${
   processImpl[T]('f)
 }

 def processImpl[T:Type](t:Expr[T])(using Quotes):Expr[T] =
   import quotes.reflect._
   val checker = new TreeMap() {}
   checker.transformTerm(t.asTerm)(Symbol.spliceOwner)
   t

Main.scala:

package x

object Main {

 def main(args:Array[String]):Unit =
    val sl = new SL()
    X.process(
      sl.foo(x=>x+1).run()
    )

}

compile with -Ycheck:macros flag (flag is essential)

Output (click arrow to expand)

Latest Dotty nightly build version: 3.0.0-RC1-bin-20210128-ce684de-NIGHTLY
[info] loading settings for project root from build.sbt ...
[info] set current project to test (in build file:/Users/rssh/tests/dotty/crash-yycheck-macros-light/)
[info] compiling 2 Scala sources to /Users/rssh/tests/dotty/crash-yycheck-macros-light/target/scala-3.0.0-RC1/classes ..
[error] -- Error: /Users/rssh/tests/dotty/crash-yycheck-macros-light/src/main/scala/x/Main.scala:8:13 
[error] 8 |    X.process(
[error]    |    ^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.AssertionError: assertion failed: Tree had an unexpected owner for val f
[error]    |Expected: val SL_this (x.Main$._$_$SL_this)
[error]    |But was: val macro (x.Main$._$macro)
[error]    |
[error]    |
[error]    |The code of the definition of val f is
[error]    |val f: scala.Function1[scala.Int, scala.Int] = ((x: scala.Int) => x.+(1))
[error]    |
[error]    |which was found in the code
[error]    |({
[error]    |  val f: scala.Function1[scala.Int, scala.Int] = ((x: scala.Int) => x.+(1))
[error]    |  SL_this
[error]    |}: x.SL)
[error]    |
[error]    |which has the AST representation
[error]    |Inlined(Some(Apply(Select(Ident("sl"), "foo"), List(Block(List(DefDef("$anonfun", List(TermParamClause(List(ValDef("x", Inferred(), None)))), Inferred(), Some(Apply(Select(Ident("x"), "+"), List(Literal(IntConstant(1))))))), Closure(Ident("$anonfun"), None))))), Nil, Typed(Block(List(ValDef("f", Inferred(), Some(Inlined(None, Nil, Block(List(DefDef("$anonfun", List(TermParamClause(List(ValDef("x", Inferred(), None)))), Inferred(), Some(Apply(Select(Ident("x"), "+"), List(Literal(IntConstant(1))))))), Closure(Ident("$anonfun"), None)))))), Inlined(None, Nil, Ident("SL_this"))), TypeIdent("SL")))
[error]    |
[error]    |
[error]    |	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2823)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1436)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1438)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1471)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1564)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2826)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1465)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1442)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1564)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2826)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1563)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1491)
[error]    |	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1564)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2826)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$.yCheckOwners(QuotesImpl.scala:2827)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$yCheckedOwners(QuotesImpl.scala:2789)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.copy(QuotesImpl.scala:294)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.copy(QuotesImpl.scala:293)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement(Quotes.scala:4266)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformStatement(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree(Quotes.scala:4240)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformTree(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTrees$$anonfun$1(Quotes.scala:4370)
[error]    |	at scala.collection.immutable.List.mapConserve(List.scala:472)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTrees(Quotes.scala:4370)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTrees$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformTrees(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformSubTrees(Quotes.scala:4385)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformSubTrees$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformSubTrees(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4327)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformTerm(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4311)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformTerm(X.scala:25)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4327)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4229)
[error]    |	at x.X$$anon$1.transformTerm(X.scala:25)
[error]    |	at x.X$.processImpl(X.scala:26)
[error]    |
[error]    | This location contains code that was inlined from Main.scala:8
[error] 9 |      sl.foo(x=>x+1).run()
[error] 10 |    )
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
@rssh
Copy link
Contributor Author

rssh commented Jan 29, 2021

crash-yycheck-macros-light.tar.gz

  • full sbt project

@rssh
Copy link
Contributor Author

rssh commented Feb 6, 2021

but -Ycheck:all (as default option in TestBootsrapClass). gives us new surprises ...

Exception in thread "main" dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; module class SL$#3421 in module class i11251, defined in Period(1..63, run = 2), is referred to in run Period(17..17, run = 3) at dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:943) at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:728) at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:791) at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:865) at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:122) at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:116) at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109) ....

@rssh
Copy link
Contributor Author

rssh commented Feb 6, 2021

// track-down situation to call of. registeredCompanion(SymDenotations.scala:2207) when actually companion class is not exists (adding dummy ComanionClass fixes the situation).
Is the compiler expect that each class has a companion? (in such case error is not generating one),
or error is assuming that for each class should exists companion?

@rssh
Copy link
Contributor Author

rssh commented Feb 6, 2021

submitted #11331 as a separate unrelated issue, (I guess after fixing one, will be able to submit path with test-cases)

rssh added a commit to rssh/dotty that referenced this issue Feb 7, 2021
@rssh
Copy link
Contributor Author

rssh commented Feb 7, 2021

fix submitted in #11335

rssh added a commit to rssh/dotty that referenced this issue Feb 15, 2021
nicolasstucki added a commit that referenced this issue Feb 24, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants