Skip to content

Commit c706878

Browse files
committed
wip
1 parent 144215d commit c706878

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,6 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
15971597
&& level == 0
15981598
&& !hasInliningErrors =>
15991599
val expanded = expandMacro(res.args.head, tree.srcPos)
1600-
println(" ")
1601-
println(expanded)
1602-
println(expanded.show)
1603-
println(" ")
1604-
println(" ")
16051600
typedExpr(expanded) // Inline calls and constant fold code generated by the macro
16061601
case res =>
16071602
specializeEq(inlineIfNeeded(res))

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
228228
end ClassDefTypeTest
229229

230230
object ClassDef extends ClassDefModule:
231-
def apply(cls: Symbol, constr: DefDef, parents: List[Tree], body: List[Statement]): ClassDef =
231+
def apply(cls: Symbol, parents: List[Tree], body: List[Statement]): ClassDef =
232+
val constr = ctx.typeAssigner.assignType(untpd.DefDef(nme.CONSTRUCTOR, Nil, tpd.TypeTree(dotc.core.Symbols.defn.UnitClass.typeRef), untpd.EmptyTree), cls.primaryConstructor)
233+
println(constr.show)
234+
println(constr)
232235
tpd.ClassDefWithParents(cls.asClass, constr, parents, body)
233236

234237
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = {
@@ -2459,18 +2462,18 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
24592462
def requiredMethod(path: String): Symbol = dotc.core.Symbols.requiredMethod(path)
24602463
def classSymbol(fullName: String): Symbol = dotc.core.Symbols.requiredClass(fullName)
24612464

2462-
def newClass(owner: Symbol, name: String, flags: Flags, parents: List[TypeRepr], decls: List[Symbol], selfInfo: Option[TypeRepr], privateWithin: Symbol): Symbol =
2463-
dotc.core.Symbols.newNormalizedClassSymbol(
2465+
def newClass(owner: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfInfo: Option[TypeRepr]): Symbol =
2466+
val cls = dotc.core.Symbols.newNormalizedClassSymbol(
24642467
owner,
24652468
name.toTypeName,
2466-
flags,
2469+
Flags.EmptyFlags,
24672470
parents,
2468-
dotc.core.Scopes.newScopeWith(decls*),
2471+
dotc.core.Scopes.newScope, // TODO remove from parameters of newNormalizedClassSymbol
24692472
selfInfo.getOrElse(Types.NoType),
2470-
privateWithin)
2471-
2472-
def newPrimaryConstructor(cls: Symbol, tpe: TypeRepr): Symbol =
2473-
dotc.core.Symbols.newSymbol(cls, nme.CONSTRUCTOR, dotc.core.Flags.Method, tpe, noSymbol)
2473+
dotc.core.Symbols.NoSymbol)
2474+
val ctrTpe = Types.MethodType(Nil)(_ => Nil, _ => dotc.core.Symbols.defn.UnitClass.typeRef)
2475+
cls.enter(dotc.core.Symbols.newSymbol(cls, nme.CONSTRUCTOR, dotc.core.Flags.Method, ctrTpe, noSymbol))
2476+
cls
24742477

24752478
def newMethod(owner: Symbol, name: String, tpe: TypeRepr): Symbol =
24762479
newMethod(owner, name, tpe, Flags.EmptyFlags, noSymbol)

library/src/scala/quoted/Quotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
464464

465465
/** Methods of the module object `val ClassDef` */
466466
trait ClassDefModule { this: ClassDef.type =>
467-
@experimental def apply(cls: Symbol, constr: DefDef, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): ClassDef
467+
@experimental def apply(cls: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): ClassDef
468468
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], selfOpt: Option[ValDef], body: List[Statement]): ClassDef
469469
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], Option[ValDef], List[Statement])
470470
}
@@ -3534,7 +3534,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
35343534
/** The class Symbol of a global class definition */
35353535
def classSymbol(fullName: String): Symbol
35363536

3537-
def newClass(owner: Symbol, name: String, flags: Flags, parents: List[TypeRepr], decls: List[Symbol], selfInfo: Option[TypeRepr], privateWithin: Symbol): Symbol
3537+
@experimental def newClass(owner: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfInfo: Option[TypeRepr]): Symbol
35383538

35393539
/** Generates a new method symbol with the given parent, name and type.
35403540
*

tests/run-macros/ClassDef_apply.check

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
a
1+
Constructing foo
2+
class Test_2$package$foo$1
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import scala.quoted.*
22

33
inline def makeClass(inline name: String): Any = ${ makeClassExpr('name) }
4-
private def makeClassExpr(name: Expr[String])(using Quotes): Expr[Any] = {
4+
private def makeClassExpr(nameExpr: Expr[String])(using Quotes): Expr[Any] = {
55
import quotes.reflect.*
66

7-
val cls = Symbol.newClass(Symbol.spliceOwner, name.valueOrAbort, Flags.EmptyFlags, parents = List(TypeRepr.of[Object]), decls = Nil, selfInfo = None, privateWithin = Symbol.noSymbol)
7+
val name = nameExpr.valueOrAbort
8+
val parents = List(Inferred(TypeRepr.of[Object]))
9+
def decls(cls: Symbol): List[Symbol] = Nil
810

9-
val constr = DefDef(cls.primaryConstructor, argss => Some('{}.asTerm))
10-
val clsDef = ClassDef(cls, constr, parents = Nil, body = Nil)
11+
val cls = Symbol.newClass(Symbol.spliceOwner, name, parents = parents.map(_.tpe), decls, selfInfo = None)
12+
13+
val clsDef = ClassDef(cls, parents, body = List('{println(s"Constructing ${$nameExpr}")}.asTerm))
1114
val newCls = Typed(Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil), Inferred(TypeRepr.of[Object]))
15+
1216
Block(List(clsDef), newCls).asExpr
1317
// '{
14-
// class `name`()
18+
// class `name`() { println("Constructing `name`") }
1519
// new `name`()
1620
// }
1721
}
18-
19-
// Block(List(TypeDef(foo,Template(DefDef(<init>,List(List()),
20-
// TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],Literal(Constant(()))),List(),
21-
// ValDef(_,EmptyTree,EmptyTree),List()))),Apply(Select(New(TypeTree[TypeRef(NoPrefix,class foo)]),<init>),List()))
22-
// Block(List(TypeDef(foo,Template(DefDef(<init>,List(List()),
23-
// TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Unit)],EmptyTree),List(Apply(Select(New(TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class java)),object lang),Object)]),<init>),List())),
24-
// ValDef(_,EmptyTree,EmptyTree),List()))),Typed(Apply(Select(New(Ident(foo)),<init>),List()),TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class java)),object lang),Object)]))

0 commit comments

Comments
 (0)