orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
41 stars 3 forks source link

NamelessToNamed reconstructing contexts out of order #219

Open jthywiss opened 6 years ago

jthywiss commented 6 years ago

Tranking, an Orc user, reported the following bug in orc.ast.oil.nameless.NamelessToNamed:

Date: Thu, 24 May 2018 14:55:14 +0800 From: Tranking

. . . . when I debug orc source code, I found that the nameless code which was compiled by NamedToNameless had an error when it rollback to named code which was compiled by NamelessToNamed, the error was caused by the method below:

def namelessToNamed(x: BoundVar, defn: Def, context: List[BoundVar], typecontext: List[BoundTypevar]): named.Def = {
  defn -> {
    case Def(typearity, arity, body, argtypes, returntype) => {
      val formals = (for (_ <- 0 until arity) yield new BoundVar()).toList
      val typeformals = (for (_ <- 0 until typearity) yield new BoundTypevar()).toList
      val newContext = formals ::: context
      val newTypeContext = typeformals ::: typecontext
      val newbody = namelessToNamed(body, newContext, newTypeContext)
      val newArgTypes = argtypes map { _ map { namelessToNamed(_, newTypeContext) } }
      val newReturnType = returntype map { namelessToNamed(_, newTypeContext) }
      named.Def(x, formals, newbody, typeformals, newArgTypes, newReturnType)
    }
  }
}

and the method is belong to the class of orc/ast/oil/nameless/NamelessToNamed. The error line is [val newContext... ]. The correct code should be:

  val newContext = formals.reverse:::context
jthywiss commented 6 years ago

Tranking, thank you for the bug report!

It looks like the file was changed by the ODO merge since the time of Tranking's version, but the code is still there, currently at line 147. Need to check if typeformals are also affected.