@@ -43,10 +43,16 @@ class CustomControlPhase(setting: Setting) extends CommonPhase:
43
43
var fromBooleanSym : Symbol = uninitialized
44
44
var toFunc1Sym : Symbol = uninitialized
45
45
var fromBranchesSym : Symbol = uninitialized
46
+ var fromBranchesExact0Sym : Symbol = uninitialized
47
+ var fromBranchesExact1Sym : Symbol = uninitialized
46
48
var fromCasesSym : Symbol = uninitialized
49
+ var fromCasesExactSym : Symbol = uninitialized
47
50
var dfValClsRef : TypeRef = uninitialized
48
51
var dfEncodingRef : TypeRef = uninitialized
49
52
var enumHackedUnapply : Symbol = uninitialized
53
+ var exact0Sym : Symbol = uninitialized
54
+ var exact1Sym : Symbol = uninitialized
55
+ var exactApplySym : Symbol = uninitialized
50
56
var dfcStack : List [Tree ] = Nil
51
57
52
58
override def prepareForDefDef (tree : DefDef )(using Context ): Context =
@@ -148,27 +154,34 @@ class CustomControlPhase(setting: Setting) extends CommonPhase:
148
154
(pairs.reverse, someBlock)
149
155
end transformIfRecur
150
156
157
+ private def isExact0 (tpe : Type )(using Context ): Boolean =
158
+ tpe.dealias match
159
+ case OrType (t1, t2) => isExact0(t1) || isExact0(t2)
160
+ case tpe if tpe.typeSymbol == exact0Sym => true
161
+ case _ => false
162
+
163
+ private def isExact1 (tpe : Type )(using Context ): Boolean =
164
+ tpe.dealias match
165
+ case OrType (t1, t2) => isExact1(t1) || isExact1(t2)
166
+ case tpe if tpe.typeSymbol == exact1Sym => true
167
+ case _ => false
168
+
151
169
override def transformIf (tree : If )(using Context ): Tree =
152
170
if (replaceIfs.contains(tree.srcPos.show))
153
171
// debug("=======================")
154
172
val dfcTree = dfcStack.head
155
- def buildIf (combinedTpe : Type ): Tree =
156
- val (branchesVarArgs, elseOption) =
157
- transformIfRecur(tree, combinedTpe, dfcTree, Nil )
158
- val branches = mkList(branchesVarArgs)
159
- ref(fromBranchesSym)
160
- .appliedToType(combinedTpe)
161
- .appliedTo(branches, elseOption)
162
- .appliedTo(dfcTree)
163
- tree.tpe match
164
- case AppliedType (tycon, List (tpe))
165
- if tycon.dealias.typeSymbol == requiredClass(" dfhdl.internals.Exact" ) =>
166
- val combinedTpe = tpe.widen
167
- val ifTree = buildIf(combinedTpe)
168
- ref(requiredMethod(" dfhdl.internals.Exact.apply" ))
169
- .appliedToType(combinedTpe)
170
- .appliedTo(ifTree.withType(combinedTpe))
171
- case combinedTpe => buildIf(combinedTpe)
173
+ val combinedTpe = tree.tpe.widen
174
+ val (branchesVarArgs, elseOption) =
175
+ transformIfRecur(tree, combinedTpe, dfcTree, Nil )
176
+ val branches = mkList(branchesVarArgs)
177
+ val sym =
178
+ if (isExact1(combinedTpe)) fromBranchesExact1Sym
179
+ else if (isExact0(combinedTpe)) fromBranchesExact0Sym
180
+ else fromBranchesSym
181
+ ref(sym)
182
+ .appliedToType(combinedTpe)
183
+ .appliedTo(branches, elseOption)
184
+ .appliedTo(dfcTree)
172
185
else tree
173
186
174
187
object DFType :
@@ -550,7 +563,8 @@ class CustomControlPhase(setting: Setting) extends CommonPhase:
550
563
caseTupleTrees : List [Tree ],
551
564
forceAnonymous : Boolean
552
565
)(using Context ): Tree =
553
- ref(fromCasesSym)
566
+ val sym = if (isExact1(retTpe)) fromCasesExactSym else fromCasesSym
567
+ ref(sym)
554
568
.appliedToType(retTpe)
555
569
.appliedTo(
556
570
selectorTree,
@@ -954,9 +968,16 @@ class CustomControlPhase(setting: Setting) extends CommonPhase:
954
968
fromBooleanSym = requiredMethod(" dfhdl.core.r__For_Plugin.fromBoolean" )
955
969
toFunc1Sym = requiredMethod(" dfhdl.core.r__For_Plugin.toFunc1" )
956
970
fromBranchesSym = requiredMethod(" dfhdl.core.DFIf.fromBranches" )
971
+ fromBranchesExact0Sym = requiredMethod(" dfhdl.core.DFIf.fromBranchesExact0" )
972
+ fromBranchesExact1Sym = requiredMethod(" dfhdl.core.DFIf.fromBranchesExact1" )
957
973
fromCasesSym = requiredMethod(" dfhdl.core.DFMatch.fromCases" )
974
+ fromCasesExactSym = requiredMethod(" dfhdl.core.DFMatch.fromCasesExact" )
958
975
dfValClsRef = requiredClassRef(" dfhdl.core.DFVal" )
959
976
dfEncodingRef = requiredClassRef(" dfhdl.core.DFEncoding" )
960
977
enumHackedUnapply = requiredMethod(" dfhdl.unapply" )
978
+ exact0Sym = requiredClass(" dfhdl.internals.Exact0" )
979
+ exact1Sym = requiredClass(" dfhdl.internals.Exact1" )
980
+ exactApplySym = requiredMethod(" dfhdl.internals.Exact.apply" )
961
981
ctx
982
+ end prepareForUnit
962
983
end CustomControlPhase
0 commit comments