Skip to content

Commit

Permalink
fixed incorrect temporary vla generartion for direct-context-arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Jul 7, 2024
1 parent 328dc29 commit ac8a949
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,22 +373,25 @@ object ApplyTransform {
}

def adoptCallMode(origin: Tree, plainTree: Tree, funSym: Symbol, owner: Symbol, argss: List[ApplyArgList], callMode: FunCallMode, nesting: Int)(using Context, CpsTopLevelContext): CpsTree = {
Log.trace(s"adoptCallMode: plainTree=${plainTree.show}, callMode=${callMode} funSym=${funSym}", nesting)
Log.trace(s"adoptCallMode: plainTree=${plainTree.show}, callMode=${callMode} funSym=${funSym}, haveDirectContext=${argss.exists(_.containsDirectContext)}", nesting)
if (argss.exists(_.containsDirectContext))
//if (funSym.hasAnnotation(Symbols.requiredClass("cps.plugin.annotation.CpsNotChange"))) {
// throw CpsTransformException(s"DirectContext function can't be annotated with @CpsNotChange", origin.srcPos)
//}
val noChangeAnnotation = funSym.hasAnnotation(Symbols.requiredClass("cps.plugin.annotation.CpsNotChange"))
val directContextArg = argss.find(_.containsDirectContext).flatMap(_.findDirectContext).get
Log.trace(s"adoptCallMode: directContextArg=${directContextArg.show}", nesting)
val adoptedTree = directContextArg match
case dc@CpsDirectHelper.ByInclusionCall(tf,tg,fctx,fgincl) =>
Log.trace("!!!adoptCallMode: ByInclusionCall", nesting)
if (funSym.hasAnnotation(Symbols.requiredClass("cps.plugin.annotation.CpsNotChange"))) {
println("byInclusdionCall with CpsNotChange")
println(s" tf.tpe=${tf.tpe.show}")
throw CpsTransformException(s"DirectContext function can't be annotated with @CpsNotChange", origin.srcPos)
}
val callArgs = CpsDirectHelper.ByInclusionCallArgs(tf,tg,fctx,fgincl)
if (tf.tpe =:= tg.tpe) then
Log.trace(s"!!!adoptCallMode: ByInclusionCall, tf.tpe =:= tg.tpe = ${tf.tpe.show}", nesting)
val nCpsDirectArg = CpsDirectHelper.genCpsDirectDefaultConstructor(TypeTree(tf.tpe),fctx,dc.span)
val tree = CpsDirectHelper.substituteCpsDirectArgInCall(plainTree, callArgs, nCpsDirectArg).getOrElse(
throw CpsTransformException("Internal error: can't find direct context argument in call", origin.srcPos)
Expand Down Expand Up @@ -756,6 +759,7 @@ object ApplyTransform {
case ShiftedFun(origin, obj, method, targs, additionalArgs, canBeOverloaded, callShouldBeInlined, shape) =>
obj.tpe.member(method).symbol
val lastCpsTree = adoptCallMode(fullOrigin, pureReply, funSymbol, owner, argss, callMode, nesting)
// to preserve order of evaluation, evaluate all arguments before call.
val nApplyCpsTree = genPrefixes(argss, lastCpsTree)
val retval = nApplyCpsTree
Log.trace(s"genApplication result: ${retval.show}", nesting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ object ApplyTermArgList {
val (aExpr, named) = a match
case NamedArg(name, expr) => (expr, Some(name.toTermName))
case expr => (expr, None)
val depResult = DependencyCheck.run(aExpr,s.symbols)
val isDirectContext = mt.isDirectContext(s.index, a.srcPos)
val depResult = if (isDirectContext) {
// direct context is always syntetic and substituted by real context in the code
// (if we will generate temporary val for it, we broke this substitution)
// (mb add contextual argument for byIdentityCall to set).
DependencyCheck.Result(false, Set.empty)
} else {
DependencyCheck.run(aExpr,s.symbols)
}
val nApplyArg = ApplyArg( aExpr,
mt.paramName(s.index, a.srcPos).toTermName,
mt.paramType(s.index, a.srcPos),
mt.isByName(s.index, a.srcPos),
mt.isDirectContext(s.index, a.srcPos),
isDirectContext,
owner,
depResult.canBeDependent,
named,
Expand Down

0 comments on commit ac8a949

Please sign in to comment.