@@ -386,8 +386,8 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
386
386
Context .bind(If (c, transform(thn), transform(els)))
387
387
388
388
case source.If (guards, thn, els) =>
389
- val thnClause = preprocess(Nil , guards, transform(thn))
390
- val elsClause = preprocess(Nil , Nil , transform(els))
389
+ val thnClause = preprocess(" thn " , Nil , guards, transform(thn))
390
+ val elsClause = preprocess(" els " , Nil , Nil , transform(els))
391
391
Context .bind(PatternMatchingCompiler .compile(List (thnClause, elsClause)))
392
392
393
393
// case i @ source.If(guards, thn, els) =>
@@ -400,24 +400,24 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
400
400
// def loop$13() = if ([[cond]]) { [[ body ]]; loop$13() } else { return () }
401
401
// loop$13()
402
402
case source.While (guards, body, default) =>
403
- val loopName = TmpBlock (" whileLoop " )
403
+ val loopName = TmpBlock (" while " )
404
404
val loopType = core.BlockType .Function (Nil , Nil , Nil , Nil , core.Type .TUnit )
405
405
406
406
// TODO double check: probably we are forgetting the capture of the guards!
407
407
val loopCapt = transform(Context .inferredCapture(body))
408
408
val loopCall = Stmt .App (core.BlockVar (loopName, loopType, loopCapt), Nil , Nil , Nil )
409
409
410
410
val transformedBody = transform(body)
411
- val thenBranch = Stmt .Val (TmpValue (" whileThen " ), transformedBody.tpe, transformedBody, loopCall)
411
+ val thenBranch = Stmt .Val (TmpValue (" while_thn " ), transformedBody.tpe, transformedBody, loopCall)
412
412
val elseBranch = default.map(transform).getOrElse(Return (Literal ((), core.Type .TUnit )))
413
413
414
414
val loopBody = guards match {
415
415
case List (MatchGuard .BooleanGuard (cond)) =>
416
416
insertBindings { core.If (transformAsPure(cond), thenBranch, elseBranch) }
417
417
case _ =>
418
418
insertBindings {
419
- val thenClause = preprocess(Nil , guards, thenBranch)
420
- val elseClause = preprocess(Nil , Nil , elseBranch)
419
+ val thenClause = preprocess(" guard_thn " , Nil , guards, thenBranch)
420
+ val elseClause = preprocess(" guard_els " , Nil , Nil , elseBranch)
421
421
PatternMatchingCompiler .compile(List (thenClause, elseClause))
422
422
}
423
423
}
@@ -434,8 +434,8 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
434
434
case source.Match (sc, cs, default) =>
435
435
// (1) Bind scrutinee and all clauses so we do not have to deal with sharing on demand.
436
436
val scrutinee : ValueVar = Context .bind(transformAsPure(sc))
437
- val clauses = cs.map(c => preprocess(scrutinee, c))
438
- val defaultClause = default.map(stmt => preprocess(Nil , Nil , transform(stmt))).toList
437
+ val clauses = cs.zipWithIndex. map((c, i) => preprocess(s " k ${i} " , scrutinee, c))
438
+ val defaultClause = default.map(stmt => preprocess(" k_els " , Nil , Nil , transform(stmt))).toList
439
439
val compiledMatch = PatternMatchingCompiler .compile(clauses ++ defaultClause)
440
440
Context .bind(compiledMatch)
441
441
@@ -527,10 +527,10 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
527
527
*/
528
528
def collectClauses (term : source.Term )(using Context ): Option [List [Clause ]] = term match {
529
529
case source.If (guards, thn, els) =>
530
- val thenClause = preprocess(Nil , guards, transform(thn))
530
+ val thenClause = preprocess(" thn " , Nil , guards, transform(thn))
531
531
val elseClauses = collectClauses(els) match {
532
532
case Some (clauses) => clauses
533
- case None => List (preprocess(Nil , Nil , transform(els)))
533
+ case None => List (preprocess(" els " , Nil , Nil , transform(els)))
534
534
}
535
535
Some (thenClause :: elseClauses)
536
536
case _ => None
@@ -653,10 +653,10 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
653
653
})
654
654
}
655
655
656
- def preprocess (sc : ValueVar , clause : source.MatchClause )(using Context ): Clause =
657
- preprocess(List ((sc, clause.pattern)), clause.guards, transform(clause.body))
656
+ def preprocess (label : String , sc : ValueVar , clause : source.MatchClause )(using Context ): Clause =
657
+ preprocess(label, List ((sc, clause.pattern)), clause.guards, transform(clause.body))
658
658
659
- def preprocess (patterns : List [(ValueVar , source.MatchPattern )], guards : List [source.MatchGuard ], body : core.Stmt )(using Context ): Clause = {
659
+ def preprocess (label : String , patterns : List [(ValueVar , source.MatchPattern )], guards : List [source.MatchGuard ], body : core.Stmt )(using Context ): Clause = {
660
660
import PatternMatchingCompiler .*
661
661
662
662
def boundInPattern (p : source.MatchPattern ): List [core.ValueParam ] = p match {
@@ -686,7 +686,7 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
686
686
687
687
// create joinpoint
688
688
val params = patterns.flatMap { case (sc, p) => boundInPattern(p) } ++ guards.flatMap(boundInGuard)
689
- val joinpoint = Context .bind(TmpBlock (" k " ), BlockLit (Nil , Nil , params, Nil , body))
689
+ val joinpoint = Context .bind(TmpBlock (label ), BlockLit (Nil , Nil , params, Nil , body))
690
690
691
691
def transformPattern (p : source.MatchPattern ): Pattern = p match {
692
692
case source.AnyPattern (id) =>
0 commit comments