File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -506,7 +506,7 @@ flattenStmts (Statements s) = map Floating (reverse s)
506506
507507disjunction :: [FlatStatementGroup ] -> FlatStatement
508508disjunction [FlatStatementGroup [x]] = unOrdered x
509- disjunction groups = FlatDisjunction groups
509+ disjunction groups = flatDisjunction groups
510510
511511mkGroup :: [Statements ] -> [Statements ] -> FlatStatementGroup
512512mkGroup ords floats =
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ module Glean.Query.Flatten.Types
2121 , Ordered (.. )
2222 , unOrdered
2323 , grouping
24+ , flatDisjunction
2425 , mkStatementGroup
2526 , singletonGroup
2627 , boundVars
@@ -129,6 +130,18 @@ grouping :: FlatStatementGroup -> FlatStatement
129130grouping (FlatStatementGroup [one]) = unOrdered one
130131grouping group = FlatDisjunction [group]
131132
133+ -- | Flatten nested FlatDisjunction
134+ flatDisjunction :: [FlatStatementGroup ] -> FlatStatement
135+ flatDisjunction groups =
136+ FlatDisjunction
137+ [ group
138+ | g <- groups
139+ , group <- case g of
140+ FlatStatementGroup [Ordered (FlatDisjunction gs)] -> gs
141+ FlatStatementGroup [Floating (FlatDisjunction gs)] -> gs
142+ _ -> [g]
143+ ]
144+
132145-- | Smart constructor for a FlatStatementGroup, as with "grouping"
133146-- this flattens unnecessary nesting.
134147mkStatementGroup :: [Ordered FlatStatement ] -> FlatStatementGroup
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ instance Apply FlatStatement where
248248 [] -> case stmtss' of
249249 [] -> return (FlatDisjunction [] )
250250 (ss : _) -> return (grouping ss)
251- some -> return (FlatDisjunction some)
251+ some -> return (flatDisjunction some)
252252 apply (FlatConditional cond then_ else_) = do
253253 -- like disjunctions, assumptions arising from the conditional statements
254254 -- are not true outside of it. However, those arising from the condition
@@ -731,7 +731,7 @@ filterStmt stmt = case stmt of
731731 FlatNegation stmts -> FlatNegation <$> filterGroupEnclosed stmts
732732 FlatDisjunction [stmts] -> grouping <$> filterGroup stmts
733733 FlatDisjunction stmtss ->
734- FlatDisjunction <$> mapM filterGroupEnclosed stmtss
734+ flatDisjunction <$> mapM filterGroupEnclosed stmtss
735735 FlatConditional cond then_ else_ -> do
736736 (cond', then') <- encloseSeen $ do
737737 cond' <- filterGroup cond
You can’t perform that action at this time.
0 commit comments