Skip to content

Commit 5f06f74

Browse files
committed
Add opaque types: parsing & pickling
Add `opaque` to syntax. Let it be parsed and stored/pickled as a flag.
1 parent 8d07271 commit 5f06f74

File tree

8 files changed

+22
-8
lines changed

8 files changed

+22
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
124124

125125
case class Sealed() extends Mod(Flags.Sealed)
126126

127+
case class Opaque() extends Mod(Flags.Opaque)
128+
127129
case class Override() extends Mod(Flags.Override)
128130

129131
case class Abstract() extends Mod(Flags.Abstract)

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,12 @@ object Flags {
251251

252252
final val AccessorOrSealed = Accessor.toCommonFlags
253253

254-
/** A mutable var */
254+
/** A mutable var */
255255
final val Mutable = termFlag(12, "mutable")
256256

257+
/** An opqaue type */
258+
final val Opaque = typeFlag(12, "opaque")
259+
257260
/** Symbol is local to current class (i.e. private[this] or protected[this]
258261
* pre: Private or Protected are also set
259262
*/
@@ -264,7 +267,7 @@ object Flags {
264267
*/
265268
final val ParamAccessor = termFlag(14, "<paramaccessor>")
266269

267-
/** A value or class implementing a module */
270+
/** A value or class implementing a module */
268271
final val Module = commonFlag(15, "module")
269272
final val ModuleVal = Module.toTermFlags
270273
final val ModuleClass = Module.toTypeFlags
@@ -441,12 +444,12 @@ object Flags {
441444
/** Flags representing source modifiers */
442445
final val SourceModifierFlags =
443446
commonFlags(Private, Protected, Abstract, Final, Inline,
444-
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Unused)
447+
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Unused, Opaque)
445448

446449
/** Flags representing modifiers that can appear in trees */
447450
final val ModifierFlags =
448-
SourceModifierFlags | Module | Param | Synthetic | Package | Local |
449-
commonFlags(Mutable)
451+
SourceModifierFlags | Module | Param | Synthetic | Package | Local
452+
// | Mutable is subsumed by commonFlags(Opaque) from SourceModifierFlags
450453
// | Trait is subsumed by commonFlags(Lazy) from SourceModifierFlags
451454

452455
assert(ModifierFlags.isTermFlags && ModifierFlags.isTypeFlags)

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Standard-Section: "ASTs" TopLevelStat*
183183
OVERRIDE
184184
INLINE // inline method
185185
MACRO // inline method containing toplevel splices
186+
OPAQUE // opaque type
186187
STATIC // mapped to static Java member
187188
OBJECT // an object or its class
188189
TRAIT // a trait
@@ -299,6 +300,7 @@ object TastyFormat {
299300
final val DEFAULTparameterized = 30
300301
final val STABLE = 31
301302
final val MACRO = 32
303+
final val OPAQUE = 33
302304

303305
// Cat. 2: tag Nat
304306

@@ -410,7 +412,7 @@ object TastyFormat {
410412

411413
/** Useful for debugging */
412414
def isLegalTag(tag: Int) =
413-
firstSimpleTreeTag <= tag && tag <= MACRO ||
415+
firstSimpleTreeTag <= tag && tag <= OPAQUE ||
414416
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
415417
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
416418
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -432,6 +434,7 @@ object TastyFormat {
432434
| OVERRIDE
433435
| INLINE
434436
| MACRO
437+
| OPAQUE
435438
| STATIC
436439
| OBJECT
437440
| TRAIT
@@ -486,6 +489,7 @@ object TastyFormat {
486489
case OVERRIDE => "OVERRIDE"
487490
case INLINE => "INLINE"
488491
case MACRO => "MACRO"
492+
case OPAQUE => "OPAQUE"
489493
case STATIC => "STATIC"
490494
case OBJECT => "OBJECT"
491495
case TRAIT => "TRAIT"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ class TreePickler(pickler: TastyPickler) {
603603
if (flags is Trait) writeByte(TRAIT)
604604
if (flags is Covariant) writeByte(COVARIANT)
605605
if (flags is Contravariant) writeByte(CONTRAVARIANT)
606+
if (flags is Opaque) writeByte(OPAQUE)
606607
}
607608
sym.annotations.foreach(pickleAnnotation(sym, _))
608609
}

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ class TreeUnpickler(reader: TastyReader,
562562
case OVERRIDE => addFlag(Override)
563563
case INLINE => addFlag(Inline)
564564
case MACRO => addFlag(Macro)
565+
case OPAQUE => addFlag(Opaque)
565566
case STATIC => addFlag(JavaStatic)
566567
case OBJECT => addFlag(Module)
567568
case TRAIT => addFlag(Trait)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ object Parsers {
16421642
case PRIVATE => Mod.Private()
16431643
case PROTECTED => Mod.Protected()
16441644
case SEALED => Mod.Sealed()
1645+
case OPAQUE => Mod.Opaque()
16451646
}
16461647

16471648
/** Drop `private' modifier when followed by a qualifier.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ object Tokens extends TokensCommon {
178178
final val INLINE = 62; enter(INLINE, "inline")
179179
final val ENUM = 63; enter(ENUM, "enum")
180180
final val UNUSED = 64; enter(UNUSED, "unused")
181+
final val OPAQUE = 65; enter(OPAQUE, "opaque")
181182

182183
/** special symbols */
183184
final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line")
@@ -198,7 +199,7 @@ object Tokens extends TokensCommon {
198199
/** XML mode */
199200
final val XMLSTART = 96; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate
200201

201-
final val alphaKeywords = tokenRange(IF, UNUSED)
202+
final val alphaKeywords = tokenRange(IF, OPAQUE)
202203
final val symbolicKeywords = tokenRange(USCORE, VIEWBOUND)
203204
final val symbolicTokens = tokenRange(COMMA, VIEWBOUND)
204205
final val keywords = alphaKeywords | symbolicKeywords
@@ -226,7 +227,7 @@ object Tokens extends TokensCommon {
226227
final val defIntroTokens = templateIntroTokens | dclIntroTokens
227228

228229
final val localModifierTokens = BitSet(
229-
ABSTRACT, FINAL, SEALED, IMPLICIT, INLINE, LAZY, UNUSED)
230+
ABSTRACT, FINAL, SEALED, IMPLICIT, INLINE, LAZY, UNUSED, OPAQUE)
230231

231232
final val accessModifierTokens = BitSet(
232233
PRIVATE, PROTECTED)

docs/docs/internals/syntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ LocalModifier ::= ‘abstract’
286286
| ‘sealed’
287287
| ‘implicit’
288288
| ‘lazy’
289+
| ‘opaque’
289290
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
290291
AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
291292

0 commit comments

Comments
 (0)