File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ class Compiler {
91
91
new ExplicitSelf , // Make references to non-trivial self types explicit as casts
92
92
new StringInterpolatorOpt , // Optimizes raw and s and f string interpolators by rewriting them to string concatenations or formats
93
93
new DropBreaks ) :: // Optimize local Break throws by rewriting them
94
- List (new PruneErasedDefs , // Drop erased definitions from scopes and simplify erased expressions
94
+ List (new PruneInlineTraits ,
95
+ new PruneErasedDefs , // Drop erased definitions from scopes and simplify erased expressions
95
96
new UninitializedDefs , // Replaces `compiletime.uninitialized` by `_`
96
97
new InlinePatterns , // Remove placeholders of inlined patterns
97
98
new VCInlineMethods , // Inlines calls to value class methods
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import core ._
5
+ import Contexts ._
6
+ import DenotTransformers .SymTransformer
7
+ import Flags ._
8
+ import SymDenotations ._
9
+ import Symbols ._
10
+ import MegaPhase .MiniPhase
11
+ import ast .tpd
12
+
13
+ class PruneInlineTraits extends MiniPhase with SymTransformer { thisTransform =>
14
+ import tpd ._
15
+ import PruneInlineTraits ._
16
+
17
+ override def phaseName : String = PruneInlineTraits .name
18
+
19
+ override def description : String = PruneInlineTraits .description
20
+
21
+ override def transformSym (sym : SymDenotation )(using Context ): SymDenotation =
22
+ if isEraseable(sym) then sym.copySymDenotation(initFlags = sym.flags | Deferred )
23
+ else sym
24
+
25
+ override def transformValDef (tree : ValDef )(using Context ): ValDef =
26
+ if isEraseable(tree.symbol) then cpy.ValDef (tree)(rhs = EmptyTree )
27
+ else tree
28
+
29
+ override def transformDefDef (tree : DefDef )(using Context ): DefDef =
30
+ if isEraseable(tree.symbol) then cpy.DefDef (tree)(rhs = EmptyTree )
31
+ else tree
32
+
33
+ private def isEraseable (sym : SymDenotation )(using Context ): Boolean =
34
+ sym.owner.isInlineTrait
35
+ && ! sym.isConstructor
36
+ && ! sym.is(Param )
37
+ && ! sym.is(ParamAccessor )
38
+ && ! sym.is(Private )
39
+ && ! sym.isLocalDummy
40
+ && ! sym.isType
41
+ }
42
+
43
+ object PruneInlineTraits {
44
+ import tpd ._
45
+
46
+ val name : String = " pruneInlineTraits"
47
+ val description : String = " drop rhs definitions in inline traits"
48
+ }
You can’t perform that action at this time.
0 commit comments