Skip to content

Commit

Permalink
Delete the Set constructor
Browse files Browse the repository at this point in the history
Summary: We only ever used this constructor for tests and it is getting very hard to accomodate in the code, especially for schema evolution. In the tests, we can use an array instead, since sets are represented as arrays anyway.

Reviewed By: donsbot

Differential Revision: D67460367

fbshipit-source-id: a2831454fdfd4bc9fdf8d2f49f0664d99cba7563
  • Loading branch information
Josef Svenningsson authored and facebook-github-bot committed Dec 20, 2024
1 parent 19a7593 commit b6ed90e
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 25 deletions.
4 changes: 0 additions & 4 deletions glean/db/Glean/Query/Codegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,6 @@ preProcessPat pat = unsafePerformIO $
ByteArray bs -> do
b <- builder
lift $ encodeByteArray b bs
Set terms -> do
b <- builder
lift $ FFI.call $ glean_push_value_set b $ fromIntegral $ length terms
mapM_ build terms

-- | True if the prefix of this query is empty
emptyPrefix :: [QueryChunk var] -> Bool
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Flatten.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ flattenPattern pat = case pat of
ByteArray s -> singleTerm (ByteArray s)
Array terms -> manyTerms Array <$> mapM flattenPattern terms
Tuple terms -> manyTerms Tuple <$> mapM flattenPattern terms
Set terms -> manyTerms Set <$> mapM flattenPattern terms
Alt s x -> fmap (fmap (Alt s)) <$> flattenPattern x
Ref (MatchWild ty) -> singleTerm (Ref (MatchWild ty))
Ref (MatchNever ty) -> singleTerm (Ref (MatchNever ty))
Expand Down
2 changes: 0 additions & 2 deletions glean/db/Glean/Query/Opt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ instance Apply Pat where
apply (Tuple xs) = Tuple <$> mapM apply xs
apply (Array xs) = Array <$> mapM apply xs
apply (Alt n x) = Alt n <$> apply x
apply (Set xs) = Set <$> mapM apply xs
apply (Ref (MatchVar v)) = applyVar v
apply (Ref (MatchBind v)) = applyVar v
apply (Ref (MatchAnd x y)) = do
Expand Down Expand Up @@ -385,7 +384,6 @@ neverMatches = \case
ByteArray _ -> False
String _ -> False
Tuple terms -> any neverMatches terms
Set _ -> False
Alt _ term -> neverMatches term
Ref match -> case match of
MatchWild _ -> False
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Prune.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ prune hasFacts (QueryWithInfo q _ gen t) = do
String{} -> Just pat
Array xs -> Array <$> traverse prunePat xs
Tuple xs -> Tuple <$> traverse prunePat xs
Set xs -> Set <$> traverse prunePat xs
Alt i x -> Alt i <$> prunePat x
Ref m -> case m of
MatchWild{} -> Just pat
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Reorder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ classifyPattern bound t = go PrefixEmpty t end
Array xs -> termSeq pref xs r
ByteArray{} -> fixed pref r
Tuple xs -> termSeq pref xs r
Set xs -> termSeq pref xs r
Alt _ t -> fixed pref (\pref -> go pref t r)
String{} -> fixed pref r
Ref m -> case m of
Expand Down
3 changes: 0 additions & 3 deletions glean/db/Glean/Query/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ buildTerm output vars term = go term
outputNatImm (fromIntegral (length vs)) output
mapM_ go vs
Tuple fields -> mapM_ go fields
Set vs -> do
outputNatImm (fromIntegral (length vs)) output
mapM_ go vs
Alt n term -> do outputNatImm n output; go term
Ref (MatchFid f) -> outputNatImm (fromIntegral (fromFid f)) output
Ref (MatchPrefix str rest) -> do
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ tcPatUsesNegation = \case
RTS.Array xs -> firstJust tcPatUsesNegation xs
RTS.ByteArray _ -> Nothing
RTS.Tuple xs -> firstJust tcPatUsesNegation xs
RTS.Set xs -> firstJust tcPatUsesNegation xs
RTS.Alt _ t -> tcPatUsesNegation t
RTS.String _ -> Nothing
RTS.Ref match -> matchUsesNegation match
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Typecheck/Unify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ zonkTcPat p = case p of
RTS.Tuple ts -> RTS.Tuple <$> mapM zonkTcPat ts
RTS.Alt n t -> RTS.Alt n <$> zonkTcPat t
RTS.String{} -> return p
RTS.Set terms -> RTS.Set <$> mapM zonkTcPat terms
Ref (MatchExt (Typed ty (TcPromote inner e))) -> do
ty' <- zonkType ty
inner' <- zonkType inner
Expand Down
1 change: 0 additions & 1 deletion glean/db/Glean/Query/Vars.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ instance VarsOf m => VarsOf (Term m) where
Tuple xs -> varsOf w xs r
Array xs -> varsOf w xs r
Alt _ x -> varsOf w x r
Set xs -> varsOf w xs r

instance VarsOf (Match () Var) where
varsOf w m r = case m of
Expand Down
7 changes: 2 additions & 5 deletions glean/hs/Glean/RTS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module Glean.RTS (
glean_pop_value_fact,
) where

import Data.List
import Data.Word
import Foreign.C.String
import Foreign.C.Types
Expand All @@ -63,6 +62,7 @@ import qualified Data.ByteString.Unsafe as BS
import System.IO.Unsafe (unsafePerformIO)

import qualified Util.FFI as FFI
import Util.List (uniq)

import qualified Glean.FFI as FFI
import Glean.RTS.Builder
Expand All @@ -82,9 +82,6 @@ encodeValue b (Array xs) = do
mapM_ (encodeValue b) xs
encodeValue b (ByteArray xs) = encodeByteArray b xs
encodeValue b (Tuple xs) = mapM_ (encodeValue b) xs
encodeValue b (Set xs) = do
FFI.call $ glean_push_value_set b $ fromIntegral $ length xs
mapM_ (encodeValue b) xs
encodeValue b (Alt n x) = do
FFI.call $ glean_push_value_selector b $ fromIntegral n
encodeValue b x
Expand Down Expand Up @@ -264,7 +261,7 @@ decodeValue d ty = case ty of
Alt (fromIntegral sel) <$> decodeValue d (tys !! fromIntegral sel)
SetRep elty -> do
size <- dSet d
Set . sort <$> replicateM (fromIntegral size) (decodeValue d elty)
Array . uniq <$> replicateM (fromIntegral size) (decodeValue d elty)
StringRep -> String <$> dString d
PredicateRep _ -> Ref <$> dFact d

Expand Down
3 changes: 0 additions & 3 deletions glean/hs/Glean/RTS/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ data Term ref
| Array [Term ref]
| ByteArray {-# UNPACK #-} !ByteString
| Tuple [Term ref]
| Set [Term ref]
| Alt {-# UNPACK #-} !Word64 (Term ref)
| String {-# UNPACK #-} !ByteString -- utf8-encoded
| Ref ref
Expand All @@ -57,8 +56,6 @@ instance Display ref => Display (Term ref) where
display _ (ByteArray xs) = pretty (show xs) <> "#"
display opts (Tuple xs) =
align $ encloseSep "{" "}" "," $ map (display opts) xs
display opts (Set qs) =
align $ "set" <+> encloseSep "(" ")" "," (map (display opts) qs)
display opts (Alt s x) = "(" <> pretty s <> "|" <> display opts x <> ")"
-- display opts (String s) = "\"" <> display opts s <> "\""
display _ (String s) =
Expand Down
3 changes: 1 addition & 2 deletions glean/test/tests/RTSTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ valueFor (T.RecordTy fields) =
valueFor (T.SumTy fields) = do
(i, field) <- elements $ zip [0..] fields
Alt i <$> valueFor (T.fieldDefType field)
valueFor (T.SetTy ty) = fmap Set $ sized $ \n -> do
valueFor (T.SetTy ty) = fmap Array $ sized $ \n -> do
k <- choose (0,n)
nub . sort <$> vectorOf k (resize (n `div` k) $ valueFor ty)
valueFor T.PredicateTy{} = Ref <$> arbitrary
Expand All @@ -124,7 +124,6 @@ shrinkValue (Nat n) = Nat <$>
[ n `div` 2 | n >= 2] ++
[ (n `div` 2) + 1 | n >= 4 ] ++
[ n - 1 | n >= 1 ]
shrinkValue (Set es) = Set <$> shrinkList shrinkValue es
shrinkValue (Alt n e) = Alt n <$> shrinkValue e
shrinkValue (Tuple es) = Tuple <$> shrinkList shrinkValue es
shrinkValue (Array es) = Array <$> shrinkList shrinkValue es
Expand Down

0 comments on commit b6ed90e

Please sign in to comment.