Skip to content

Commit

Permalink
Small reordering tweak
Browse files Browse the repository at this point in the history
Summary:
Classify lookup statements as `StmtPointMatch`. Normally lookups are
tracked separately, but we might encounter lookups inside disjunctions
or nested groups, where classifying them correctly is important.

Reviewed By: malanka

Differential Revision: D64036715

fbshipit-source-id: c748075f545a4df15d896adda7130240ac657889
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Oct 9, 2024
1 parent f4fcb30 commit 76cbade
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
5 changes: 5 additions & 0 deletions glean/db/Glean/Query/Codegen/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module Glean.Query.Codegen.Types
( Match(..)
, matchVar
, isVar
, Var(..)
, CodegenQuery
, QueryWithInfo(..)
Expand Down Expand Up @@ -187,6 +188,10 @@ type Expr_ var = Term (Match () var)

type Output = Typed (Register 'BinaryOutputPtr)

isVar :: Pat -> Maybe Var
isVar (Ref v) = matchVar v
isVar _ = Nothing

data Var = Var
{ varType :: Type
, varId :: {-# UNPACK #-}!Int
Expand Down
12 changes: 0 additions & 12 deletions glean/db/Glean/Query/Opt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ import qualified Glean.Angle.Types as Type
import Glean.Angle.Types (FieldDef_(..))
import Glean.Query.Flatten.Types
import Glean.Query.Codegen.Types
( matchVar
, Match(..)
, Var(..)
, Generator_(..)
, Pat
, Generator
, QueryWithInfo(..))
import Glean.Query.Vars
import Glean.RTS.Term
import Glean.RTS.Types
Expand Down Expand Up @@ -501,11 +494,6 @@ extendGen var gen = do
IntMap.insert (varId var') gen (optGenerators s) }
return True

isVar :: Pat -> Maybe Var
isVar (Ref (MatchVar v)) = Just v
isVar (Ref (MatchBind v)) = Just v
isVar _ = Nothing

data OptState = OptState
{ optNextVar :: !Int
-- ^ for making fresh variables
Expand Down
15 changes: 3 additions & 12 deletions glean/db/Glean/Query/Reorder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ import Compat.Prettyprinter hiding ((<>))

import Glean.Query.BindOrder
import Glean.Query.Codegen.Types
( matchVar
, Var(..)
, Pat
, Match(..)
, CgStatement_(..)
, CgStatement
, Generator_(..)
, CgQuery(..)
, QueryWithInfo(..)
, SeekSection(..)
, CodegenQuery)
import Glean.Display
import Glean.Query.Flatten.Types
import Glean.Query.Vars
Expand Down Expand Up @@ -319,7 +308,9 @@ reorderStmtGroup sc bound stmts =
others = [ (bound, stmt) | (Nothing, bound, stmt) <- summaries ]

classify :: VarSet -> FlatStatement -> StmtCost
classify bound (FlatStatement _ _ (FactGenerator _ key _ _)) =
classify bound (FlatStatement _ lhs (FactGenerator _ key _ _))
| Just (Var _ v _) <- isVar lhs, v `IntSet.member` bound = StmtPointMatch
| otherwise =
case classifyPattern ((`IntSet.member` bound) . varId) key of
PatternMatch _ Point -> StmtPointMatch
PatternMatch PrefixFactId Scan -> StmtPrefixFactMatch
Expand Down

0 comments on commit 76cbade

Please sign in to comment.