Skip to content
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

incremental crash: inlining from top-level object defined in file with other name #13994

Closed
bishabosha opened this issue Nov 23, 2021 · 4 comments · Fixed by #14050
Closed

incremental crash: inlining from top-level object defined in file with other name #13994

bishabosha opened this issue Nov 23, 2021 · 4 comments · Fixed by #14050

Comments

@bishabosha
Copy link
Member

bishabosha commented Nov 23, 2021

When incrementally compiling some project with -sourcepath compiler option, if I reference an inline method (foo defined in a/zz.scala, where foo is defined in a root object a.Foo) in a non-inline method (bar in a/Bar.scala, where bar is defined in a root object a.Bar), and then modify the rhs of foo and recompile, zinc will compile zz.scala in one run, and then crash when compiling Bar.scala in the second run.

It seems the issue is only triggered when an inline method is defined in an object with a different name to the file it is in.

Compiler version

3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY

Minimized code

  1. make sbt project (v1.5.5)
// build.sbt
scalaVersion := "3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY"

(Compile / scalacOptions) ++= Seq(
  "-sourcepath", (Compile / sourceDirectories).value.map(_.getAbsolutePath).distinct.mkString(java.io.File.pathSeparator),
)
  1. add these files to the sources:
// src/main/scala/a/zz.scala
package a

object Foo: // note that `Foo` is defined in `zz.scala`
  class Local
  inline def foo(using Local): Nothing =
    ???
// src/main/scala/a/Bar.scala
package a

object Bar:
  given Foo.Local()
  def Bar = Foo.foo
  1. run sbt compile successfully

  2. Edit rhs of foo in zz.scala

 package a

 object Foo:
   class Local
   inline def foo(using Local): Nothing =
     ???
+    ???
  1. run sbt compile, expect crash

Output (click arrow to expand)

[info] compiling 1 Scala source to /Users/jamie/workspace/test-inc-inlining/target/scala-3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY/classes ...
[info] compiling 1 Scala source to /Users/jamie/workspace/test-inc-inlining/target/scala-3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY/classes ...
[info] exception occurred while compiling /Users/jamie/workspace/test-inc-inlining/src/main/scala/a/Bar.scala
java.util.NoSuchElementException: None.get while compiling /Users/jamie/workspace/test-inc-inlining/src/main/scala/a/Bar.scala
[error] ## Exception when compiling 2 sources to /Users/jamie/workspace/test-inc-inlining/target/scala-3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY/classes
[error] java.util.NoSuchElementException: None.get
[error] scala.None$.get(Option.scala:627)
[error] scala.None$.get(Option.scala:626)
[error] dotty.tools.dotc.typer.PrepareInlineable$.makeInlineable(PrepareInlineable.scala:35)
[error] dotty.tools.dotc.typer.PrepareInlineable$.registerInlineInfo$$anonfun$1$$anonfun$1(PrepareInlineable.scala:267)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
[error] dotty.tools.dotc.typer.PrepareInlineable$.registerInlineInfo$$anonfun$1(PrepareInlineable.scala:267)
[error] dotty.tools.dotc.core.Annotations$.dotty$tools$dotc$core$Annotations$$anon$2$$_$$lessinit$greater$$anonfun$1(Annotations.scala:165)
[error] dotty.tools.dotc.core.Annotations$LazyBodyAnnotation.tree(Annotations.scala:153)
[error] dotty.tools.dotc.typer.Inliner$.bodyToInline(Inliner.scala:52)
[error] dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:156)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:86)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:103)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:111)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1466)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1477)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:94)
[error] dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:72)
[error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
[error] dotty.tools.dotc.transform.Inlining.run(Inlining.scala:44)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:308)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:309)
[error] dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:48)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:261)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:272)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:289)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:222)
[error] dotty.tools.dotc.Run.compile(Run.scala:206)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:175)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:173)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:167)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2357)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2314)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2310)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:748)
[error]            
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) java.util.NoSuchElementException: None.get
[error] Total time: 0 s, completed Nov 23, 2021 10:14:13 AM
@bishabosha bishabosha changed the title No InlineAccessorsKey in context when inlining from object in file with different name incremental crash: inlining from top-level object defined in file with other name Nov 23, 2021
@bishabosha
Copy link
Member Author

this seems to not be present on 3.1.0, but is in 3.1.2-RC1-bin-20211119-2ef89b2-NIGHTLY

@bishabosha
Copy link
Member Author

possible blocker for #12931

@bishabosha
Copy link
Member Author

appeared for the first time in 3.1.1-RC1-bin-20210922-b13f37a-NIGHTLY

@nicolasstucki
Copy link
Contributor

It started in 1c0bf3f

bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 6, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 6, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 6, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 6, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2021
odersky added a commit that referenced this issue Dec 14, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.2 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