File tree 6 files changed +55
-5
lines changed
compiler/src/dotty/tools/dotc
6 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,6 @@ object Mode {
147
147
*/
148
148
val RelaxedOverriding : Mode = newMode(30 , " RelaxedOverriding" )
149
149
150
- /** We are checking the original call of an Inlined node */
151
- val InlinedCall : Mode = newMode(31 , " InlinedCall " )
150
+ /** Skip inlining of methods. */
151
+ val NoInline : Mode = newMode(31 , " NoInline " )
152
152
}
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ object Inlines:
63
63
)
64
64
&& ! ctx.typer.hasInliningErrors
65
65
&& ! ctx.base.stopInlining
66
+ && ! ctx.mode.is(Mode .NoInline )
66
67
}
67
68
68
69
private def needsTransparentInlining (tree : Tree )(using Context ): Boolean =
Original file line number Diff line number Diff line change @@ -361,7 +361,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
361
361
case tree @ Inlined (call, bindings, expansion) if ! tree.inlinedFromOuterScope =>
362
362
val pos = call.sourcePos
363
363
CrossVersionChecks .checkExperimentalRef(call.symbol, pos)
364
- withMode(Mode .InlinedCall )(transform(call))
364
+ withMode(Mode .NoInline )(transform(call))
365
365
val callTrace = Inlines .inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
366
366
cpy.Inlined (tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(tree)))
367
367
case templ : Template =>
@@ -512,7 +512,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
512
512
if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs
513
513
514
514
private def registerNeedsInlining (tree : Tree )(using Context ): Unit =
515
- if tree.symbol.is(Inline ) && ! Inlines .inInlineMethod && ! ctx.mode.is(Mode .InlinedCall ) then
515
+ if tree.symbol.is(Inline ) && ! Inlines .inInlineMethod && ! ctx.mode.is(Mode .NoInline ) then
516
516
ctx.compilationUnit.needsInlining = true
517
517
518
518
/** Check if the definition has macro annotation and sets `compilationUnit.hasMacroAnnotations` if needed. */
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import dotty.tools.dotc.ast.tpd
7
7
import dotty .tools .dotc .ast .untpd
8
8
import dotty .tools .dotc .core .Constants .Constant
9
9
import dotty .tools .dotc .core .Contexts .*
10
+ import dotty .tools .dotc .core .Flags .*
11
+ import dotty .tools .dotc .core .Mode
10
12
import dotty .tools .dotc .core .Names .{Name , TermName }
11
13
import dotty .tools .dotc .core .StdNames .*
12
14
import dotty .tools .dotc .core .Types .*
@@ -17,6 +19,7 @@ import core.Symbols.*
17
19
import transform .ValueClasses
18
20
import ErrorReporting .*
19
21
import reporting .*
22
+ import inlines .Inlines
20
23
21
24
object Dynamic {
22
25
private def isDynamicMethod (name : Name ): Boolean =
@@ -209,7 +212,12 @@ trait Dynamic {
209
212
case _ => tree
210
213
case other => tree
211
214
case _ => tree
212
- addClassOfs(typed(scall))
215
+
216
+ // We type the application of `applyDynamic` without inlining (arguments are already typed and inlined),
217
+ // to be able to add the add the Class arguments before we inline the method.
218
+ val call = addClassOfs(withMode(Mode .NoInline )(typed(scall)))
219
+ if Inlines .needsInlining(call) then Inlines .inlineCall(call)
220
+ else call
213
221
}
214
222
215
223
def fail (reason : String ): Tree =
Original file line number Diff line number Diff line change
1
+ Normal
2
+ test
3
+ ArraySeq(class java.lang.String, int)
4
+ ArraySeq(test, 42)
5
+ Transparent
6
+ test
7
+ ArraySeq(class java.lang.String, int)
8
+ ArraySeq(test, 42)
Original file line number Diff line number Diff line change
1
+ class MyRecord extends Selectable :
2
+ def applyDynamic (name : String , paramClasses : Class [_]* )(args : Any * ): Any = {
3
+ println(name)
4
+ println(paramClasses)
5
+ println(args)
6
+ ()
7
+ }
8
+
9
+ class MyRecordTransparent extends Selectable :
10
+ inline transparent def applyDynamic (name : String , paramClasses : Class [_]* )(args : Any * ): Any = {
11
+ println(name)
12
+ println(paramClasses)
13
+ println(args)
14
+ ()
15
+ }
16
+
17
+ type Person = MyRecord {
18
+ def test (a : String , b : Int ): Unit
19
+ }
20
+
21
+
22
+ type PersonTransparent = MyRecordTransparent {
23
+ def test (a : String , b : Int ): Unit
24
+ }
25
+
26
+ val person = MyRecord ().asInstanceOf [Person ]
27
+ val personTransparent = MyRecordTransparent ().asInstanceOf [PersonTransparent ]
28
+
29
+ @ main def Test : Unit =
30
+ println(" Normal" )
31
+ person.test(" test" , 42 )
32
+ println(" Transparent" )
33
+ personTransparent.test(" test" , 42 )
You can’t perform that action at this time.
0 commit comments