Skip to content

Commit

Permalink
Prevent name mangling for exported functions in GenC (fix #921)
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed Feb 27, 2021
1 parent ea380fa commit 719e203
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/main/scala/stainless/genc/phases/Scala2IRPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ private class S2IRImpl(val ctx: inox.Context, val ctxDB: FunCtxDB, val deps: Dep
// rec(tfd.fd.id) + (if (tfd.tps.nonEmpty) buildIdPostfix(tfd.tps) else buildIdFromTypeMapping(tm))

// Include the "nesting path" in case of generic functions to avoid ambiguity
private def buildId(fa: FunAbstraction, tps: Seq[Type])(implicit tm: TypeMapping): CIR.Id =
rec(fa.id) + (if (tps.nonEmpty) buildIdPostfix(tps) else buildIdFromTypeMapping(tm))
private def buildId(fa: FunAbstraction, tps: Seq[Type])(implicit tm: TypeMapping): CIR.Id = {
val exported = fa.isInstanceOf[Outer] && fa.asInstanceOf[Outer].fd.isExported
rec(fa.id, withUnique = !exported) + (if (tps.nonEmpty) buildIdPostfix(tps) else buildIdFromTypeMapping(tm))
}

private def buildId(ct: ClassType)(implicit tm: TypeMapping): CIR.Id =
rec(ct.tcd.id) + buildIdPostfix(ct.tps)
Expand Down Expand Up @@ -420,9 +422,9 @@ private class S2IRImpl(val ctx: inox.Context, val ctxDB: FunCtxDB, val deps: Dep
/****************************************************************************************************
* Recursive conversion *
****************************************************************************************************/
private def rec(id: Identifier): CIR.Id = {
if (id.name == "main") "main"
else id.uniqueNameDelimited("_")
private def rec(id: Identifier, withUnique: Boolean = true): CIR.Id = {
if (withUnique) id.uniqueNameDelimited("_")
else id.name
}

private def rec(vd: ValDef): CIR.Id = {
Expand Down

0 comments on commit 719e203

Please sign in to comment.