Skip to content

Commit a8f3dc1

Browse files
authored
Merge pull request #49 from noti0na1/dotty-explicit-nulls-notNull
Add predicate to check out of order for mutable variables
2 parents 3bb1b82 + d26b424 commit a8f3dc1

File tree

215 files changed

+1883
-725
lines changed

Some content is hidden

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

215 files changed

+1883
-725
lines changed

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ println("hello, world")
1515

1616

1717
## expectation
18-
19-

.github/ISSUE_TEMPLATE/crash.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: "\U0001F4A5 Crash report"
33
about: Report a Dotty Compiler compiler crash
44
title: ''
5-
labels: itype:bug
5+
labels: itype:bug, itype:crash
66
assignees: ''
77

88
---

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
name: "\U0001F389 Suggest a feature"
33
about: Please create a feature request here https://github.com/lampepfl/dotty-feature-requests
44
title: ''
5-
labels:
5+
labels: ''
66
assignees: ''
77

88
---
99

1010
Please create a feature request here: [lampepfl/dotty-feature-requests](https://github.com/lampepfl/dotty-feature-requests).
11-
12-
13-
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
---
2-
name: "Syntax highlighting"
2+
name: Syntax highlighting
33
about: Please create a syntax highlighting issue here https://github.com/scala/vscode-scala-syntax/issues
44
title: ''
5-
labels:
5+
labels: ''
66
assignees: ''
77

88
---
99

1010
Please create a syntax highlighting issue here: [scala/vscode-scala-syntax](https://github.com/scala/vscode-scala-syntax/issues).
11-
12-
13-

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,23 +1224,20 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
12241224
}
12251225

12261226
/* Emit code to compare the two top-most stack values using the 'op' operator. */
1227-
private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType, targetIfNoJump: asm.Label): Unit = {
1228-
if (targetIfNoJump == success) genCJUMP(failure, success, op.negate(), tk, targetIfNoJump)
1227+
private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType, targetIfNoJump: asm.Label, negated: Boolean = false): Unit = {
1228+
if (targetIfNoJump == success) genCJUMP(failure, success, op.negate(), tk, targetIfNoJump, negated = !negated)
12291229
else {
12301230
if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
12311231
bc.emitIF_ICMP(op, success)
12321232
} else if (tk.isRef) { // REFERENCE(_) | ARRAY(_)
12331233
bc.emitIF_ACMP(op, success)
12341234
} else {
12351235
import Primitives._
1236+
def useCmpG = if (negated) op == GT || op == GE else op == LT || op == LE
12361237
(tk: @unchecked) match {
12371238
case LONG => emit(asm.Opcodes.LCMP)
1238-
case FLOAT =>
1239-
if (op == LT || op == LE) emit(asm.Opcodes.FCMPL)
1240-
else emit(asm.Opcodes.FCMPG)
1241-
case DOUBLE =>
1242-
if (op == LT || op == LE) emit(asm.Opcodes.DCMPL)
1243-
else emit(asm.Opcodes.DCMPG)
1239+
case FLOAT => emit(if (useCmpG) asm.Opcodes.FCMPG else asm.Opcodes.FCMPL)
1240+
case DOUBLE => emit(if (useCmpG) asm.Opcodes.DCMPG else asm.Opcodes.DCMPL)
12441241
}
12451242
bc.emitIF(op, success)
12461243
}
@@ -1249,9 +1246,9 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
12491246
}
12501247

12511248
/* Emits code to compare (and consume) stack-top and zero using the 'op' operator */
1252-
private def genCZJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType, targetIfNoJump: asm.Label): Unit = {
1249+
private def genCZJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType, targetIfNoJump: asm.Label, negated: Boolean = false): Unit = {
12531250
import Primitives._
1254-
if (targetIfNoJump == success) genCZJUMP(failure, success, op.negate(), tk, targetIfNoJump)
1251+
if (targetIfNoJump == success) genCZJUMP(failure, success, op.negate(), tk, targetIfNoJump, negated = !negated)
12551252
else {
12561253
if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
12571254
bc.emitIF(op, success)
@@ -1261,18 +1258,17 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
12611258
case NE => bc emitIFNONNULL success
12621259
}
12631260
} else {
1261+
def useCmpG = if (negated) op == GT || op == GE else op == LT || op == LE
12641262
(tk: @unchecked) match {
12651263
case LONG =>
12661264
emit(asm.Opcodes.LCONST_0)
12671265
emit(asm.Opcodes.LCMP)
12681266
case FLOAT =>
12691267
emit(asm.Opcodes.FCONST_0)
1270-
if (op == LT || op == LE) emit(asm.Opcodes.FCMPL)
1271-
else emit(asm.Opcodes.FCMPG)
1268+
emit(if (useCmpG) asm.Opcodes.FCMPG else asm.Opcodes.FCMPL)
12721269
case DOUBLE =>
12731270
emit(asm.Opcodes.DCONST_0)
1274-
if (op == LT || op == LE) emit(asm.Opcodes.DCMPL)
1275-
else emit(asm.Opcodes.DCMPG)
1271+
emit(if (useCmpG) asm.Opcodes.DCMPG else asm.Opcodes.DCMPL)
12761272
}
12771273
bc.emitIF(op, success)
12781274
}
@@ -1287,8 +1283,8 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
12871283
case ScalaPrimitivesOps.NE => Primitives.NE
12881284
case ScalaPrimitivesOps.LT => Primitives.LT
12891285
case ScalaPrimitivesOps.LE => Primitives.LE
1290-
case ScalaPrimitivesOps.GE => Primitives.GE
12911286
case ScalaPrimitivesOps.GT => Primitives.GT
1287+
case ScalaPrimitivesOps.GE => Primitives.GE
12921288
}
12931289

12941290
/*

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
7676

7777
override def getCurrentCUnit(): CompilationUnit = { cunit }
7878

79-
/* ---------------- helper utils for generating classes and fiels ---------------- */
79+
/* ---------------- helper utils for generating classes and fields ---------------- */
8080

8181
def genPlainClass(cd: ClassDef) = cd match {
8282
case ClassDef(_, _, _, impl) =>

compiler/src/dotty/tools/backend/jvm/BCodeSyncAndTry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
310310
* ------
311311
*/
312312

313-
// a note on terminology: this is not "postHandlers", despite appearences.
313+
// a note on terminology: this is not "postHandlers", despite appearances.
314314
// "postHandlers" as in the source-code view. And from that perspective, both (3.A) and (3.B) are invisible implementation artifacts.
315315
if (hasFinally) withFreshCleanupScope {
316316
nopIfNeeded(startTryBody)

compiler/src/dotty/tools/backend/jvm/BTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ abstract class BTypes {
362362
*
363363
* - Initializer block (JLS 8.6 / 8.7): block of statements in a java class
364364
* - static initializer: executed before constructor body
365-
* - instance initializer: exectued when class is initialized (instance creation, static
365+
* - instance initializer: executed when class is initialized (instance creation, static
366366
* field access, ...)
367367
*
368368
* - A static nested class can be defined as

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ object CompilationUnit {
8383
unit1
8484
}
8585

86-
def apply(source: SourceFile)(implicit ctx: Context): CompilationUnit = {
86+
/** Create a compilation unit corresponding to `source`.
87+
* If `mustExist` is true, this will fail if `source` does not exist.
88+
*/
89+
def apply(source: SourceFile, mustExist: Boolean = true)(implicit ctx: Context): CompilationUnit = {
8790
val src =
88-
if (source.file.isDirectory) {
91+
if (!mustExist)
92+
source
93+
else if (source.file.isDirectory) {
8994
ctx.error(s"expected file, received directory '${source.file.path}'")
9095
NoSource
9196
}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,26 @@ object desugar {
804804
flatTree(cdef1 :: companions ::: implicitWrappers)
805805
}.reporting(i"desugared: $result", Printers.desugar)
806806

807+
/** Expand
808+
*
809+
* package object name { body }
810+
*
811+
* to:
812+
*
813+
* package name {
814+
* object `package` { body }
815+
* }
816+
*/
817+
def packageModuleDef(mdef: ModuleDef)(implicit ctx: Context): Tree =
818+
val impl = mdef.impl
819+
val mods = mdef.mods
820+
val moduleName = normalizeName(mdef, impl).asTermName
821+
if (mods.is(Package))
822+
PackageDef(Ident(moduleName),
823+
cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
824+
else
825+
mdef
826+
807827
/** Expand
808828
*
809829
* object name extends parents { self => body }
@@ -854,7 +874,7 @@ object desugar {
854874
ctx.warning(em"${hl("final")} modifier is redundant for objects", flagSourcePos(Final))
855875

856876
if (mods.is(Package))
857-
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
877+
packageModuleDef(mdef)
858878
else if (isEnumCase) {
859879
typeParamIsReferenced(enumClass.typeParams, Nil, Nil, impl.parents)
860880
// used to check there are no illegal references to enum's type parameters in parents
@@ -1229,12 +1249,6 @@ object desugar {
12291249
case _ =>
12301250
false
12311251

1232-
/** Does this package contains at least one top-level definition
1233-
* that will require a wrapping object ?
1234-
*/
1235-
def hasTopLevelDef(pdef: PackageDef)(given Context): Boolean =
1236-
pdef.stats.exists(isTopLevelDef)
1237-
12381252
/** Assuming `src` contains top-level definition, returns the name that should
12391253
* be using for the package object that will wrap them.
12401254
*/
@@ -1758,7 +1772,7 @@ object desugar {
17581772
case Block(Nil, expr) =>
17591773
collect(expr)
17601774
case Quote(expr) =>
1761-
new TreeTraverser {
1775+
new UntypedTreeTraverser {
17621776
def traverse(tree: untpd.Tree)(implicit ctx: Context): Unit = tree match {
17631777
case Splice(expr) => collect(expr)
17641778
case TypSplice(expr) =>

0 commit comments

Comments
 (0)