File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -213,6 +213,22 @@ object PatternMatcher {
213213
214214 /** Plan for matching `selectors` against argument patterns `args` */
215215 def matchArgsPlan (selectors : List [Tree ], args : List [Tree ], onSuccess : Plan ): Plan = {
216+ /* For a case with arguments that have some test on them such as
217+ * ```
218+ * case Foo(1, 2) => someCode
219+ * ```
220+ * all arguments values are extracted before the checks are performed. This shape is expected by `emit`
221+ * to avoid generating deep trees.
222+ * ```
223+ * val x1: Foo = ...
224+ * val x2: Int = x1._1
225+ * val x3: Int = x1._2
226+ * if (x2 == 1) {
227+ * if (x3 == 2) someCode
228+ * else label$1()
229+ * } else label$1()
230+ * ```
231+ */
216232 def matchArgsSelectorsPlan (selectors : List [Tree ], syms : List [Symbol ]): Plan =
217233 selectors match {
218234 case selector :: selectors1 => letAbstract(selector)(sym => matchArgsSelectorsPlan(selectors1, sym :: syms))
@@ -850,6 +866,23 @@ object PatternMatcher {
850866 else {
851867 /** Merge nested `if`s that have the same `else` branch into a single `if`.
852868 * This optimization targets calls to label defs for case failure jumps to next case.
869+ *
870+ * Plan for
871+ * ```
872+ * val x1: Int = ...
873+ * val x2: Int = ...
874+ * if (x1 == y1) {
875+ * if (x2 == y2) someCode
876+ * else label$1()
877+ * } else label$1()
878+ * ```
879+ * is emitted as
880+ * ```
881+ * val x1: Int = ...
882+ * val x2: Int = ...
883+ * if (x1 == y1 && x2 == y2) someCode
884+ * else label$1()
885+ * ```
853886 */
854887 def emitWithMashedConditions (plans : List [TestPlan ]): Tree = {
855888 val plan = plans.head
You can’t perform that action at this time.
0 commit comments