Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GHC 9.8.1 #1310

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# haskell-language-server = {};
# hlint = {};
};
modules = [{ghcOptions = ["-Wno-error=x-partial"];}];
shell.buildInputs = with pkgs; [
zlib
z3
Expand Down
11 changes: 7 additions & 4 deletions src-tool/Pact/Analyze/Eval/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,10 @@ format s tms = do
then Right (literalS (Str s))
else if plen - length tms > 1
then Left (AnalyzeFailure dummyInfo "format: not enough arguments for template")
else Right $ foldl'
(\r (e, t) -> r .++ rep e .++ t)
(head parts)
(zip tms (tail parts))
else case parts of
partsHead:partsTail ->
Right $ foldl'
(\r (e, t) -> r .++ rep e .++ t)
partsHead
(zip tms partsTail)
[] -> error "Impossible case: We checked that this list is nonempty"
7 changes: 6 additions & 1 deletion src-tool/Pact/Analyze/Translate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,12 @@ translatePact nodes = do
-- The proper fix is recognizing the nested defpact dyn invoke and replacing it with
-- the default value of what the invocation would return.
-- For now, this unblocks the problem.
(if null protoSteps then [] else tail $ reverse protoSteps)
(if null protoSteps
then []
else (\case
_:xs -> xs
[] -> error "Expected nonempty list"
Comment on lines +760 to +761
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if this can be changed to avoid the preceding null protoSteps check, and returning an empty list in this branch instead of erroring out? That is, smth like

(case reverse protoSteps of
  [] -> []
  _:xs -> xs)

) $ reverse protoSteps)

let steps = zipWith3
(\(Step exec p e _ _) mCancel mRb -> Step exec p e mCancel mRb)
Expand Down
4 changes: 3 additions & 1 deletion src/Pact/ApiReq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ combineSigDatas sds outputLocal = do
when (S.size hashes /= 1 || S.size cmds /= 1) $ do
error "SigData files must contain exactly one unique hash and command. Aborting..."
let sigs = foldl1 f $ map _sigDataSigs sds
returnCommandIfDone outputLocal $ SigData (head $ S.toList hashes) sigs (Just $ head $ S.toList cmds)
case (S.toList cmds, S.toList hashes) of
(cmd:_, hash':_) -> returnCommandIfDone outputLocal $ SigData hash' sigs (Just cmd)
_ -> error "Expected nonempty lists of commands and hashes"
where
f accum sigs
| length accum /= length sigs = error "Sig lists have different lengths"
Expand Down
5 changes: 3 additions & 2 deletions src/Pact/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,9 @@ enforceAcyclic
-> Eval e [(Term (Either l r), key, [key])]
enforceAcyclic info cs = forM cs $ \c -> case c of
AcyclicSCC v -> return v
CyclicSCC vs -> do
let i = if null vs then info else _tInfo $ view _1 $ head vs
CyclicSCC [] -> error "Expected nonempty list"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous impl proceeded as usual binding i to info in this case if my brain is symbolic-executing the code right. Although I'm not sure if that makes sense given the semantics of this branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evalError or something else here, even if unreachable, just in case.

CyclicSCC vs@(v:_) -> do
let i = if null vs then info else _tInfo $ view _1 $ v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null vs shall always be False here, right? Also, I think you can drop this last $ before v.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, need to drop the if null if the above change is to make it in.

pl = over (traverse . _3) (SomeDoc . prettyList)
$ over (traverse . _1) (fmap mkSomeDoc)
$ vs
Expand Down
12 changes: 7 additions & 5 deletions src/Pact/PersistPactDb/Regression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ runRegression p = do
(commit v)
void $ begin v
tids <- _txids pactdb user1 t1 v
assertEquals "user txids" [1] tids
assertEquals' "user txlogs"
[TxLog "USER_user1" "key1" row,
TxLog "USER_user1" "key1" row'] $
_getTxLog pactdb usert (head tids) v
case tids of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we still check assertEquals "user txids" [1] tids?

tid:_ ->
assertEquals' "user txlogs"
[TxLog "USER_user1" "key1" row,
TxLog "USER_user1" "key1" row'] $
_getTxLog pactdb usert tid v
_ -> error "Expected nonempty list of tids"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there an assertFailure or something like this instead of error here?

_writeRow pactdb Insert usert "key2" row v
assertEquals' "user insert key2 pre-rollback" (Just row) (_readRow pactdb usert "key2" v)
assertEquals' "keys pre-rollback" ["key1","key2"] $ _keys pactdb (UserTables user1) v
Expand Down
4 changes: 2 additions & 2 deletions src/Pact/Server/History/Persistence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ selectCompletedCommands e v = foldM f HashMap.empty v
rs <- qrys (_qryCompletedStmt e) [hashToField $ unRequestKey rk] [RText,RInt,RInt]
if null rs
then return m
else case head rs of
[SText (Utf8 cr),SInt _, SInt _] ->
else case rs of
[SText (Utf8 cr),SInt _, SInt _]:_ ->
return $ HashMap.insert rk (crFromField cr) m
r -> dbError $ "Invalid result from query: " ++ show r

Expand Down
12 changes: 8 additions & 4 deletions src/Pact/Typechecker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,11 @@ toAST (TApp Term.App{..} _) = do
return app'
Resume -> do
app' <- specialBind
case head args' of -- 'specialBind' ensures non-empty args
(Binding _ _ _ (AstBindSchema sty)) ->
case Data.List.uncons args' of -- 'specialBind' ensures non-empty args
Just (Binding _ _ _ (AstBindSchema sty), _) ->
setOrAssocYR yrResume sty
a -> die'' a "Expected binding"
Just (a,_) -> die'' a "Expected binding"
Nothing -> error "Impossible case"
return app'
_ -> mkApp fun' args'

Expand Down Expand Up @@ -1204,7 +1205,10 @@ showFails = do

-- | unsafe lens for using `typecheckBody` with const
singLens :: Iso' a [a]
singLens = iso pure head
singLens = iso pure (\case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add HasCallStack constraint to this function to get better traces where it happened for debuggability (unless it's a hot spot, though I doubt it is).

x:_ -> x
[] -> error "Expected nonempty list"
)

-- | Typecheck a top-level production.
typecheck :: TopLevel Node -> TC (TopLevel Node)
Expand Down