Skip to content

Commit 0ce75e1

Browse files
committed
Polishings mostly in typer
1 parent 8bab2ac commit 0ce75e1

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
196196
private val byNameMarker = marker("ByName")
197197
private val matchMarker = marker("Match")
198198
private val superMarker = marker("Super")
199-
private val retainsMarker = marker("Retains")
200199

201200
/** Extract the API representation of a source file */
202201
def apiSource(tree: Tree): Seq[api.ClassLike] = {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ object Checking {
599599
def checkNoPrivateLeaks(sym: Symbol)(using Context): Type = {
600600
class NotPrivate extends TypeMap {
601601
var errors: List[() => String] = Nil
602-
var inCaptureSet: Boolean = false
602+
private var inCaptureSet: Boolean = false
603603

604604
def accessBoundary(sym: Symbol): Symbol =
605605
if (sym.is(Private) || !sym.owner.isClass) sym.owner
@@ -622,7 +622,7 @@ object Checking {
622622
}
623623
&& !(inCaptureSet && other.isAllOf(LocalParamAccessor))
624624
// class parameters in capture sets are not treated as leaked since in
625-
// phase -Ycc these are treated as normal vals.
625+
// phase CheckCaptures these are treated as normal vals.
626626

627627
def apply(tp: Type): Type = tp match {
628628
case tp: NamedType =>
@@ -660,9 +660,10 @@ object Checking {
660660
case tp @ AnnotatedType(underlying, annot)
661661
if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot =>
662662
val underlying1 = this(underlying)
663+
val saved = inCaptureSet
663664
inCaptureSet = true
664665
val annot1 = annot.mapWith(this)
665-
inCaptureSet = false
666+
inCaptureSet = saved
666667
derivedAnnotatedType(tp, underlying1, annot1)
667668
case _ =>
668669
mapOver(tp)
@@ -1434,6 +1435,10 @@ trait Checking {
14341435
val kind = if pattern then "pattern selector" else "value"
14351436
report.warning(MatchableWarning(tp, pattern), pos)
14361437

1438+
/** Check that there is an implicit capability to throw a checked exception
1439+
* if the saferExceptions feature is turned on. Return that capability is it exists,
1440+
* EmptyTree otherwise.
1441+
*/
14371442
def checkCanThrow(tp: Type, span: Span)(using Context): Tree =
14381443
if Feature.enabled(Feature.saferExceptions) && tp.isCheckedException then
14391444
ctx.typer.implicitArgTree(defn.CanThrowClass.typeRef.appliedTo(tp), span)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ trait ImportSuggestions:
319319
* If there's nothing to suggest, an empty string is returned.
320320
*/
321321
override def importSuggestionAddendum(pt: Type)(using Context): String =
322-
if ctx.phase == Phases.checkCapturesPhase then return ""
322+
if ctx.phase == Phases.checkCapturesPhase then
323+
return "" // it's too late then to look for implicits
323324
val (fullMatches, headMatches) =
324325
importSuggestions(pt)(using ctx.fresh.setExploreTyperState())
325326
implicits.println(i"suggestions for $pt in ${ctx.owner} = ($fullMatches%, %, $headMatches%, %)")

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Decorators._
1313
import config.Printers.{gadts, typr}
1414
import annotation.tailrec
1515
import reporting._
16-
import cc.{CapturingType, derivedCapturingType}
1716
import collection.mutable
1817

1918
import scala.annotation.internal.sharable
@@ -526,10 +525,10 @@ object Inferencing {
526525
}
527526

528527
/** Replace every top-level occurrence of a wildcard type argument by
529-
* a fresh skolem type. The skolem types are of the form $i.CAP, where
530-
* $i is a skolem of type `scala.internal.TypeBox`, and `CAP` is its
531-
* type member. See the documentation of `TypeBox` for a rationale why we do this.
532-
*/
528+
* a fresh skolem type. The skolem types are of the form $i.CAP, where
529+
* $i is a skolem of type `scala.internal.TypeBox`, and `CAP` is its
530+
* type member. See the documentation of `TypeBox` for a rationale why we do this.
531+
*/
533532
def captureWildcards(tp: Type)(using Context): Type = derivedOnDealias(tp) {
534533
case tp @ AppliedType(tycon, args) if tp.hasWildcardArg =>
535534
val tparams = tycon.typeParamSymbols
@@ -545,7 +544,6 @@ object Inferencing {
545544
case tp: RefinedType => tp.derivedRefinedType(captureWildcards(tp.parent), tp.refinedName, tp.refinedInfo)
546545
case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent))
547546
case tp: LazyRef => captureWildcards(tp.ref)
548-
case CapturingType(parent, refs) => tp.derivedCapturingType(captureWildcards(parent), refs)
549547
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)
550548
case _ => tp
551549
}
@@ -736,7 +734,6 @@ trait Inferencing { this: Typer =>
736734
if !argType.isSingleton then argType = SkolemType(argType)
737735
argType <:< tvar
738736
case _ =>
739-
() // scala-meta complains if this is missing, but I could not mimimize further
740737
end constrainIfDependentParamRef
741738
}
742739

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,14 @@ trait TypeAssigner {
291291

292292
def safeSubstMethodParams(mt: MethodType, argTypes: List[Type])(using Context): Type =
293293
if mt.isResultDependent then safeSubstParams(mt.resultType, mt.paramRefs, argTypes)
294+
else if mt.isCaptureDependent then mt.resultType.substParams(mt, argTypes)
294295
else mt.resultType
295296

296297
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(using Context): Apply = {
297298
val ownType = fn.tpe.widen match {
298299
case fntpe: MethodType =>
299300
if (fntpe.paramInfos.hasSameLengthAs(args) || ctx.phase.prev.relaxedTyping)
300-
if fntpe.isCaptureDependent then
301-
fntpe.resultType.substParams(fntpe, args.tpes)
302-
else
303-
safeSubstMethodParams(fntpe, args.tpes)
301+
safeSubstMethodParams(fntpe, args.tpes)
304302
else
305303
errorType(i"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
306304
case t =>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,12 +1874,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18741874
val expr1 = typed(tree.expr, defn.ThrowableType)
18751875
val cap = checkCanThrow(expr1.tpe.widen, tree.span)
18761876
val res = Throw(expr1).withSpan(tree.span)
1877-
if cap.isEmpty || !ctx.settings.Ycc.value || ctx.isAfterTyper then res
1878-
else
1877+
if ctx.settings.Ycc.value && !cap.isEmpty && !ctx.isAfterTyper then
1878+
// Record access to the CanThrow capabulity recovered in `cap` by wrapping
1879+
// the type of the `throw` (i.e. Nothing) in a `@requiresCapability` annotatoon.
18791880
Typed(res,
18801881
TypeTree(
18811882
AnnotatedType(res.tpe,
18821883
Annotation(defn.RequiresCapabilityAnnot, cap))))
1884+
else res
18831885

18841886
def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(using Context): SeqLiteral = {
18851887
val elemProto = pt.stripNull.elemType match {

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ class CompilationTests {
241241
given TestGroup = TestGroup("recheck")
242242
aggregateTests(
243243
compileFilesInDir("tests/new", recheckOptions),
244-
compileFilesInDir("tests/pos", recheckOptions, FileFilter.exclude(TestSources.posTestRecheckExcluded)),
245-
compileFilesInDir("tests/run", recheckOptions, FileFilter.exclude(TestSources.runTestRecheckExcluded))
244+
//Following are disabled since they take too long for what they provide.
245+
//compileFilesInDir("tests/pos", recheckOptions, FileFilter.exclude(TestSources.posTestRecheckExcluded)),
246+
//compileFilesInDir("tests/run", recheckOptions, FileFilter.exclude(TestSources.runTestRecheckExcluded))
246247
).checkCompile()
247248

248249
// Explicit nulls tests

0 commit comments

Comments
 (0)