Skip to content

Commit e614f23

Browse files
authored
Change cc syntax (#17377)
Trial: change cc syntax From To {xs} T T^{xs} {*} T T^ (xs) A -> B A ->{xs} B
2 parents 82efd33 + 156ec83 commit e614f23

File tree

162 files changed

+1082
-1055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1082
-1055
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,16 +1824,6 @@ object desugar {
18241824
flatTree(pats1 map (makePatDef(tree, mods, _, rhs)))
18251825
case ext: ExtMethods =>
18261826
Block(List(ext), Literal(Constant(())).withSpan(ext.span))
1827-
case CapturingTypeTree(refs, parent) =>
1828-
// convert `{refs} T` to `T @retains refs`
1829-
// `{refs}-> T` to `-> (T @retainsByName refs)`
1830-
def annotate(annotName: TypeName, tp: Tree) =
1831-
Annotated(tp, New(scalaAnnotationDot(annotName), List(refs)))
1832-
parent match
1833-
case ByNameTypeTree(restpt) =>
1834-
cpy.ByNameTypeTree(parent)(annotate(tpnme.retainsByName, restpt))
1835-
case _ =>
1836-
annotate(tpnme.retains, parent)
18371827
case f: FunctionWithMods if f.hasErasedParams => makeFunctionWithValDefs(f, pt)
18381828
}
18391829
desugared.withSpan(tree.span)
@@ -1927,7 +1917,7 @@ object desugar {
19271917
}
19281918
tree match
19291919
case tree: FunctionWithMods =>
1930-
untpd.FunctionWithMods(applyVParams, tree.body, tree.mods, tree.erasedParams)
1920+
untpd.FunctionWithMods(applyVParams, result, tree.mods, tree.erasedParams)
19311921
case _ => untpd.Function(applyVParams, result)
19321922
}
19331923
}
@@ -1993,8 +1983,6 @@ object desugar {
19931983
case _ => traverseChildren(tree)
19941984
}
19951985
}.traverse(body)
1996-
case CapturingTypeTree(refs, parent) =>
1997-
collect(parent)
19981986
case _ =>
19991987
}
20001988
collect(tree)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
223223
/** Strip `=> T` to `T` and (under pureFunctions) `{refs}-> T` to `T` */
224224
def stripByNameType(tree: Tree)(using Context): Tree = unsplice(tree) match
225225
case ByNameTypeTree(t1) => t1
226-
case untpd.CapturingTypeTree(_, parent) =>
227-
val parent1 = stripByNameType(parent)
228-
if parent1 eq parent then tree else parent1
229226
case _ => tree
230227

231228
/** All type and value parameter symbols of this DefDef */
@@ -473,13 +470,15 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
473470
*/
474471
object ImpureByNameTypeTree:
475472

476-
def apply(tp: ByNameTypeTree)(using Context): untpd.CapturingTypeTree =
477-
untpd.CapturingTypeTree(
478-
untpd.captureRoot.withSpan(tp.span.startPos) :: Nil, tp)
473+
def apply(tp: Tree)(using Context): untpd.ByNameTypeTree =
474+
untpd.ByNameTypeTree(
475+
untpd.CapturesAndResult(
476+
untpd.captureRoot.withSpan(tp.span.startPos) :: Nil, tp))
479477

480-
def unapply(tp: Tree)(using Context): Option[ByNameTypeTree] = tp match
481-
case untpd.CapturingTypeTree(id @ Select(_, nme.CAPTURE_ROOT) :: Nil, bntp: ByNameTypeTree)
482-
if id.span == bntp.span.startPos => Some(bntp)
478+
def unapply(tp: Tree)(using Context): Option[Tree] = tp match
479+
case untpd.ByNameTypeTree(
480+
untpd.CapturesAndResult(id @ Select(_, nme.CAPTURE_ROOT) :: Nil, result))
481+
if id.span == result.span.startPos => Some(result)
483482
case _ => None
484483
end ImpureByNameTypeTree
485484
}

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
148148
}
149149

150150
/** {x1, ..., xN} T (only relevant under captureChecking) */
151-
case class CapturingTypeTree(refs: List[Tree], parent: Tree)(implicit @constructorOnly src: SourceFile) extends TypTree
151+
case class CapturesAndResult(refs: List[Tree], parent: Tree)(implicit @constructorOnly src: SourceFile) extends TypTree
152152

153153
/** Short-lived usage in typer, does not need copy/transform/fold infrastructure */
154154
case class DependentTypeTree(tp: List[Symbol] => Type)(implicit @constructorOnly src: SourceFile) extends Tree
@@ -501,6 +501,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
501501
def captureRoot(using Context): Select =
502502
Select(scalaDot(nme.caps), nme.CAPTURE_ROOT)
503503

504+
def makeRetaining(parent: Tree, refs: List[Tree], annotName: TypeName)(using Context): Annotated =
505+
Annotated(parent, New(scalaAnnotationDot(annotName), List(refs)))
506+
504507
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(using Context): DefDef =
505508
DefDef(nme.CONSTRUCTOR, joinParams(tparams, vparamss), TypeTree(), rhs)
506509

@@ -658,9 +661,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
658661
case tree: Number if (digits == tree.digits) && (kind == tree.kind) => tree
659662
case _ => finalize(tree, untpd.Number(digits, kind))
660663
}
661-
def CapturingTypeTree(tree: Tree)(refs: List[Tree], parent: Tree)(using Context): Tree = tree match
662-
case tree: CapturingTypeTree if (refs eq tree.refs) && (parent eq tree.parent) => tree
663-
case _ => finalize(tree, untpd.CapturingTypeTree(refs, parent))
664+
def CapturesAndResult(tree: Tree)(refs: List[Tree], parent: Tree)(using Context): Tree = tree match
665+
case tree: CapturesAndResult if (refs eq tree.refs) && (parent eq tree.parent) => tree
666+
case _ => finalize(tree, untpd.CapturesAndResult(refs, parent))
664667

665668
def TypedSplice(tree: Tree)(splice: tpd.Tree)(using Context): ProxyTree = tree match {
666669
case tree: TypedSplice if splice `eq` tree.splice => tree
@@ -723,8 +726,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
723726
tree
724727
case MacroTree(expr) =>
725728
cpy.MacroTree(tree)(transform(expr))
726-
case CapturingTypeTree(refs, parent) =>
727-
cpy.CapturingTypeTree(tree)(transform(refs), transform(parent))
729+
case CapturesAndResult(refs, parent) =>
730+
cpy.CapturesAndResult(tree)(transform(refs), transform(parent))
728731
case _ =>
729732
super.transformMoreCases(tree)
730733
}
@@ -782,7 +785,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
782785
this(x, splice)
783786
case MacroTree(expr) =>
784787
this(x, expr)
785-
case CapturingTypeTree(refs, parent) =>
788+
case CapturesAndResult(refs, parent) =>
786789
this(this(x, refs), parent)
787790
case _ =>
788791
super.foldMoreCases(x, tree)

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ sealed abstract class CaptureSet extends Showable:
7070
assert(!isConst)
7171
asInstanceOf[Var]
7272

73-
/** Does this capture set contain the root reference `*` as element? */
73+
/** Does this capture set contain the root reference `cap` as element? */
7474
final def isUniversal(using Context) =
7575
elems.exists {
7676
case ref: TermRef => ref.symbol == defn.captureRoot
@@ -133,7 +133,7 @@ sealed abstract class CaptureSet extends Showable:
133133
* for `x` in a state where we assume all supersets of `x` have just the elements
134134
* known at this point. On the other hand if x's capture set has no known elements,
135135
* a set `cs` might account for `x` only if it subsumes `x` or it contains the
136-
* root capability `*`.
136+
* root capability `cap`.
137137
*/
138138
def mightAccountFor(x: CaptureRef)(using Context): Boolean =
139139
reporting.trace(i"$this mightAccountFor $x, ${x.captureSetOfInfo}?", show = true) {
@@ -270,7 +270,7 @@ sealed abstract class CaptureSet extends Showable:
270270
def substParams(tl: BindingType, to: List[Type])(using Context) =
271271
map(Substituters.SubstParamsMap(tl, to))
272272

273-
/** Invoke handler if this set has (or later aquires) the root capability `*` */
273+
/** Invoke handler if this set has (or later aquires) the root capability `cap` */
274274
def disallowRootCapability(handler: () => Context ?=> Unit)(using Context): this.type =
275275
if isUniversal then handler()
276276
this
@@ -372,7 +372,7 @@ object CaptureSet:
372372
def isConst = isSolved
373373
def isAlwaysEmpty = false
374374

375-
/** A handler to be invoked if the root reference `*` is added to this set */
375+
/** A handler to be invoked if the root reference `cap` is added to this set */
376376
var rootAddedHandler: () => Context ?=> Unit = () => ()
377377

378378
var description: String = ""

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ object CheckCaptures:
5252
* @param outer0 the next enclosing environment
5353
*/
5454
case class Env(
55-
owner: Symbol,
56-
nestedInOwner: Boolean,
57-
captured: CaptureSet,
58-
isBoxed: Boolean,
59-
outer0: Env | Null
60-
):
55+
owner: Symbol,
56+
nestedInOwner: Boolean,
57+
captured: CaptureSet,
58+
isBoxed: Boolean,
59+
outer0: Env | Null):
60+
6161
def outer = outer0.nn
6262

6363
def isOutermost = outer0 == null
@@ -433,7 +433,7 @@ class CheckCaptures extends Recheck, SymTransformer:
433433
case defn.FunctionOf(ptformals, _, _)
434434
if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) =>
435435
// Redo setup of the anonymous function so that formal parameters don't
436-
// get capture sets. This is important to avoid false widenings to `*`
436+
// get capture sets. This is important to avoid false widenings to `cap`
437437
// when taking the base type of the actual closures's dependent function
438438
// type so that it conforms to the expected non-dependent function type.
439439
// See withLogFile.scala for a test case.
@@ -582,7 +582,7 @@ class CheckCaptures extends Recheck, SymTransformer:
582582
refs.disallowRootCapability { () =>
583583
val kind = if tree.isInstanceOf[ValDef] then "mutable variable" else "expression"
584584
report.error(
585-
em"""The $kind's type $wtp is not allowed to capture the root capability `*`.
585+
em"""The $kind's type $wtp is not allowed to capture the root capability `cap`.
586586
|This usually means that a capability persists longer than its allowed lifetime.""",
587587
tree.srcPos)
588588
}
@@ -768,9 +768,9 @@ class CheckCaptures extends Recheck, SymTransformer:
768768
styp1.capturing(if alwaysConst then CaptureSet(cs1.elems) else cs1).forceBoxStatus(resultBoxed)
769769

770770
if needsAdaptation then
771-
val criticalSet = // the set which is not allowed to have `*`
772-
if covariant then cs1 // can't box with `*`
773-
else expected.captureSet // can't unbox with `*`
771+
val criticalSet = // the set which is not allowed to have `cap`
772+
if covariant then cs1 // can't box with `cap`
773+
else expected.captureSet // can't unbox with `cap`
774774
if criticalSet.isUniversal && expected.isValueType then
775775
// We can't box/unbox the universal capability. Leave `actual` as it is
776776
// so we get an error in checkConforms. This tends to give better error
@@ -779,11 +779,11 @@ class CheckCaptures extends Recheck, SymTransformer:
779779
println(i"cannot box/unbox $actual vs $expected")
780780
actual
781781
else
782-
// Disallow future addition of `*` to `criticalSet`.
782+
// Disallow future addition of `cap` to `criticalSet`.
783783
criticalSet.disallowRootCapability { () =>
784784
report.error(
785785
em"""$actual cannot be box-converted to $expected
786-
|since one of their capture sets contains the root capability `*`""",
786+
|since one of their capture sets contains the root capability `cap`""",
787787
pos)
788788
}
789789
if !insertBox then // unboxing
@@ -922,8 +922,8 @@ class CheckCaptures extends Recheck, SymTransformer:
922922
* usingLogFile[box ?1 () -> Unit] { (f: {*} File) => () => { f.write(0) } }
923923
*
924924
* We may propagate `f` into ?1, making ?1 ill-formed.
925-
* This also causes soundness issues, since `f` in ?1 should be widened to `*`,
926-
* giving rise to an error that `*` cannot be included in a boxed capture set.
925+
* This also causes soundness issues, since `f` in ?1 should be widened to `cap`,
926+
* giving rise to an error that `cap` cannot be included in a boxed capture set.
927927
*
928928
* To solve this, we still allow ?1 to capture parameter refs like `f`, but
929929
* compensate this by pushing the widened capture set of `f` into ?1.

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ class Definitions {
968968
@tu lazy val BreakClass: Symbol = requiredClass("scala.util.boundary.Break")
969969

970970
@tu lazy val CapsModule: Symbol = requiredModule("scala.caps")
971-
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("*")
971+
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("cap")
972972
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
973973
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
974974
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ object StdNames {
286286
// ----- Term names -----------------------------------------
287287

288288
// Compiler-internal
289-
val CAPTURE_ROOT: N = "*"
289+
val CAPTURE_ROOT: N = "cap"
290290
val CONSTRUCTOR: N = "<init>"
291291
val STATIC_CONSTRUCTOR: N = "<clinit>"
292292
val EVT2U: N = "evt2u$"
@@ -301,6 +301,7 @@ object StdNames {
301301
val THROWS: N = "$throws"
302302
val U2EVT: N = "u2evt$"
303303
val ALLARGS: N = "$allArgs"
304+
val UPARROW: N = "^"
304305

305306
final val Nil: N = "Nil"
306307
final val Predef: N = "Predef"

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ object Types {
20932093
*/
20942094
final def isTracked(using Context): Boolean = canBeTracked && !captureSetOfInfo.isAlwaysEmpty
20952095

2096-
/** Is this reference the root capability `*` ? */
2096+
/** Is this reference the root capability `cap` ? */
20972097
def isRootCapability(using Context): Boolean = false
20982098

20992099
/** Normalize reference so that it can be compared with `eq` for equality */
@@ -4989,9 +4989,9 @@ object Types {
49894989
if (!givenSelf.isValueType) appliedRef
49904990
else if (clsd.is(Module)) givenSelf
49914991
else if (ctx.erasedTypes) appliedRef
4992-
else givenSelf match
4993-
case givenSelf @ EventuallyCapturingType(tp, _) =>
4994-
givenSelf.derivedAnnotatedType(tp & appliedRef, givenSelf.annot)
4992+
else givenSelf.dealiasKeepAnnots match
4993+
case givenSelf1 @ EventuallyCapturingType(tp, _) =>
4994+
givenSelf1.derivedAnnotatedType(tp & appliedRef, givenSelf1.annot)
49954995
case _ =>
49964996
AndType(givenSelf, appliedRef)
49974997
}

0 commit comments

Comments
 (0)