Skip to content

Commit

Permalink
Return values already included in result
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Sep 3, 2024
1 parent 2806167 commit fac91e3
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ class Objects(using Context @constructorOnly):
// Only perform garbage collection for method context
val heapGC =
if ctx == EvalContext.Method then
Heap.gc(value :: Returns.currentReturns, footprint, heapAfter, changeSetNew, State.currentObjectRef)
Heap.gc(value :: Nil, footprint, heapAfter, changeSetNew, State.currentObjectRef)
else
heapAfter
Res(value, heapGC, changeSetNew)
Expand Down Expand Up @@ -749,17 +749,6 @@ class Objects(using Context @constructorOnly):
case None =>
report.warning("[Internal error] Unhandled return for method " + meth + " in " + meth.owner.show + ". Trace:\n" + Trace.show, Trace.position)

/**
* Return the current return values in a method context.
*
* Warning: only use this method if it is certain that a method body has just
* finished before any other code is executed.
*
* Calling this method from lazy val or function context is problematic.
*/
def currentReturns(using data: Data): List[Value] =
data.last.values.toList

type Contextual[T] = (Context, State.Data, Env.Data, Cache.Data, Heap.MutableData, Regions.Data, Returns.Data, Trace) ?=> T

// --------------------------- domain operations -----------------------------
Expand Down Expand Up @@ -835,9 +824,8 @@ class Objects(using Context @constructorOnly):
* @param superType The type of the super in a super call. NoType for non-super calls.
* @param needResolve Whether the target of the call needs resolution?
*/
def call(value: Value, meth: Symbol, args: List[ArgInfo], receiver: Type, superType: Type, needResolve: Boolean = true): Contextual[Value] = log.force(
"call " + meth.show + ", this = " + value.show + ", args = " + args.map(_.value.show) + ", heap.size = " + Heap.getHeapData().size,
printer, (_: Value).show) {
def call(value: Value, meth: Symbol, args: List[ArgInfo], receiver: Type, superType: Type, needResolve: Boolean = true): Contextual[Value] = log(
"call " + meth.show + ", this = " + value.show + ", args = " + args.map(_.value.show) + ", heap.size = " + Heap.getHeapData().size, printer, (_: Value).show) {

value.filterClass(meth.owner) match
case Cold =>
Expand Down Expand Up @@ -970,7 +958,7 @@ class Objects(using Context @constructorOnly):
// No usage of `return` is possible in constructors --- still install
// return handler for uniform handling of method context.
Returns.installHandler(ctor)
val res = eval(ddef.rhs, ref, cls, EvalContext.Method)
val res = eval(tree, ref, cls, EvalContext.Method)
Returns.popHandler(ctor)
res

Expand Down

0 comments on commit fac91e3

Please sign in to comment.