8000 Rename NoType to VoidType and print it as "void". · scala-js/scala-js@cdcff99 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdcff99

Browse files
committed
Rename NoType to VoidType and print it as "void".
Also clarify that it is the real top type of our type system. We have been using `void` in the "theoretical" type system since Scala.js 1.0.0, but for historical reasons, `NoType` kept its old name. We now officially rename it to `VoidType`, and print it as `void` instead of `<notype>`, giving it a true `Type` status.
1 parent ec93673 commit cdcff99

39 files changed

+258
-253
lines changed

compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
14141414
js.MethodIdent(name),
14151415
NoOriginalName,
14161416
Nil,
1417-
jstpe.NoType,
1417+
jstpe.VoidType,
14181418
Some(stats))(
14191419
OptimizerHints.empty, Unversioned)
14201420
}
@@ -1842,7 +1842,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
18421842
}
18431843
}
18441844

1845-
js.If(cond, body, js.Skip())(jstpe.NoType)
1845+
js.If(cond, body, js.Skip())(jstpe.VoidType)
18461846
}
18471847

18481848
/* preStats / postStats use pre/post order traversal respectively to
@@ -2080,7 +2080,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
20802080
val namespace = js.MemberNamespace.Constructor
20812081
js.MethodDef(
20822082
js.MemberFlags.empty.withNamespace(namespace), methodName,
2083-
originalName, jsParams, jstpe.NoType, Some(genStat(dd.rhs)))(
2083+
originalName, jsParams, jstpe.VoidType, Some(genStat(dd.rhs)))(
20842084
optimizerHints, Unversioned)
20852085
} else {
20862086
val resultIRType = toIRType(sym.tpe.resultType)
@@ -2180,7 +2180,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
21802180
}
21812181
}
21822182
val newBody = body.map(
2183-
b => transformer.transform(b, isStat = resultType == jstpe.NoType))
2183+
b => transformer.transform(b, isStat = resultType == jstpe.VoidType))
21842184
js.MethodDef(flags, methodName, originalName, newParams, resultType,
21852185
newBody)(methodDef.optimizerHints, Unversioned)(methodDef.pos)
21862186
}
@@ -2216,7 +2216,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
22162216
}
22172217
}
22182218
val newBody = body.map(
2219-
b => transformer.transform(b, isStat = resultType == jstpe.NoType))
2219+
b => transformer.transform(b, isStat = resultType == jstpe.VoidType))
22202220
js.MethodDef(flags, methodName, originalName, newParams, resultType,
22212221
newBody)(methodDef.optimizerHints, Unversioned)(methodDef.pos)
22222222
}
@@ -2248,7 +2248,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
22482248
optimizerHints: OptimizerHints): js.MethodDef = {
22492249
implicit val pos = tree.pos
22502250

2251-
val bodyIsStat = resultIRType == jstpe.NoType
2251+
val bodyIsStat = resultIRType == jstpe.VoidType
22522252

22532253
def genBodyWithinReturnableScope(): js.Tree = tree match {
22542254
case Block(
@@ -2439,8 +2439,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
24392439
*/
24402440
def genExpr(tree: Tree): js.Tree = {
24412441
val result = genStatOrExpr(tree, isStat = false)
2442-
assert(result.tpe != jstpe.NoType,
2443-
s"genExpr($tree) returned a tree with type NoType at pos ${tree.pos}")
2442+
assert(result.tpe != jstpe.VoidType,
2443+
s"genExpr($tree) returned a tree with type VoidType at pos ${tree.pos}")
24442444
result
24452445
}
24462446

@@ -2517,7 +2517,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
25172517
case tree @ If(cond, thenp, elsep) =>
25182518
def default: js.Tree = {
25192519
val tpe =
2520-
if (isStat) jstpe.NoType
2520+
if (isStat) jstpe.VoidType
25212521
else toIRType(tree.tpe)
25222522

25232523
js.If(genExpr(cond), genStatOrExpr(thenp, isStat),
@@ -2559,8 +2559,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
25592559

25602560
case Return(expr) =>
25612561
js.Return(toIRType(expr.tpe) match {
2562-
case jstpe.NoType => js.Block(genStat(expr), js.Undefined())
2563-
case _ => genExpr(expr)
2562+
case jstpe.VoidType => js.Block(genStat(expr), js.Undefined())
2563+
case _ => genExpr(expr)
25642564
}, getEnclosingReturnLabel())
25652565

25662566
case t: Try =>
@@ -2916,7 +2916,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
29162916
if (transformedRhs.tpe == jstpe.NothingType) {
29172917
// In this case, we do not need the outer block label
29182918
js.While(js.BooleanLiteral(true), {
2919-
js.Labeled(labelIdent, jstpe.NoType, {
2919+
js.Labeled(labelIdent, jstpe.VoidType, {
29202920
transformedRhs match {
29212921
// Eliminate a trailing return@lab
29222922
case js.Block(stats :+ ReturnFromThisLabel(exprAsStat)) =>
@@ -2930,11 +2930,11 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
29302930
// When all else has failed, we need the full machinery
29312931
val blockLabelIdent = freshLabelIdent("block")
29322932
val bodyType =
2933-
if (isStat) jstpe.NoType
2933+
if (isStat) jstpe.VoidType
29342934
else toIRType(tree.tpe)
29352935
js.Labeled(blockLabelIdent, bodyType, {
29362936
js.While(js.BooleanLiteral(true), {
2937-
js.Labeled(labelIdent, jstpe.NoType, {
2937+
js.Labeled(labelIdent, jstpe.VoidType, {
29382938
if (isStat)
29392939
js.Block(transformedRhs, js.Return(js.Undefined(), blockLabelIdent))
29402940
else
@@ -3050,7 +3050,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
30503050
val blockAST = genStatOrExpr(block, isStat)
30513051

30523052
val resultType =
3053-
if (isStat) jstpe.NoType
3053+
if (isStat) jstpe.VoidType
30543054
else toIRType(tree.tpe)
30553055

30563056
val handled =
@@ -3282,7 +3282,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
32823282
val r = toIRType(to)
32833283

32843284
def isValueType(tpe: jstpe.Type): Boolean = tpe match {
3285-
case jstpe.NoType | jstpe.BooleanType | jstpe.CharType |
3285+
case jstpe.VoidType | jstpe.BooleanType | jstpe.CharType |
32863286
jstpe.ByteType | jstpe.ShortType | jstpe.IntType | jstpe.LongType |
32873287
jstpe.FloatType | jstpe.DoubleType =>
32883288
true
@@ -3625,7 +3625,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
36253625
.withNoinline(noinline)
36263626
val methodIdent = encodeMethodSym(method)
36273627
val resultType =
3628-
if (method.isClassConstructor) jstpe.NoType
3628+
if (method.isClassConstructor) jstpe.VoidType
36293629
else toIRType(method.tpe.resultType)
36303630
js.ApplyStatically(flags, receiver, encodeClassName(method.owner),
36313631
methodIdent, arguments)(resultType)
@@ -3891,7 +3891,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
38913891
val genSelector = genExpr(selector)
38923892

38933893
val resultType =
3894-
if (isStat) jstpe.NoType
3894+
if (isStat) jstpe.VoidType
38953895
else toIRType(tree.tpe)
38963896

38973897
val defaultLabelSym = cases.collectFirst {
@@ -4035,8 +4035,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
40354035
(alts, newBody)
40364036
}
40374037
js.Labeled(matchResultLabel, resultType, js.Block(List(
4038-
js.Labeled(elseClauseLabel, jstpe.NoType, {
4039-
buildMatch(patchedClauses.reverse, js.Skip(), jstpe.NoType)
4038+
js.Labeled(elseClauseLabel, jstpe.VoidType, {
4039+
buildMatch(patchedClauses.reverse, js.Skip(), jstpe.VoidType)
40404040
}),
40414041
elseClause
40424042
)))
@@ -4133,7 +4133,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
41334133
val translatedMatch = genTranslatedMatch(cases, matchEnd)
41344134
val genMore = genBlockWithCaseLabelDefs(more, isStat)
41354135
val label = getEnclosingReturnLabel()
4136-
if (translatedMatch.tpe == jstpe.NoType) {
4136+
if (translatedMatch.tpe == jstpe.VoidType) {
41374137
// Could not actually reproduce this, but better be safe than sorry
41384138
translatedMatch :: js.Return(js.Undefined(), label) :: genMore
41394139
} else {
@@ -4217,7 +4217,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
42174217
tree match {
42184218
case If(cond, thenp, elsep) =>
42194219
js.If(genExpr(cond), genCaseBody(thenp), genCaseBody(elsep))(
4220-
jstpe.NoType)
4220+
jstpe.VoidType)
42214221

42224222
case Block(stats, Literal(Constant(()))) =>
42234223
// Generated a lot by the async transform
@@ -4272,7 +4272,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
42724272

42734273
def genMatchEndBody(): js.Tree = {
42744274
genStatOrExpr(matchEndBody,
4275-
isStat = toIRType(matchEndBody.tpe) == jstpe.NoType)
4275+
isStat = toIRType(matchEndBody.tpe) == jstpe.VoidType)
42764276
}
42774277

42784278
matchEnd.params match {
@@ -4326,7 +4326,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
43264326
) {
43274327
genTranslatedCases
43284328
}
4329-
val optimized = genOptimizedMatchEndLabeled(labelIdent, jstpe.NoType,
4329+
val optimized = genOptimizedMatchEndLabeled(labelIdent, jstpe.VoidType,
43304330
translatedCases, info.generatedReturns)
43314331
js.Block(varDefs ::: optimized :: genMatchEndBody() :: Nil)
43324332
}
@@ -4379,7 +4379,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
43794379
implicit pos: Position): js.Tree = {
43804380

43814381
def default: js.Tree =
4382-
js.Labeled(label, jstpe.NoType, translatedBody)
4382+
js.Labeled(label, jstpe.VoidType, translatedBody)
43834383

43844384
if (returnCount == 0) {
43854385
translatedBody
@@ -4403,7 +4403,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
44034403
case _ =>
44044404
js.UnaryOp(js.UnaryOp.Boolean_!, cond)
44054405
}
4406-
js.Block(stats1 :+ js.If(notCond, js.Block(stats2), js.Skip())(jstpe.NoType))
4406+
js.Block(stats1 :+ js.If(notCond, js.Block(stats2), js.Skip())(jstpe.VoidType))
44074407

44084408
case _ :: _ =>
44094409
throw new AssertionError("unreachable code")
@@ -5219,7 +5219,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
52195219
def makePrimitiveBox(expr: js.Tree, tpe: Type)(
52205220
implicit pos: Position): js.Tree = {
52215221
toIRType(tpe) match {
5222-
case jstpe.NoType => // for JS interop cases
5222+
case jstpe.VoidType => // for JS interop cases
52235223
js.Block(expr, js.Undefined())
52245224
case jstpe.BooleanType | jstpe.CharType | jstpe.ByteType |
52255225
jstpe.ShortType | jstpe.IntType | jstpe.LongType | jstpe.FloatType |
@@ -5234,8 +5234,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
52345234
def makePrimitiveUnbox(expr: js.Tree, tpe: Type)(
52355235
implicit pos: Position): js.Tree = {
52365236
toIRType(tpe) match {
5237-
case jstpe.NoType => expr // for JS interop cases
5238-
case irTpe => js.AsInstanceOf(expr, irTpe)
5237+
case jstpe.VoidType => expr // for JS interop cases
5238+
case irTpe => js.AsInstanceOf(expr, irTpe)
52395239
}
52405240
}
52415241

@@ -6135,8 +6135,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
61356135
*
61366136
* we generate a function:
61376137
*
6138-
* lambda<o, c1, ..., cM>[notype](
6139-
* outer, capture1, ..., captureM, param1, ..., paramN) {
6138+
* arrow-lambda<o = outer, c1 = capture1, ..., cM = captureM>(param1, ..., paramN) {
61406139
* <body>
61416140
* }
61426141
*
@@ -6206,8 +6205,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
62066205
*
62076206
* we generate a function:
62086207
*
6209-
* lambda<o, c1, ..., cM>[notype](
6210-
* outer, capture1, ..., captureM, param1, ..., paramN) {
6208+
* arrow-lambda<o = outer, c1 = capture1, ..., cM = captureM>(param1, ..., paramN) {
62116209
* outer.lambdaImpl(param1, ..., paramN, capture1, ..., captureM)
62126210
* }
62136211
*/
@@ -6540,7 +6538,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
65406538
js.MethodIdent(ObjectArgConstructorName),
65416539
NoOriginalName,
65426540
List(fParamDef),
6543-
jstpe.NoType,
6541+
jstpe.VoidType,
65446542
Some(js.Block(List(
65456543
js.Assign(
65466544
js.Select(js.This()(thisType), fFieldIdent)(jstpe.AnyType),
@@ -6549,7 +6547,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
65496547
js.This()(thisType),
65506548
ir.Names.ObjectClass,
65516549
js.MethodIdent(ir.Names.NoArgConstructorName),
6552-
Nil)(jstpe.NoType)))))(
6550+
Nil)(jstpe.VoidType)))))(
65536551
js.OptimizerHints.empty, Unversioned)
65546552
}
65556553

compiler/src/main/scala/org/scalajs/nscplugin/GenJSExports.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ trait GenJSExports[G <: Global with Singleton] extends SubComponent {
870870
}
871871

872872
// #4684 If the getter returns void, we must "box" it by returning undefined
873-
if (callGetter.tpe == jstpe.NoType)
873+
if (callGetter.tpe == jstpe.VoidType)
874874
js.Block(callGetter, js.Undefined())
875875
else
876876
callGetter
@@ -975,7 +975,7 @@ trait GenJSExports[G <: Global with Singleton] extends SubComponent {
975975
(toIRType(tpe): @unchecked) match {
976976
case jstpe.AnyType | jstpe.AnyNotNullType => NoTypeTest
977977

978-
case jstpe.NoType => PrimitiveTypeTest(jstpe.UndefType, 0)
978+
case jstpe.VoidType => PrimitiveTypeTest(jstpe.UndefType, 0)
979979
case jstpe.BooleanType => PrimitiveTypeTest(jstpe.BooleanType, 1)
980980
case jstpe.CharType => PrimitiveTypeTest(jstpe.CharType, 2)
981981
case jstpe.ByteType => PrimitiveTypeTest(jstpe.ByteType, 3)

compiler/src/main/scala/org/scalajs/nscplugin/TypeConversions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait TypeConversions[G <: Global with Singleton] extends SubComponent {
2525

2626
private lazy val primitiveIRTypeMap: Map[Symbol, Types.Type] = {
2727
Map(
28-
UnitClass -> Types.NoType,
28+
UnitClass -> Types.VoidType,
2929
BooleanClass -> Types.BooleanType,
3030
CharClass -> Types.CharType,
3131
ByteClass -> Types.ByteType,

ir/shared/src/main/scala/org/scalajs/ir/Hashers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ object Hashers {
581581
def mixTypeRef(typeRef: TypeRef): Unit = typeRef match {
582582
case PrimRef(tpe) =>
583583
tpe match {
584-
case NoType => mixTag(TagVoidRef)
584+
case VoidType => mixTag(TagVoidRef)
585585
case BooleanType => mixTag(TagBooleanRef)
586586
case CharType => mixTag(TagCharRef)
587587
case ByteType => mixTag(TagByteRef)
@@ -621,7 +621,7 @@ object Hashers {
621621
case DoubleType => mixTag(TagDoubleType)
622622
case StringType => mixTag(TagStringType)
623623
case NullType => mixTag(TagNullType)
624-
case NoType => mixTag(TagNoType)
624+
case VoidType => mixTag(TagVoidType)
625625

626626
case ClassType(className, nullable) =>
627627
mixTag(if (nullable) TagClassType else TagNonNullClassType)

ir/shared/src/main/scala/org/scalajs/ir/Names.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ object Names {
393393
def appendTypeRef(typeRef: TypeRef): Unit = typeRef match {
394394
case PrimRef(tpe) =>
395395
tpe match {
396-
case NoType => builder.append('V')
396+
case VoidType => builder.append('V')
397397
case BooleanType => builder.append('Z')
398398
case CharType => builder.append('C')
399399
case ByteType => builder.append('B')

ir/shared/src/main/scala/org/scalajs/ir/Printers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object Printers {
106106

107107
print(")")
108108

109-
if (resultType != NoType) {
109+
if (resultType != VoidType) {
110110
print(": ")
111111
print(resultType)
112112
print(" = ")
@@ -173,7 +173,7 @@ object Printers {
173173

174174
case Labeled(label, tpe, body) =>
175175
print(label)
176-
if (tpe != NoType) {
176+
if (tpe != VoidType) {
177177
print('[')
178178
print(tpe)
179179
print(']')
@@ -1037,7 +1037,7 @@ object Printers {
10371037
print(flags.namespace.prefixString)
10381038
print("set ")
10391039
printJSMemberName(name)
1040-
printSig(arg :: Nil, None, NoType)
1040+
printSig(arg :: Nil, None, VoidType)
10411041
printBlock(body)
10421042
}
10431043

@@ -1104,7 +1104,7 @@ object Printers {
11041104
case DoubleType => print("double")
11051105
case StringType => print("string")
11061106
case NullType => print("null")
1107-
case NoType => print("<notype>")
1107+
case VoidType => print("void")
11081108

11091109
case ClassType(className, nullable) =>
11101110
print(className)

0 commit comments

Comments
 (0)
0