Skip to content

Commit 2c630b7

Browse files
committed
Revert "into" syntax changes
We now make into be just a type alias that the compiler knows about. No syntax changes are necessary.
1 parent 6896fe3 commit 2c630b7

File tree

9 files changed

+15
-82
lines changed

9 files changed

+15
-82
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,11 +2268,8 @@ object desugar {
22682268
assert(ctx.mode.isExpr || ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), ctx.mode)
22692269
Select(t, op.name)
22702270
case PrefixOp(op, t) =>
2271-
if op.name == tpnme.into then
2272-
Annotated(t, New(ref(defn.IntoAnnot.typeRef), Nil :: Nil))
2273-
else
2274-
val nspace = if (ctx.mode.is(Mode.Type)) tpnme else nme
2275-
Select(t, nspace.UNARY_PREFIX ++ op.name)
2271+
val nspace = if (ctx.mode.is(Mode.Type)) tpnme else nme
2272+
Select(t, nspace.UNARY_PREFIX ++ op.name)
22762273
case ForDo(enums, body) =>
22772274
makeFor(nme.foreach, nme.foreach, enums, body) orElse tree
22782275
case ForYield(enums, body) =>

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
565565
ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree)
566566
.withFlags(flags)
567567

568-
def isInto(t: Tree)(using Context): Boolean = t match
569-
case PrefixOp(Ident(tpnme.into), _) => true
570-
case Function(_, res) => isInto(res)
571-
case Parens(t) => isInto(t)
572-
case _ => false
573-
574568
def lambdaAbstract(params: List[ValDef] | List[TypeDef], tpt: Tree)(using Context): Tree =
575569
params match
576570
case Nil => tpt

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ object StdNames {
132132
val EXCEPTION_RESULT_PREFIX: N = "exceptionResult"
133133
val EXPAND_SEPARATOR: N = str.EXPAND_SEPARATOR
134134
val IMPORT: N = "<import>"
135-
val INTO: N = "$into"
136135
val MODULE_SUFFIX: N = str.MODULE_SUFFIX
137136
val OPS_PACKAGE: N = "<special-ops>"
138137
val OVERLOADED: N = "<overloaded>"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import Capabilities.*
4444

4545
import scala.annotation.internal.sharable
4646
import scala.annotation.threadUnsafe
47-
import dotty.tools.dotc.cc.ccConfig
4847

4948
object Types extends TypeUtils {
5049

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ object Parsers {
7878
enum ParseKind:
7979
case Expr, Type, Pattern
8080

81-
enum IntoOK:
82-
case Yes, No, Nested
83-
8481
type StageKind = Int
8582
object StageKind {
8683
val None = 0
@@ -1582,8 +1579,8 @@ object Parsers {
15821579
/** Same as [[typ]], but if this results in a wildcard it emits a syntax error and
15831580
* returns a tree for type `Any` instead.
15841581
*/
1585-
def toplevelTyp(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
1586-
rejectWildcardType(typ(intoOK, inContextBound))
1582+
def toplevelTyp(inContextBound: Boolean = false): Tree =
1583+
rejectWildcardType(typ(inContextBound))
15871584

15881585
private def getFunction(tree: Tree): Option[Function] = tree match {
15891586
case Parens(tree1) => getFunction(tree1)
@@ -1642,21 +1639,12 @@ object Parsers {
16421639
* | `(' [ FunArgType {`,' FunArgType } ] `)'
16431640
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
16441641
* MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
1645-
* IntoType ::= [‘into’] IntoTargetType
1646-
* | ‘( IntoType ‘)’
1647-
* IntoTargetType ::= Type
1648-
* | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
16491642
*/
1650-
def typ(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
1643+
def typ(inContextBound: Boolean = false): Tree =
16511644
val start = in.offset
16521645
var imods = Modifiers()
16531646
val erasedArgs: ListBuffer[Boolean] = ListBuffer()
16541647

1655-
def nestedIntoOK(token: Int) =
1656-
if token == TLARROW then IntoOK.No
1657-
else if intoOK == IntoOK.Nested then IntoOK.Yes
1658-
else intoOK
1659-
16601648
def functionRest(params: List[Tree]): Tree =
16611649
val paramSpan = Span(start, in.lastOffset)
16621650
atSpan(start, in.offset) {
@@ -1685,9 +1673,8 @@ object Parsers {
16851673
else
16861674
accept(ARROW)
16871675

1688-
def resType() = typ(nestedIntoOK(token))
16891676
val resultType =
1690-
if isPure then capturesAndResult(resType) else resType()
1677+
if isPure then capturesAndResult(typ) else typ()
16911678
if token == TLARROW then
16921679
for case ValDef(_, tpt, _) <- params do
16931680
if isByNameType(tpt) then
@@ -1722,12 +1709,6 @@ object Parsers {
17221709
syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
17231710
t
17241711

1725-
def isIntoPrefix: Boolean =
1726-
intoOK == IntoOK.Yes
1727-
&& in.isIdent(nme.into)
1728-
&& in.featureEnabled(Feature.into)
1729-
&& canStartTypeTokens.contains(in.lookahead.token)
1730-
17311712
def convertToElem(t: Tree): Tree = t match
17321713
case ByNameTypeTree(t1) =>
17331714
syntaxError(ByNameParameterNotSupported(t), t.span)
@@ -1764,32 +1745,6 @@ object Parsers {
17641745
funArgType()
17651746
commaSeparatedRest(t, funArg)
17661747
accept(RPAREN)
1767-
1768-
val intoAllowed =
1769-
intoOK == IntoOK.Yes
1770-
&& args.lengthCompare(1) == 0
1771-
&& (!canFollowSimpleTypeTokens.contains(in.token) || followingIsVararg())
1772-
val byNameAllowed = in.isArrow || isPureArrow
1773-
1774-
def sanitize(arg: Tree): Tree = arg match
1775-
case ByNameTypeTree(t) if !byNameAllowed =>
1776-
syntaxError(ByNameParameterNotSupported(t), t.span)
1777-
t
1778-
case PrefixOp(id @ Ident(tpnme.into), t) if !intoAllowed =>
1779-
syntaxError(em"no `into` modifier allowed here", id.span)
1780-
t
1781-
case Parens(t) =>
1782-
cpy.Parens(arg)(sanitize(t))
1783-
case arg: FunctionWithMods =>
1784-
val body1 = sanitize(arg.body)
1785-
if body1 eq arg.body then arg
1786-
else FunctionWithMods(arg.args, body1, arg.mods, arg.erasedParams).withSpan(arg.span)
1787-
case Function(args, res) if !intoAllowed =>
1788-
cpy.Function(arg)(args, sanitize(res))
1789-
case arg =>
1790-
arg
1791-
val args1 = args.mapConserve(sanitize)
1792-
17931748
if in.isArrow || isPureArrow || erasedArgs.contains(true) then
17941749
functionRest(args)
17951750
else
@@ -1817,8 +1772,6 @@ object Parsers {
18171772
typ()
18181773
else if in.token == INDENT then
18191774
enclosed(INDENT, typ())
1820-
else if isIntoPrefix then
1821-
PrefixOp(typeIdent(), typ(IntoOK.Nested))
18221775
else
18231776
typeRest(infixType(inContextBound))
18241777
end typ
@@ -2228,9 +2181,7 @@ object Parsers {
22282181
* | `=>' Type
22292182
* | `->' [CaptureSet] Type
22302183
*/
2231-
val funArgType: () => Tree =
2232-
() => paramTypeOf(() => typ(IntoOK.Yes))
2233-
// We allow intoOK and filter out afterwards in typ()
2184+
val funArgType: () => Tree = () => paramTypeOf(typ)
22342185

22352186
/** ParamType ::= ParamValueType
22362187
* | `=>' ParamValueType
@@ -2239,11 +2190,9 @@ object Parsers {
22392190
def paramType(): Tree = paramTypeOf(paramValueType)
22402191

22412192
/** ParamValueType ::= Type [`*']
2242-
* | IntoType
2243-
* | ‘(’ IntoType ‘)’ `*'
22442193
*/
22452194
def paramValueType(): Tree =
2246-
val t = toplevelTyp(IntoOK.Yes)
2195+
val t = toplevelTyp()
22472196
if isIdent(nme.raw.STAR) then
22482197
if !t.isInstanceOf[Parens] && isInto(t) then
22492198
syntaxError(
@@ -3573,7 +3522,7 @@ object Parsers {
35733522
*/
35743523
def contextTypes(paramOwner: ParamOwner, numLeadParams: Int, impliedMods: Modifiers): List[ValDef] =
35753524
typesToParams(
3576-
commaSeparated(() => paramTypeOf(() => toplevelTyp())),
3525+
commaSeparated(() => paramTypeOf(toplevelTyp)),
35773526
paramOwner, numLeadParams, impliedMods)
35783527

35793528
def typesToParams(tps: List[Tree], paramOwner: ParamOwner, numLeadParams: Int, impliedMods: Modifiers): List[ValDef] =

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
334334
case AnnotatedType(tpe, annot) =>
335335
if defn.SilentAnnots.contains(annot.symbol) && !printDebug then
336336
toText(tpe)
337-
else if (annot.symbol == defn.IntoAnnot || annot.symbol == defn.IntoParamAnnot)
337+
else if (annot.symbol == defn.IntoParamAnnot)
338338
&& !printDebug
339-
then atPrec(GlobalPrec)( Str("into ") ~ toText(tpe) )
339+
then atPrec(GlobalPrec):
340+
"into[" ~ toText(tpe) ~ "]"
340341
else if annot.isInstanceOf[CaptureAnnotation] then
341342
toTextLocal(tpe) ~ "^" ~ toText(annot)
342343
else

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
702702
&& Feature.ccEnabled && !printDebug
703703
&& Phases.checkCapturesPhase.exists // might be missing on -Ytest-pickler
704704
then toTextRetainsAnnot
705-
else if annot.symbol.enclosingClass == defn.IntoAnnot && !printDebug then
706-
atPrec(GlobalPrec):
707-
Str("into ") ~ toText(arg)
708705
else toTextAnnot
709706
case EmptyTree =>
710707
"<empty>"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26722672
&& checkedArgs(1).tpe.derivesFrom(defn.RuntimeExceptionClass)
26732673
then
26742674
report.error(em"throws clause cannot be defined for RuntimeException", checkedArgs(1).srcPos)
2675+
else if tycon == defn.IntoType then
2676+
// <into> is defined in package scala but this should be hidden from user programs
2677+
report.error(em"not found: <into>", tpt1.srcPos)
26752678
else if (ctx.isJava)
26762679
if tycon eq defn.ArrayClass then
26772680
checkedArgs match {

docs/_docs/internals/syntax.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,6 @@ FunArgTypes ::= FunArgType { ‘,’ FunArgType }
219219
ParamType ::= [‘=>’] ParamValueType
220220
| ‘->’ [CaptureSet] ParamValueType -- under captureChecking
221221
ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
222-
| IntoType
223-
| ‘(’ IntoType ‘)’ ‘*’ PostfixOp(t, "*")
224-
IntoType ::= [‘into’] IntoTargetType Into(t)
225-
| ‘(’ IntoType ‘)’
226-
IntoTargetType ::= Type
227-
| FunTypeArgs (‘=>’ | ‘?=>’) IntoType
228222
TypeArgs ::= ‘[’ TypeArg {‘,’ TypeArg} ‘]’ ts
229223
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>> ds
230224
TypeBounds ::= [‘>:’ TypeBound] [‘<:’ TypeBound] TypeBoundsTree(lo, hi)

0 commit comments

Comments
 (0)