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

Compiler crash on inlined function and -optimize option #6157

Closed
scabug opened this issue Jul 30, 2012 · 6 comments
Closed

Compiler crash on inlined function and -optimize option #6157

scabug opened this issue Jul 30, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented Jul 30, 2012

The optimizer crashes when compiling method calling other methods:

Try to compile the attached project (2 classes) using sbt and its compile command.

The problem is new and does no occurs in scala 2.9.2

Look at the build.sbt for detailed compilation options.

{noformat}
[error]
[error] while compiling: /home/ecastro/Bureau/inline-optim-bug/src/main/scala/bug/ErrorHandler.scala
[error] during phase: inliner
[error] library version: version 2.10.0-M6
[error] compiler version: version 2.10.0-M6
[error] reconstructed args: -Ydead-code -optimise -classpath /home/ecastro/Bureau/inline-optim-bug/target/scala-2.10.0-M6/classes -Yinline -bootclasspath /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/netx.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/plugin.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/classes:/home/ecastro/.sbt/boot/scala-2.10.0-M6/lib/scala-library.jar -Yclosure-elim -d /home/ecastro/Bureau/inline-optim-bug/target/scala-2.10.0-M6/classes -Yinline-handlers
[error]
[error] last tree to typer: TypeTree(trait Seq)
[error] symbol: trait Seq in package collection (flags: abstract )
[error] symbol definition: abstract trait Seq extends PartialFunction with Iterable with GenSeq with GenericTraversableTemplate with SeqLike
[error] tpe: Seq
[error] symbol owners: trait Seq -> package collection
[error] context owners: object ErrorHandler -> package bug
[error]
[error] == Enclosing template or block ==
[error]
[error] Template( // val : in object ErrorHandler, tree.tpe=...
[error] "java.lang.Object" // parents
[error] ValDef(
[error] private
[error] "_"
[error]
[error]
[error] )
{noformat}etc.

@scabug
Copy link
Author

scabug commented Jul 30, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6157?orig=1
Reporter: Emmanuel Castro (emmanuel.castro)
Assignee: @magarciaEPFL
Affected Versions: 2.10.0-M6
Other Milestones: 2.10.0
Attachments:

@scabug
Copy link
Author

scabug commented Aug 6, 2012

@magarciaEPFL said (edited on Aug 6, 2012 2:44:56 PM UTC):
Minimized:

object Test {
  def main(args: Array[String]) {
    Console.println(
      ErrorHandler.defaultIfIOException("String")("String")
    )
  }
}

import java.io.IOException

object ErrorHandler {

  @inline
  def defaultIfIOException[T](default: => T)(closure: => T): T = {
    try {
      closure
    } catch {
      case e: IOException =>
        default
    }
  }
}

@scabug
Copy link
Author

scabug commented Aug 6, 2012

@magarciaEPFL said:
Background info:

Before inlining defaultIfIOException:

  def main(args: Array[String] (ARRAY[REF(class String)])): Unit {
  locals: value args
  startBlock: 1
  blocks: [1]
  
  1: 
    5	LOAD_MODULE object Console
    6	LOAD_MODULE object ErrorHandler
    6	NEW REF(anonymous class Test$$anonfun$main$1)
    6	DUP(REF(anonymous class Test$$anonfun$main$1))
    6	CALL_METHOD Test$$anonfun$main$1.<init> (static-instance)
    6	NEW REF(anonymous class Test$$anonfun$main$2)
    6	DUP(REF(anonymous class Test$$anonfun$main$2))
    6	CALL_METHOD Test$$anonfun$main$2.<init> (static-instance)
    6	CALL_METHOD ErrorHandler.defaultIfIOException (dynamic) // <---- please notice 4 slots on the stack 
    5	CALL_METHOD scala.Console.println (dynamic)
    5	RETURN(UNIT)
    
  }
  Exception handlers: 

After inlining defaultIfIOException:

  def main(args: Array[String] (ARRAY[REF(class String)])): Unit {
  locals: value args, variable default1, variable closure1, variable e1, variable $inlThis1, variable $retVal1
  startBlock: 1
  blocks: [1,4,5,6]
  
  1: 
    5	LOAD_MODULE object Console
    6	LOAD_MODULE object ErrorHandler
    6	NEW REF(anonymous class Test$$anonfun$main$1)
    6	DUP(REF(anonymous class Test$$anonfun$main$1))
    6	CALL_METHOD Test$$anonfun$main$1.<init> (static-instance)
    6	NEW REF(anonymous class Test$$anonfun$main$2)
    6	DUP(REF(anonymous class Test$$anonfun$main$2))
    6	CALL_METHOD Test$$anonfun$main$2.<init> (static-instance)
    6	STORE_LOCAL(variable closure1)
    6	STORE_LOCAL(variable default1)
    6	STORE_LOCAL(variable $inlThis1)
    6	JUMP 6
    
  6: 
    6	LOAD_LOCAL(variable closure1)
    6	CALL_METHOD scala.Function0.apply (dynamic)
    6	JUMP 4
    
  5: 
    6	LOAD_EXCEPTION(class IOException)
    6	STORE_LOCAL(variable e1)
    6	LOAD_LOCAL(variable default1)
    6	CALL_METHOD scala.Function0.apply (dynamic)
    6	JUMP 4
    
  4: 
    5	CALL_METHOD scala.Console.println (dynamic)
    5	RETURN(UNIT)
    
  }
  Exception handlers: 
    catch (IOException) in ArrayBuffer(6) starting at: 5
      consisting of blocks: List()
      with finalizer: null

@scabug
Copy link
Author

scabug commented Aug 6, 2012

@magarciaEPFL said:
After inlining defaultIfIOException the TFA is caught in a trap because:

  • on exit from block 1 there's just the Console object on the stack,
  • block 5 (the start of an EH, reached by exceptional control-flow from 6) has stack height == 1 on exit (the stack contains just the String pushed in that block). There's a normal control-flow edge from 5 to 4.
  • the other predecessor of block 4 (block 6) has an out-flow where the stack contains (a) the Console object it had on entry plus (b) a string

As a result we have inconsistent stack height on entry to 6.

@scabug
Copy link
Author

scabug commented Aug 6, 2012

@magarciaEPFL said:
magarciaEPFL/scala@1703736
builds upon the fix for #6188, scala/scala#1059

@scabug
Copy link
Author

scabug commented Aug 7, 2012

@magarciaEPFL said:
Fixed in scala/scala@1703736

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

1 participant