@@ -8147,16 +8147,23 @@ TExprNode::TPtr DropAssume(const TExprNode::TPtr& node, TExprContext&) {
8147
8147
}
8148
8148
8149
8149
TExprNode::TPtr OptimizeCoalesce (const TExprNode::TPtr& node, TExprContext& ctx) {
8150
- if (const auto & input = node->Head (); input.IsCallable (" If" ) && (input.Child (1U )->IsComplete () || input.Child (2U )->IsComplete ())) {
8150
+ if (const auto & input = node->Head (); input.IsCallable (" If" ) && input.ChildrenSize () == 3U &&
8151
+ (input.Child (1U )->IsComplete () || input.Child (2U )->IsComplete ())) {
8151
8152
YQL_CLOG (DEBUG, CorePeepHole) << " Dive " << node->Content () << " into " << input.Content ();
8152
8153
return ctx.ChangeChildren (input, {
8153
8154
input.HeadPtr (),
8154
8155
ctx.ChangeChild (*node, 0U , input.ChildPtr (1U )),
8155
8156
ctx.ChangeChild (*node, 0U , input.ChildPtr (2U ))
8156
8157
});
8157
- } else if (input.IsCallable (" Nothing" )) {
8158
- YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << input.Content ();
8159
- return node->TailPtr ();
8158
+ } else if (node->ChildrenSize () == 2U ) {
8159
+ if (input.IsCallable (" Nothing" )) {
8160
+ YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << input.Content ();
8161
+ return node->TailPtr ();
8162
+ } else if (input.IsCallable (" Just" )) {
8163
+ YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << input.Content ();
8164
+ return IsSameAnnotation (*node->GetTypeAnn (), *input.GetTypeAnn ()) ?
8165
+ node->HeadPtr () : input.HeadPtr ();
8166
+ }
8160
8167
}
8161
8168
return node;
8162
8169
}
0 commit comments