Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39fdf3d

Browse files
committedMar 18, 2025·
adding variadicity to the mirror
1 parent 9eb2e4c commit 39fdf3d

File tree

1 file changed

+15
-57
lines changed

1 file changed

+15
-57
lines changed
 

‎clairV2/src/main/scala-3/CV2Mirror.scala

+15-57
Original file line numberDiff line numberDiff line change
@@ -37,95 +37,53 @@ inline def inputVariadicity[Elem] = inline erasedValue[Elem] match
3737
// tries to match on that type exactly (ie. unwrappedType[Value[IntegerType]] for example) rather than the matched type...
3838
// very weird things going on
3939

40-
type unwrappedInput[Elem] = Elem match
41-
case Variadic[t] => t
42-
case _ => Elem
43-
44-
// workaround for unwrappedType to make sure that variadics work, it is ugly, but it is :'(
45-
inline def getVariadicDefInput[Label, Elem]: OpInput = {
40+
/** Produces an OpInput to OperationDef given a definition of a Type.
41+
*
42+
* @return
43+
* Input to OperationDef, either: OperandDef, ResultDef, RegionDef,
44+
* SuccessorDef, OpPropertyDef, OpAttributeDef
45+
*/
46+
inline def getDefInput[Label, Elem]: OpInput = {
4647

4748
val name = inline erasedValue[Label] match
4849
case _: String => constValue[Label].asInstanceOf[String]
4950
case _ =>
5051
throw new Exception("Internal error!")
5152

5253
inline erasedValue[Elem] match
53-
case _: Result[t] =>
54-
ResultDef(
54+
case _: Variadic[Operand[t]] =>
55+
OperandDef(
5556
id = name,
5657
typeString = typeToString[t],
5758
Variadicity.Variadic
5859
)
59-
case _: Operand[t] =>
60+
case _: Variadic[Result[t]] =>
6061
OperandDef(
6162
id = name,
6263
typeString = typeToString[t],
6364
Variadicity.Variadic
6465
)
65-
case _: Region =>
66-
RegionDef(
67-
id = name,
68-
Variadicity.Variadic
69-
)
70-
case _: Successor =>
71-
SuccessorDef(
72-
id = name,
73-
Variadicity.Variadic
74-
)
75-
case _: Property[t] =>
76-
OpPropertyDef(
77-
id = name,
78-
typeString = typeToString[t]
79-
)
80-
case _: Attr[t] =>
81-
OpAttributeDef(
82-
id = name,
83-
typeString = typeToString[t]
84-
)
85-
case _ =>
86-
throw new Exception(
87-
s"Unsupported shennaigans with variadic field $name of type ${typeToString[Elem]}"
88-
)
89-
}
90-
91-
/** Produces an OpInput to OperationDef given a definition of a Type.
92-
*
93-
* @return
94-
* Input to OperationDef, either: OperandDef, ResultDef, RegionDef,
95-
* SuccessorDef, OpPropertyDef, OpAttributeDef
96-
*/
97-
inline def getDefInput[Label, Elem]: OpInput = {
98-
99-
val name = inline erasedValue[Label] match
100-
case _: String => constValue[Label].asInstanceOf[String]
101-
case _ =>
102-
throw new Exception("Internal error!")
103-
104-
inline erasedValue[Elem] match
105-
case _: Variadic[t] =>
106-
getVariadicDefInput[Label, t]
107-
10866
case _: Result[t] =>
10967
ResultDef(
11068
id = name,
11169
typeString = typeToString[t],
112-
inputVariadicity[Elem]
70+
Variadicity.Single
11371
)
11472
case _: Operand[t] =>
11573
OperandDef(
11674
id = name,
11775
typeString = typeToString[t],
118-
inputVariadicity[Elem]
76+
Variadicity.Single
11977
)
12078
case _: Region =>
12179
RegionDef(
12280
id = name,
123-
inputVariadicity[Elem]
81+
Variadicity.Single
12482
)
12583
case _: Successor =>
12684
SuccessorDef(
12785
id = name,
128-
inputVariadicity[Elem]
86+
Variadicity.Single
12987
)
13088
case _: Property[t] =>
13189
OpPropertyDef(
@@ -139,7 +97,7 @@ inline def getDefInput[Label, Elem]: OpInput = {
13997
)
14098
case _ =>
14199
throw new Exception(
142-
s"Unsupported shennaigans with field $name of type ${typeToString[Elem]}"
100+
s"Unsupported shennaigans here with field $name of type ${typeToString[Elem]}"
143101
)
144102
}
145103

0 commit comments

Comments
 (0)
Please sign in to comment.