Skip to content

Commit 01595f7

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 2f32850 commit 01595f7

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
@@ -573,12 +573,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
573573
ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree)
574574
.withFlags(flags)
575575

576-
def isInto(t: Tree)(using Context): Boolean = t match
577-
case PrefixOp(Ident(tpnme.into), _) => true
578-
case Function(_, res) => isInto(res)
579-
case Parens(t) => isInto(t)
580-
case _ => false
581-
582576
def lambdaAbstract(params: List[ValDef] | List[TypeDef], tpt: Tree)(using Context): Tree =
583577
params match
584578
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
@@ -43,7 +43,6 @@ import CaptureSet.{CompareResult, IdentityCaptRefMap}
4343

4444
import scala.annotation.internal.sharable
4545
import scala.annotation.threadUnsafe
46-
import dotty.tools.dotc.cc.ccConfig
4746

4847
object Types extends TypeUtils {
4948

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
@@ -1590,8 +1587,8 @@ object Parsers {
15901587
/** Same as [[typ]], but if this results in a wildcard it emits a syntax error and
15911588
* returns a tree for type `Any` instead.
15921589
*/
1593-
def toplevelTyp(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
1594-
rejectWildcardType(typ(intoOK, inContextBound))
1590+
def toplevelTyp(inContextBound: Boolean = false): Tree =
1591+
rejectWildcardType(typ(inContextBound))
15951592

15961593
private def getFunction(tree: Tree): Option[Function] = tree match {
15971594
case Parens(tree1) => getFunction(tree1)
@@ -1656,21 +1653,12 @@ object Parsers {
16561653
* | `(' [ FunArgType {`,' FunArgType } ] `)'
16571654
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
16581655
* MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
1659-
* IntoType ::= [‘into’] IntoTargetType
1660-
* | ‘( IntoType ‘)’
1661-
* IntoTargetType ::= Type
1662-
* | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
16631656
*/
1664-
def typ(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
1657+
def typ(inContextBound: Boolean = false): Tree =
16651658
val start = in.offset
16661659
var imods = Modifiers()
16671660
val erasedArgs: ListBuffer[Boolean] = ListBuffer()
16681661

1669-
def nestedIntoOK(token: Int) =
1670-
if token == TLARROW then IntoOK.No
1671-
else if intoOK == IntoOK.Nested then IntoOK.Yes
1672-
else intoOK
1673-
16741662
def functionRest(params: List[Tree]): Tree =
16751663
val paramSpan = Span(start, in.lastOffset)
16761664
atSpan(start, in.offset) {
@@ -1699,9 +1687,8 @@ object Parsers {
16991687
else
17001688
accept(ARROW)
17011689

1702-
def resType() = typ(nestedIntoOK(token))
17031690
val resultType =
1704-
if isPure then capturesAndResult(resType) else resType()
1691+
if isPure then capturesAndResult(typ) else typ()
17051692
if token == TLARROW then
17061693
for case ValDef(_, tpt, _) <- params do
17071694
if isByNameType(tpt) then
@@ -1736,12 +1723,6 @@ object Parsers {
17361723
syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
17371724
t
17381725

1739-
def isIntoPrefix: Boolean =
1740-
intoOK == IntoOK.Yes
1741-
&& in.isIdent(nme.into)
1742-
&& in.featureEnabled(Feature.into)
1743-
&& canStartTypeTokens.contains(in.lookahead.token)
1744-
17451726
def convertToElem(t: Tree): Tree = t match
17461727
case ByNameTypeTree(t1) =>
17471728
syntaxError(ByNameParameterNotSupported(t), t.span)
@@ -1778,32 +1759,6 @@ object Parsers {
17781759
funArgType()
17791760
commaSeparatedRest(t, funArg)
17801761
accept(RPAREN)
1781-
1782-
val intoAllowed =
1783-
intoOK == IntoOK.Yes
1784-
&& args.lengthCompare(1) == 0
1785-
&& (!canFollowSimpleTypeTokens.contains(in.token) || followingIsVararg())
1786-
val byNameAllowed = in.isArrow || isPureArrow
1787-
1788-
def sanitize(arg: Tree): Tree = arg match
1789-
case ByNameTypeTree(t) if !byNameAllowed =>
1790-
syntaxError(ByNameParameterNotSupported(t), t.span)
1791-
t
1792-
case PrefixOp(id @ Ident(tpnme.into), t) if !intoAllowed =>
1793-
syntaxError(em"no `into` modifier allowed here", id.span)
1794-
t
1795-
case Parens(t) =>
1796-
cpy.Parens(arg)(sanitize(t))
1797-
case arg: FunctionWithMods =>
1798-
val body1 = sanitize(arg.body)
1799-
if body1 eq arg.body then arg
1800-
else FunctionWithMods(arg.args, body1, arg.mods, arg.erasedParams).withSpan(arg.span)
1801-
case Function(args, res) if !intoAllowed =>
1802-
cpy.Function(arg)(args, sanitize(res))
1803-
case arg =>
1804-
arg
1805-
val args1 = args.mapConserve(sanitize)
1806-
18071762
if in.isArrow || isPureArrow || erasedArgs.contains(true) then
18081763
functionRest(args)
18091764
else
@@ -1830,8 +1785,6 @@ object Parsers {
18301785
typ()
18311786
else if in.token == INDENT then
18321787
enclosed(INDENT, typ())
1833-
else if isIntoPrefix then
1834-
PrefixOp(typeIdent(), typ(IntoOK.Nested))
18351788
else
18361789
typeRest(infixType(inContextBound))
18371790
end typ
@@ -2218,9 +2171,7 @@ object Parsers {
22182171
* | `=>' Type
22192172
* | `->' [CaptureSet] Type
22202173
*/
2221-
val funArgType: () => Tree =
2222-
() => paramTypeOf(() => typ(IntoOK.Yes))
2223-
// We allow intoOK and filter out afterwards in typ()
2174+
val funArgType: () => Tree = () => paramTypeOf(typ)
22242175

22252176
/** ParamType ::= ParamValueType
22262177
* | `=>' ParamValueType
@@ -2229,11 +2180,9 @@ object Parsers {
22292180
def paramType(): Tree = paramTypeOf(paramValueType)
22302181

22312182
/** ParamValueType ::= Type [`*']
2232-
* | IntoType
2233-
* | ‘(’ IntoType ‘)’ `*'
22342183
*/
22352184
def paramValueType(): Tree =
2236-
val t = toplevelTyp(IntoOK.Yes)
2185+
val t = toplevelTyp()
22372186
if isIdent(nme.raw.STAR) then
22382187
if !t.isInstanceOf[Parens] && isInto(t) then
22392188
syntaxError(
@@ -3541,7 +3490,7 @@ object Parsers {
35413490
*/
35423491
def contextTypes(paramOwner: ParamOwner, numLeadParams: Int, impliedMods: Modifiers): List[ValDef] =
35433492
typesToParams(
3544-
commaSeparated(() => paramTypeOf(() => toplevelTyp())),
3493+
commaSeparated(() => paramTypeOf(toplevelTyp)),
35453494
paramOwner, numLeadParams, impliedMods)
35463495

35473496
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
@@ -326,9 +326,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
326326
case AnnotatedType(tpe, annot) =>
327327
if defn.SilentAnnots.contains(annot.symbol) && !printDebug then
328328
toText(tpe)
329-
else if (annot.symbol == defn.IntoAnnot || annot.symbol == defn.IntoParamAnnot)
329+
else if (annot.symbol == defn.IntoParamAnnot)
330330
&& !printDebug
331-
then atPrec(GlobalPrec)( Str("into ") ~ toText(tpe) )
331+
then atPrec(GlobalPrec):
332+
"into[" ~ toText(tpe) ~ "]"
332333
else if annot.isInstanceOf[CaptureAnnotation] then
333334
toTextLocal(tpe) ~ "^" ~ toText(annot)
334335
else

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
699699
&& Feature.ccEnabled && !printDebug
700700
&& Phases.checkCapturesPhase.exists // might be missing on -Ytest-pickler
701701
then toTextRetainsAnnot
702-
else if annot.symbol.enclosingClass == defn.IntoAnnot && !printDebug then
703-
atPrec(GlobalPrec):
704-
Str("into ") ~ toText(arg)
705702
else toTextAnnot
706703
case EmptyTree =>
707704
"<empty>"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26662666
&& checkedArgs(1).tpe.derivesFrom(defn.RuntimeExceptionClass)
26672667
then
26682668
report.error(em"throws clause cannot be defined for RuntimeException", checkedArgs(1).srcPos)
2669+
else if tycon == defn.IntoType then
2670+
// <into> is defined in package scala but this should be hidden from user programs
2671+
report.error(em"not found: <into>", tpt1.srcPos)
26692672
else if (ctx.isJava)
26702673
if tycon eq defn.ArrayClass then
26712674
checkedArgs match {

docs/_docs/internals/syntax.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ FunArgType ::= Type
213213
FunArgTypes ::= FunArgType { ‘,’ FunArgType }
214214
ParamType ::= [‘=>’] ParamValueType
215215
ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
216-
| IntoType
217-
| ‘(’ IntoType ‘)’ ‘*’ PostfixOp(t, "*")
218-
IntoType ::= [‘into’] IntoTargetType Into(t)
219-
| ‘(’ IntoType ‘)’
220-
IntoTargetType ::= Type
221-
| FunTypeArgs (‘=>’ | ‘?=>’) IntoType
222216
TypeArgs ::= ‘[’ Types ‘]’ ts
223217
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>> ds
224218
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)

0 commit comments

Comments
 (0)