From 342558dcc6750039209c97a070cf1fb118293469 Mon Sep 17 00:00:00 2001 From: Emilien Bauer Date: Thu, 13 Nov 2025 18:06:38 +0000 Subject: [PATCH 1/3] Add macros module, move a helper there. --- build.mill | 4 ++- .../main/scala-3/clair/AssemblyFormat.scala | 33 ++++++++++--------- core/src/main/scala-3/clair/Macros.scala | 23 +++---------- macros/src/main/scala-3/Macros.scala | 9 +++++ macros/test/src/scala-3/EmptyTest.scala | 5 +++ 5 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 macros/src/main/scala-3/Macros.scala create mode 100644 macros/test/src/scala-3/EmptyTest.scala diff --git a/build.mill b/build.mill index ac52788c..6a18df18 100644 --- a/build.mill +++ b/build.mill @@ -170,9 +170,11 @@ object `package` extends ScairSettings with ScoverageReport with UnidocModule: object utils extends ScairModule + object macros extends ScairModule + object core extends ScairModule: - override def moduleDeps = Seq(utils) + override def moduleDeps = Seq(utils, macros) override def mvnDeps = Seq( mvn"com.lihaoyi::fastparse::3.1.1" diff --git a/core/src/main/scala-3/clair/AssemblyFormat.scala b/core/src/main/scala-3/clair/AssemblyFormat.scala index e83a7f38..cf23ae3d 100644 --- a/core/src/main/scala-3/clair/AssemblyFormat.scala +++ b/core/src/main/scala-3/clair/AssemblyFormat.scala @@ -7,6 +7,7 @@ import scair.Parser import scair.Printer import scair.clair.codegen.* import scair.ir.* +import scair.macros.* import scala.quoted.* @@ -137,7 +138,7 @@ case class AttrDictDirective() extends Directive: state.lastWasPunctuation = false '{ $p.printOptionalAttrDict(${ - selectMember[DictType[String, Attribute]](op, "attributes") + op.member[DictType[String, Attribute]]("attributes") }.toMap)(using 0) } @@ -161,44 +162,44 @@ case class VariableDirective( case OperandDef(name = n, variadicity = v) => v match case Variadicity.Single => - '{ $p.print(${ selectMember[Operand[Attribute]](op, n) }) } + '{ $p.print(${ op.member[Operand[Attribute]](n) }) } case Variadicity.Variadic => '{ - $p.printList(${ selectMember[Seq[Operand[Attribute]]](op, n) })( - using 0 + $p.printList(${ op.member[Seq[Operand[Attribute]]](n) })(using + 0 ) } case Variadicity.Optional => '{ $p.printList(${ - selectMember[Option[Operand[Attribute]]](op, n) + op.member[Option[Operand[Attribute]]](n) })(using 0) } case ResultDef(name = n, variadicity = v) => v match case Variadicity.Single => - '{ $p.print(${ selectMember[Result[Attribute]](op, n) }) } + '{ $p.print(${ op.member[Result[Attribute]](n) }) } case Variadicity.Variadic => '{ - $p.printList(${ selectMember[Seq[Result[Attribute]]](op, n) })( - using 0 + $p.printList(${ op.member[Seq[Result[Attribute]]](n) })(using + 0 ) } case Variadicity.Optional => '{ - $p.printList(${ selectMember[Option[Result[Attribute]]](op, n) })( - using 0 + $p.printList(${ op.member[Option[Result[Attribute]]](n) })(using + 0 ) } case OpPropertyDef(name = n, variadicity = v) => v match case Variadicity.Single => '{ - $p.print(${ selectMember[Attribute](op, n) }) + $p.print(${ op.member[Attribute](n) }) } case Variadicity.Optional => '{ - ${ selectMember[Option[Attribute]](op, n) }.foreach($p.print) + ${ op.member[Option[Attribute]](n) }.foreach($p.print) } Expr.block(List(space), printVar) @@ -244,7 +245,7 @@ case class VariableDirective( override def isPresent(op: Expr[?])(using Quotes) = construct match - case OpInputDef(name = n) => parsed(selectMember[Any](op, n)) + case OpInputDef(name = n) => parsed(op.member[Any](n)) /** Directive for types of individual operands or results. */ @@ -260,13 +261,13 @@ case class TypeDirective( val printType = construct match case MayVariadicOpInputDef(name = n, variadicity = Variadicity.Single) => - '{ $p.print(${ selectMember[Value[?]](op, n) }.typ) } + '{ $p.print(${ op.member[Value[?]](n) }.typ) } case MayVariadicOpInputDef( name = n, variadicity = Variadicity.Variadic ) => '{ - $p.printList(${ selectMember[Seq[Value[?]]](op, n) }.map(_.typ))(using + $p.printList(${ op.member[Seq[Value[?]]](n) }.map(_.typ))(using 0 ) } @@ -275,7 +276,7 @@ case class TypeDirective( variadicity = Variadicity.Optional ) => '{ - ${ selectMember[Option[Value[?]]](op, n) } + ${ op.member[Option[Value[?]]](n) } .map(_.typ) .map($p.print) .getOrElse(()) diff --git a/core/src/main/scala-3/clair/Macros.scala b/core/src/main/scala-3/clair/Macros.scala index afc01007..7c284cbc 100644 --- a/core/src/main/scala-3/clair/Macros.scala +++ b/core/src/main/scala-3/clair/Macros.scala @@ -11,6 +11,7 @@ import scair.clair.mirrored.* import scair.dialects.builtin.* import scair.enums.macros.* import scair.ir.* +import scair.macros.* import scair.transformations.CanonicalizationPatterns import scair.transformations.RewritePattern @@ -35,19 +36,6 @@ import scala.quoted.* || ADT to Unstructured conversion Macro || \*≡==---==≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡==---==≡*/ -/** Small helper to select a member of an expression. - * @param obj - * The object to select the member from. - * @param name - * The name of the member to select. - */ -def selectMember[T: Type](obj: Expr[?], name: String)(using - Quotes -): Expr[T] = - import quotes.reflect.* - - Select.unique(obj.asTerm, name).asExprOf[T] - def makeSegmentSizes[T <: MayVariadicOpInputDef: Type]( hasMultiVariadic: Boolean, defs: Seq[T], @@ -63,7 +51,7 @@ def makeSegmentSizes[T <: MayVariadicOpInputDef: Type]( case Variadicity.Single => Expr(1) case Variadicity.Variadic | Variadicity.Optional => '{ - ${ selectMember[Seq[?]](adtOpExpr, d.name) }.length + ${ adtOpExpr.member[Seq[?]](d.name) }.length } ) ) @@ -96,8 +84,7 @@ def ADTFlatInputMacro[Def <: OpInputDef: Type]( )(using Quotes): Expr[Seq[DefinedInput[Def]]] = val stuff = opInputDefs.map((d: Def) => - selectMember[DefinedInput[Def] | IterableOnce[DefinedInput[Def]]]( - adtOpExpr, + adtOpExpr.member[DefinedInput[Def] | IterableOnce[DefinedInput[Def]]]( d.name ) ) @@ -219,7 +206,7 @@ def verifyMacro( .filter(_.variadicity == Variadicity.Single) .collect(_ match case OperandDef(name, _, _, Some(constraint)) => - val mem = selectMember[Operand[Attribute]](adtOpExpr, name) + val mem = adtOpExpr.member[Operand[Attribute]](name) '{ (ctx: scair.core.constraints.ConstraintContext) => $constraint.verify($mem.typ)(using ctx) }) @@ -804,7 +791,7 @@ def ADTFlatAttrInputMacro[Def <: AttributeDef: Type]( adtAttrExpr: Expr[?] )(using Quotes): Expr[Seq[Attribute]] = Expr.ofList( - attrInputDefs.map(d => selectMember[Attribute](adtAttrExpr, d.name)) + attrInputDefs.map(d => adtAttrExpr.member[Attribute](d.name)) ) def parametersMacro( diff --git a/macros/src/main/scala-3/Macros.scala b/macros/src/main/scala-3/Macros.scala new file mode 100644 index 00000000..0b13584d --- /dev/null +++ b/macros/src/main/scala-3/Macros.scala @@ -0,0 +1,9 @@ +package scair.macros + +import scala.quoted.* + +extension (expr: Expr[?]) + + def member[T: Type](name: String)(using Quotes): Expr[T] = + import quotes.reflect.* + Select.unique(expr.asTerm, name).asExprOf[T] diff --git a/macros/test/src/scala-3/EmptyTest.scala b/macros/test/src/scala-3/EmptyTest.scala new file mode 100644 index 00000000..2303e4ec --- /dev/null +++ b/macros/test/src/scala-3/EmptyTest.scala @@ -0,0 +1,5 @@ +import org.scalatest.flatspec.AnyFlatSpec + +// Having *something* here seemed necessary to work around blocking tests at time ofr writing. +// Please remove if tests work fine without it in the future. +class EmptyTest extends AnyFlatSpec From 3a1b1fb6231a0d770a95790bb4983a99b64043e9 Mon Sep 17 00:00:00 2001 From: Emilien Bauer Date: Fri, 5 Dec 2025 18:32:06 +0000 Subject: [PATCH 2/3] Some moves. --- core/src/main/scala-3/clair/Macros.scala | 299 ++++++++++++----------- core/src/main/scala-3/clair/Mirror.scala | 2 +- 2 files changed, 151 insertions(+), 150 deletions(-) diff --git a/core/src/main/scala-3/clair/Macros.scala b/core/src/main/scala-3/clair/Macros.scala index 7c284cbc..6171116f 100644 --- a/core/src/main/scala-3/clair/Macros.scala +++ b/core/src/main/scala-3/clair/Macros.scala @@ -94,74 +94,6 @@ def ADTFlatInputMacro[Def <: OpInputDef: Type]( case '{ $ns: IterableOnce[DefinedInput[Def]] } => '{ $seq :++ $ns } ) -def operandsMacro( - opDef: OperationDef, - adtOpExpr: Expr[?] -)(using Quotes): Expr[Seq[Operand[Attribute]]] = - ADTFlatInputMacro(opDef.operands, adtOpExpr) - -def successorsMacro( - opDef: OperationDef, - adtOpExpr: Expr[?] -)(using Quotes): Expr[Seq[Successor]] = - ADTFlatInputMacro(opDef.successors, adtOpExpr) - -def resultsMacro( - opDef: OperationDef, - adtOpExpr: Expr[?] -)(using Quotes): Expr[Seq[Result[Attribute]]] = - ADTFlatInputMacro(opDef.results, adtOpExpr) - -def regionsMacro( - opDef: OperationDef, - adtOpExpr: Expr[?] -)(using Quotes): Expr[Seq[Region]] = - ADTFlatInputMacro(opDef.regions, adtOpExpr) - -def propertiesMacro( - opDef: OperationDef, - adtOpExpr: Expr[?] -)(using Quotes): Expr[Map[String, Attribute]] = - - val opSegSizeProp = makeSegmentSizes( - opDef.hasMultiVariadicOperands, - opDef.operands, - adtOpExpr - ) - val resSegSizeProp = makeSegmentSizes( - opDef.hasMultiVariadicResults, - opDef.results, - adtOpExpr - ) - val regSegSizeProp = makeSegmentSizes( - opDef.hasMultiVariadicRegions, - opDef.regions, - adtOpExpr - ) - val succSegSizeProp = makeSegmentSizes( - opDef.hasMultiVariadicSuccessors, - opDef.successors, - adtOpExpr - ) - // Populating a Dictionarty with the properties - val definedProps = - if opDef.properties.isEmpty then '{ Map.empty[String, Attribute] } - else - // extracting property instances from the ADT - val propertyExprs = ADTFlatInputMacro(opDef.properties, adtOpExpr) - val propertyNames = Expr.ofList(opDef.properties.map((d) => Expr(d.name))) - '{ - Map.from(${ propertyNames } zip ${ propertyExprs }) - } - - Seq(opSegSizeProp, resSegSizeProp, regSegSizeProp, succSegSizeProp).foldLeft( - definedProps - ) { - case (map, Some((name, segSize))) => - '{ $map + (${ Expr(name) } -> $segSize) } - case (map, None) => map - } - def customPrintMacro( opDef: OperationDef, adtOpExpr: Expr[?], @@ -827,103 +759,172 @@ def derivedAttributeCompanion[T <: Attribute: Type](using def deriveOperationCompanion[T <: Operation: Type](using Quotes ): Expr[DerivedOperationCompanion[T]] = - val opDef = getDefImpl[T] + OperationDeriver[T].companion + +final class OperationDeriver[T <: Operation: Type](using Quotes) { + + val opDef: OperationDef = operationDefOf[T] val summonedPatterns = Expr.summon[CanonicalizationPatterns[T]] match case Some(canonicalizationPatterns) => '{ $canonicalizationPatterns.patterns } case None => '{ Seq() } + + def operandsMacro( + adtOpExpr: Expr[?] + ): Expr[Seq[Operand[Attribute]]] = + ADTFlatInputMacro(opDef.operands, adtOpExpr) + + def successorsMacro( + adtOpExpr: Expr[?] + ): Expr[Seq[Successor]] = + ADTFlatInputMacro(opDef.successors, adtOpExpr) + + def resultsMacro( + adtOpExpr: Expr[?] + ): Expr[Seq[Result[Attribute]]] = + ADTFlatInputMacro(opDef.results, adtOpExpr) + + def regionsMacro( + adtOpExpr: Expr[?] + ): Expr[Seq[Region]] = + ADTFlatInputMacro(opDef.regions, adtOpExpr) + + def propertiesMacro( + adtOpExpr: Expr[?] + ): Expr[Map[String, Attribute]] = + + val opSegSizeProp = makeSegmentSizes( + opDef.hasMultiVariadicOperands, + opDef.operands, + adtOpExpr + ) + val resSegSizeProp = makeSegmentSizes( + opDef.hasMultiVariadicResults, + opDef.results, + adtOpExpr + ) + val regSegSizeProp = makeSegmentSizes( + opDef.hasMultiVariadicRegions, + opDef.regions, + adtOpExpr + ) + val succSegSizeProp = makeSegmentSizes( + opDef.hasMultiVariadicSuccessors, + opDef.successors, + adtOpExpr + ) + // Populating a Dictionarty with the properties + val definedProps = + if opDef.properties.isEmpty then '{ Map.empty[String, Attribute] } + else + // extracting property instances from the ADT + val propertyExprs = ADTFlatInputMacro(opDef.properties, adtOpExpr) + val propertyNames = Expr.ofList(opDef.properties.map((d) => Expr(d.name))) + '{ + Map.from(${ propertyNames } zip ${ propertyExprs }) + } - '{ + Seq(opSegSizeProp, resSegSizeProp, regSegSizeProp, succSegSizeProp).foldLeft( + definedProps + ) { + case (map, Some((name, segSize))) => + '{ $map + (${ Expr(name) } -> $segSize) } + case (map, None) => map + } + + def companion: Expr[DerivedOperationCompanion[T]] = + '{ - new DerivedOperationCompanion[T]: + new DerivedOperationCompanion[T]: - override def canonicalizationPatterns: Seq[RewritePattern] = - $summonedPatterns + override def canonicalizationPatterns: Seq[RewritePattern] = + $summonedPatterns - def operands(adtOp: T): Seq[Value[Attribute]] = - ${ operandsMacro(opDef, '{ adtOp }) } - def successors(adtOp: T): Seq[Block] = - ${ successorsMacro(opDef, '{ adtOp }) } - def results(adtOp: T): Seq[Result[Attribute]] = - ${ resultsMacro(opDef, '{ adtOp }) } - def regions(adtOp: T): Seq[Region] = - ${ regionsMacro(opDef, '{ adtOp }) } - def properties(adtOp: T): Map[String, Attribute] = - ${ propertiesMacro(opDef, '{ adtOp }) } + def operands(adtOp: T): Seq[Value[Attribute]] = + ${ operandsMacro('{ adtOp }) } + def successors(adtOp: T): Seq[Block] = + ${ successorsMacro('{ adtOp }) } + def results(adtOp: T): Seq[Result[Attribute]] = + ${ resultsMacro('{ adtOp }) } + def regions(adtOp: T): Seq[Region] = + ${ regionsMacro('{ adtOp }) } + def properties(adtOp: T): Map[String, Attribute] = + ${ propertiesMacro('{ adtOp }) } - def name: String = ${ Expr(opDef.name) } + def name: String = ${ Expr(opDef.name) } - def custom_print(adtOp: T, p: Printer)(using indentLevel: Int): Unit = - ${ customPrintMacro(opDef, '{ adtOp }, '{ p }, '{ indentLevel }) } + def custom_print(adtOp: T, p: Printer)(using indentLevel: Int): Unit = + ${ customPrintMacro(opDef, '{ adtOp }, '{ p }, '{ indentLevel }) } - def constraint_verify(adtOp: T): Either[String, Operation] = - ${ - verifyMacro(opDef, '{ adtOp }) - } + def constraint_verify(adtOp: T): Either[String, Operation] = + ${ + verifyMacro(opDef, '{ adtOp }) + } - override def parse[$: P as ctx]( - p: Parser, - resNames: Seq[String] - ): P[T] = - ${ - (getOpCustomParse[T]('{ p }, '{ resNames }) - .getOrElse(parseMacro[T](opDef, '{ p }, '{ resNames }))) - }(using ctx) - - def apply( - operands: Seq[Value[Attribute]] = Seq(), - successors: Seq[Block] = Seq(), - results: Seq[Result[Attribute]] = Seq(), - regions: Seq[Region] = Seq(), - properties: Map[String, Attribute] = Map.empty[String, Attribute], - attributes: DictType[String, Attribute] = - DictType.empty[String, Attribute] - ): UnstructuredOp | T & Operation = - try { - val structured = ${ - tryConstruct( - opDef, - '{ operands }, - '{ results }, - '{ regions }, - '{ successors }, - '{ properties } + override def parse[$: P as ctx]( + p: Parser, + resNames: Seq[String] + ): P[T] = + ${ + (getOpCustomParse[T]('{ p }, '{ resNames }) + .getOrElse(parseMacro[T](opDef, '{ p }, '{ resNames }))) + }(using ctx) + + def apply( + operands: Seq[Value[Attribute]] = Seq(), + successors: Seq[Block] = Seq(), + results: Seq[Result[Attribute]] = Seq(), + regions: Seq[Region] = Seq(), + properties: Map[String, Attribute] = Map.empty[String, Attribute], + attributes: DictType[String, Attribute] = + DictType.empty[String, Attribute] + ): UnstructuredOp | T & Operation = + try { + val structured = ${ + tryConstruct( + opDef, + '{ operands }, + '{ results }, + '{ regions }, + '{ successors }, + '{ properties } + ) + } + structured.attributes.addAll(attributes) + structured + } catch { _ => + UnstructuredOp( + operands = operands, + successors = successors, + results = results, + regions = regions, + properties = properties, + attributes = attributes ) } - structured.attributes.addAll(attributes) - structured - } catch { _ => + + def destructure(adtOp: T): UnstructuredOp = UnstructuredOp( - operands = operands, - successors = successors, - results = results, - regions = regions, - properties = properties, - attributes = attributes + operands = operands(adtOp), + successors = successors(adtOp), + results = results(adtOp), + regions = regions(adtOp).map(_.detached), + properties = properties(adtOp), + attributes = adtOp.attributes ) - } - - def destructure(adtOp: T): UnstructuredOp = - UnstructuredOp( - operands = operands(adtOp), - successors = successors(adtOp), - results = results(adtOp), - regions = regions(adtOp).map(_.detached), - properties = properties(adtOp), - attributes = adtOp.attributes - ) - def structure(unstrucOp: UnstructuredOp): T = - ${ - fromUnstructuredOperationMacro[T](opDef, '{ unstrucOp }) - } match - case adt: DerivedOperation[?, T] => - adt.attributes.addAll(unstrucOp.attributes) - adt - case _ => - throw new Exception( - s"Internal Error: Hacky did not hack -> T is not a DerivedOperation: ${unstrucOp}" - ) + def structure(unstrucOp: UnstructuredOp): T = + ${ + fromUnstructuredOperationMacro[T](opDef, '{ unstrucOp }) + } match + case adt: DerivedOperation[?, T] => + adt.attributes.addAll(unstrucOp.attributes) + adt + case _ => + throw new Exception( + s"Internal Error: Hacky did not hack -> T is not a DerivedOperation: ${unstrucOp}" + ) - } + } +} \ No newline at end of file diff --git a/core/src/main/scala-3/clair/Mirror.scala b/core/src/main/scala-3/clair/Mirror.scala index 7826f64d..5bf36dff 100644 --- a/core/src/main/scala-3/clair/Mirror.scala +++ b/core/src/main/scala-3/clair/Mirror.scala @@ -189,7 +189,7 @@ def stringifyLabels[Elems: Type](using Quotes): List[String] = .asInstanceOf[String] :: stringifyLabels[elems] case '[EmptyTuple] => Nil -def getDefImpl[T <: Operation: Type](using quotes: Quotes): OperationDef = +def operationDefOf[T <: Operation: Type](using quotes: Quotes): OperationDef = import quotes.reflect.* val m = Expr.summon[Mirror.ProductOf[T]].get From 70c4f45e6310e73c5ae3c218994326f7e0fc87fb Mon Sep 17 00:00:00 2001 From: Emilien Bauer Date: Fri, 5 Dec 2025 19:02:16 +0000 Subject: [PATCH 3/3] moves --- core/src/main/scala-3/clair/Macros.scala | 113 ++++++++++++----------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/core/src/main/scala-3/clair/Macros.scala b/core/src/main/scala-3/clair/Macros.scala index 6171116f..72a9aa36 100644 --- a/core/src/main/scala-3/clair/Macros.scala +++ b/core/src/main/scala-3/clair/Macros.scala @@ -70,30 +70,6 @@ def makeSegmentSizes[T <: MayVariadicOpInputDef: Type]( ) case false => None -/** Get all constructs of the specified type flattened from the ADT expression. - * @tparam Def - * The construct definition type. - * @param opInputDefs - * The construct definitions. - * @param adtOpExpr - * The ADT expression. - */ -def ADTFlatInputMacro[Def <: OpInputDef: Type]( - opInputDefs: Seq[Def], - adtOpExpr: Expr[?] -)(using Quotes): Expr[Seq[DefinedInput[Def]]] = - val stuff = - opInputDefs.map((d: Def) => - adtOpExpr.member[DefinedInput[Def] | IterableOnce[DefinedInput[Def]]]( - d.name - ) - ) - stuff.foldLeft('{ Seq.empty[DefinedInput[Def]] })((seq, next) => - next match - case '{ $ne: DefinedInput[Def] } => '{ $seq :+ $ne } - case '{ $ns: IterableOnce[DefinedInput[Def]] } => '{ $seq :++ $ns } - ) - def customPrintMacro( opDef: OperationDef, adtOpExpr: Expr[?], @@ -761,7 +737,7 @@ def deriveOperationCompanion[T <: Operation: Type](using ): Expr[DerivedOperationCompanion[T]] = OperationDeriver[T].companion -final class OperationDeriver[T <: Operation: Type](using Quotes) { +final class OperationDeriver[T <: Operation: Type](using Quotes): val opDef: OperationDef = operationDefOf[T] @@ -769,29 +745,53 @@ final class OperationDeriver[T <: Operation: Type](using Quotes) { case Some(canonicalizationPatterns) => '{ $canonicalizationPatterns.patterns } case None => '{ Seq() } - - def operandsMacro( - adtOpExpr: Expr[?] + + /** Get all constructs of the specified type flattened from the ADT + * expression. + * @tparam Def + * The construct definition type. + * @param opInputDefs + * The construct definitions. + * @param adtOpExpr + * The ADT expression. + */ + def ADTFlatInputMacro[Def <: OpInputDef: Type]( + opInputDefs: Seq[Def] + )(using adtOpExpr: Expr[T]): Expr[Seq[DefinedInput[Def]]] = + val stuff = + opInputDefs.map((d: Def) => + adtOpExpr.member[DefinedInput[Def] | IterableOnce[DefinedInput[Def]]]( + d.name + ) + ) + stuff.foldLeft('{ Seq.empty[DefinedInput[Def]] })((seq, next) => + next match + case '{ $ne: DefinedInput[Def] } => '{ $seq :+ $ne } + case '{ $ns: IterableOnce[DefinedInput[Def]] } => '{ $seq :++ $ns } + ) + + def operandsMacro(using + adtOpExpr: Expr[T] ): Expr[Seq[Operand[Attribute]]] = - ADTFlatInputMacro(opDef.operands, adtOpExpr) + ADTFlatInputMacro(opDef.operands) - def successorsMacro( - adtOpExpr: Expr[?] + def successorsMacro(using + adtOpExpr: Expr[T] ): Expr[Seq[Successor]] = - ADTFlatInputMacro(opDef.successors, adtOpExpr) + ADTFlatInputMacro(opDef.successors) - def resultsMacro( - adtOpExpr: Expr[?] + def resultsMacro(using + adtOpExpr: Expr[T] ): Expr[Seq[Result[Attribute]]] = - ADTFlatInputMacro(opDef.results, adtOpExpr) + ADTFlatInputMacro(opDef.results) - def regionsMacro( - adtOpExpr: Expr[?] + def regionsMacro(using + adtOpExpr: Expr[T] ): Expr[Seq[Region]] = - ADTFlatInputMacro(opDef.regions, adtOpExpr) + ADTFlatInputMacro(opDef.regions) - def propertiesMacro( - adtOpExpr: Expr[?] + def propertiesMacro(using + adtOpExpr: Expr[T] ): Expr[Map[String, Attribute]] = val opSegSizeProp = makeSegmentSizes( @@ -819,20 +819,22 @@ final class OperationDeriver[T <: Operation: Type](using Quotes) { if opDef.properties.isEmpty then '{ Map.empty[String, Attribute] } else // extracting property instances from the ADT - val propertyExprs = ADTFlatInputMacro(opDef.properties, adtOpExpr) - val propertyNames = Expr.ofList(opDef.properties.map((d) => Expr(d.name))) + val propertyExprs = ADTFlatInputMacro(opDef.properties) + val propertyNames = + Expr.ofList(opDef.properties.map((d) => Expr(d.name))) '{ Map.from(${ propertyNames } zip ${ propertyExprs }) } - Seq(opSegSizeProp, resSegSizeProp, regSegSizeProp, succSegSizeProp).foldLeft( - definedProps - ) { - case (map, Some((name, segSize))) => - '{ $map + (${ Expr(name) } -> $segSize) } - case (map, None) => map - } - + Seq(opSegSizeProp, resSegSizeProp, regSegSizeProp, succSegSizeProp) + .foldLeft( + definedProps + ) { + case (map, Some((name, segSize))) => + '{ $map + (${ Expr(name) } -> $segSize) } + case (map, None) => map + } + def companion: Expr[DerivedOperationCompanion[T]] = '{ @@ -842,15 +844,15 @@ final class OperationDeriver[T <: Operation: Type](using Quotes) { $summonedPatterns def operands(adtOp: T): Seq[Value[Attribute]] = - ${ operandsMacro('{ adtOp }) } + ${ operandsMacro(using '{ adtOp }) } def successors(adtOp: T): Seq[Block] = - ${ successorsMacro('{ adtOp }) } + ${ successorsMacro(using '{ adtOp }) } def results(adtOp: T): Seq[Result[Attribute]] = - ${ resultsMacro('{ adtOp }) } + ${ resultsMacro(using '{ adtOp }) } def regions(adtOp: T): Seq[Region] = - ${ regionsMacro('{ adtOp }) } + ${ regionsMacro(using '{ adtOp }) } def properties(adtOp: T): Map[String, Attribute] = - ${ propertiesMacro('{ adtOp }) } + ${ propertiesMacro(using '{ adtOp }) } def name: String = ${ Expr(opDef.name) } @@ -927,4 +929,3 @@ final class OperationDeriver[T <: Operation: Type](using Quotes) { ) } -} \ No newline at end of file