Skip to content

Commit 77d08ef

Browse files
committed
Drop addResultBoxes
1 parent d2b9c9d commit 77d08ef

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -199,38 +199,6 @@ class CheckCaptures extends Recheck, SymTransformer:
199199
}
200200
checkSubset(targetSet, curEnv.captured, pos)
201201

202-
/** If result type of a function type has toplevel boxed captures, propagate
203-
* them to the function type as a whole. Such boxed captures
204-
* can be created by substitution or as-seen-from. Propagating captures to the
205-
* left simulates an unbox operation on the result. I.e. if f has type `A -> box C B`
206-
* then in theory we need to unbox with
207-
*
208-
* x => C o- f(x)
209-
*
210-
* and that also propagates C into the type of the unboxing expression.
211-
* TODO: Generalize this to boxed captues in other parts of a function type.
212-
* Test case in pos-.../boxed1.scala.
213-
*/
214-
def addResultBoxes(tp: Type)(using Context): Type =
215-
def includeBoxed(res: Type) =
216-
//if !res.boxedCaptureSet.isAlwaysEmpty then
217-
// println(i"add boxed $tp from ${res.boxedCaptureSet}")
218-
tp.capturing(res.boxedCaptureSet)
219-
val tp1 = tp.dealias
220-
val boxedTp = tp1 match
221-
case tp1 @ AppliedType(_, args) if defn.isNonRefinedFunction(tp1) =>
222-
includeBoxed(args.last)
223-
case tp1 @ RefinedType(_, _, rinfo) if defn.isFunctionType(tp1) =>
224-
includeBoxed(rinfo.finalResultType)
225-
case tp1 @ CapturingType(parent, refs) =>
226-
val boxedParent = addResultBoxes(parent)
227-
if boxedParent eq parent then tp1
228-
else boxedParent.capturing(refs)
229-
case _ =>
230-
tp1
231-
if (boxedTp eq tp1) then tp else boxedTp
232-
end addResultBoxes
233-
234202
def assertSub(cs1: CaptureSet, cs2: CaptureSet)(using Context) =
235203
assert(cs1.subCaptures(cs2, frozen = false).isOK, i"$cs1 is not a subset of $cs2")
236204

@@ -260,9 +228,7 @@ class CheckCaptures extends Recheck, SymTransformer:
260228
override def recheckSelection(tree: Select, qualType: Type, name: Name)(using Context) = {
261229
val selType = super.recheckSelection(tree, qualType, name)
262230
val selCs = selType.widen.captureSet
263-
if selCs.isAlwaysEmpty
264-
|| selType.widen.isBoxedCapturing
265-
|| qualType.isBoxedCapturing then
231+
if selCs.isAlwaysEmpty || selType.widen.isBoxedCapturing || qualType.isBoxedCapturing then
266232
selType
267233
else
268234
val qualCs = qualType.captureSet
@@ -489,8 +455,7 @@ class CheckCaptures extends Recheck, SymTransformer:
489455
checkNotUniversal(parent)
490456
case _ =>
491457
checkNotUniversal(typeToCheck)
492-
val tpe1 = if false && tree.isTerm then addResultBoxes(tpe) else tpe
493-
super.recheckFinish(tpe1, tree, pt)
458+
super.recheckFinish(tpe, tree, pt)
494459

495460
/** This method implements the rule outlined in #14390:
496461
* When checking an expression `e: T` against an expected type `Cx Tx`

0 commit comments

Comments
 (0)