Debugging Quasiquotes and Rewritings
Debugging Quasiquotes
Replace code"..."
with dbg_code"..."
and look at the compilation messages.
They may help you figure out whether the quasiquote was compiled as expected
(sometimes, you may notice that the wrong types or implicit arguments may have been inferred).
Similarly, there is dbg_rewrite
for debugging code rewritings.
Debugging Rewritings
To see why rewritings did not fire or how they fired,
consider adding printing statements in the right-hand side of the rewriting,
or using IR.debugFor(... code ...)
to print detailed logging information about what happens in a limited scope.
See also the next section:
Debugging Pattern Matching
When something doesn’t match (for example, in a rewrite rule pattern),
it is usually best to isolate the failure and reproduced it
with a minimal pattern matching example enclosed in IR.debugFor(... code ...)
.
For example, the following session uses logging info to pintpoint that the match failed because
mehod symbol scala.Int.toFloat
is different from scala.Int.toDouble
.
scala> val pgrm = code"Some(123.toDouble.toString)"
pgrm: example.doc.IR.ClosedCode[Some[String]] = code"scala.Some.apply[java.lang.String](123.toDouble.toString())"
scala> IR.debugFor(pgrm match { case code"Some(123.toFloat.toString)" => case _ => })
Extracting code"scala.Some.apply[java.lang.String](123.toDouble.toString())" with code"scala.Some.apply[java.lang.String](123.toFloat.toString())"
| M scala.Some.apply[String](123.toFloat.toString())
| << code"scala.Some.apply[java.lang.String](123.toDouble.toString())"
| | M scala.Some
| | << code"scala.Some"
| | >> Some((Map(),Map(),Map()))
| | [+] Match String with String
| | M 123.toFloat.toString()
| | << code"123.toDouble.toString()"
| | | M 123.toFloat
| | | << code"123.toDouble"
| | | | Symbol: scala.Int.toFloat =/= scala.Int.toDouble
| | | >> None
| | >> None
| >> None
Result: None