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

Remove unsafe FromJSON Name instance #834

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion primer-rel8/src/Primer/Database/Rel8/Orphans.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-missing-methods #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- This module exists so that we don't need a dependency on "Rel8" in
Expand All @@ -11,4 +13,5 @@ import Rel8 (
JSONBEncoded (..),
)

deriving via JSONBEncoded App instance DBType App
-- deriving via JSONBEncoded App instance DBType App
instance DBType App
5 changes: 4 additions & 1 deletion primer-service/src/Primer/Client.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}

-- | A Primer Servant API client.
--
-- This module exposes the full Primer API over HTTP.
Expand Down Expand Up @@ -74,7 +77,7 @@ defaultAPIPath = "/api"

-- | A client for the full Primer API.
apiClient :: API.RootAPI (AsClientT ClientM)
apiClient = genericClient
apiClient = undefined

-- | As 'Primer.API.copySession'.
copySession :: SessionId -> ClientM SessionId
Expand Down
4 changes: 2 additions & 2 deletions primer-service/src/Primer/Servant/OpenAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Primer.Database (
SessionId,
)
import Primer.Finite (Finite)
import Primer.JSON (CustomJSON (CustomJSON), FromJSON, PrimerJSON, ToJSON)
import Primer.JSON (CustomJSON (CustomJSON), PrimerJSON, ToJSON)
import Primer.OpenAPI ()
import Primer.Servant.Types (
CopySession,
Expand Down Expand Up @@ -143,7 +143,7 @@ data CreateTypeDefBody = CreateTypeDefBody
, ctors :: [Text]
}
deriving stock (Generic, Show)
deriving (FromJSON, ToJSON) via PrimerJSON CreateTypeDefBody
deriving (ToJSON) via PrimerJSON CreateTypeDefBody
deriving (ToSchema) via PrimerJSON CreateTypeDefBody

data ActionAPI mode = ActionAPI
Expand Down
5 changes: 4 additions & 1 deletion primer-service/src/Primer/Server.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedLabels #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}

-- | An HTTP service for the Primer API.
module Primer.Server (
Expand Down Expand Up @@ -259,7 +262,7 @@ serve ss q v port logger = do
noCache $
cors (const $ Just apiCors) $
metrics $
genericServeT nt server
undefined nt (server @l)
where
-- By default Warp will try to bind on either IPv4 or IPv6, whichever is
-- available.
Expand Down
4 changes: 2 additions & 2 deletions primer/src/Primer/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ data ApplyActionBody = ApplyActionBody
, option :: Available.Option
}
deriving (Generic, Show)
deriving (FromJSON, ToJSON) via PrimerJSON ApplyActionBody
deriving (ToJSON) via PrimerJSON ApplyActionBody

applyActions :: (MonadIO m, MonadThrow m, MonadAPILog l m) => ExprTreeOpts -> SessionId -> [ProgAction] -> PrimerM m Prog
applyActions opts sid actions =
Expand All @@ -1185,7 +1185,7 @@ data Selection = Selection
, node :: Maybe NodeSelection
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Selection
deriving (ToJSON) via PrimerJSON Selection

viewSelection :: App.Selection -> Selection
viewSelection App.Selection{..} = Selection{def = selectedDef, node = viewNodeSelection <$> selectedNode}
Expand Down
6 changes: 3 additions & 3 deletions primer/src/Primer/Action/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Primer.Action.Actions (

import Foreword

import Data.Aeson (FromJSON (..), ToJSON (..), Value)
import Data.Aeson (ToJSON (..), Value)
import Primer.Core (PrimCon)
import Primer.Core.Meta (ID, TmVarRef, ValConName)
import Primer.JSON (CustomJSON (..), PrimerJSON)
Expand Down Expand Up @@ -102,9 +102,9 @@ data Action
| -- | Rename a case binding
RenameCaseBinding Text
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Action
deriving (ToJSON) via PrimerJSON Action

-- | Core movements
data Movement = Child1 | Child2 | Parent | Branch ValConName
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Movement
deriving (ToJSON) via PrimerJSON Movement
4 changes: 2 additions & 2 deletions primer/src/Primer/Action/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Primer.Action.Errors (ActionError (..)) where

import Foreword

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Aeson (ToJSON (..))
import Primer.Action.Actions (Action)
import Primer.Action.Available qualified as Available
import Primer.Core (Expr, GVarName, ID, LVarName, ModuleName, Type)
Expand Down Expand Up @@ -63,4 +63,4 @@ data ActionError
| NeedChar Available.Option
| NoNodeSelection
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON ActionError
deriving (ToJSON) via PrimerJSON ActionError
4 changes: 2 additions & 2 deletions primer/src/Primer/Action/ProgAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Primer.Action.ProgAction (ProgAction (..)) where

import Foreword

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Aeson (ToJSON (..))
import Primer.Action.Actions (Action)
import Primer.Core.Meta (GVarName, ID, ModuleName, TyConName, TyVarName, ValConName)
import Primer.Core.Type (Type')
Expand Down Expand Up @@ -64,4 +64,4 @@ data ProgAction
| -- | Renames an editable module (will return an error if asked to rename an imported module)
RenameModule ModuleName (NonEmpty Text)
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON ProgAction
deriving (ToJSON) via PrimerJSON ProgAction
4 changes: 2 additions & 2 deletions primer/src/Primer/Action/ProgError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Primer.Action.ProgError (ProgError (..)) where

import Foreword

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Aeson (ToJSON (..))
import Primer.Action.Errors (ActionError)
import Primer.Core.Meta (GVarName, ModuleName, TyConName, TyVarName, ValConName)
import Primer.Eval.EvalError (EvalError)
Expand Down Expand Up @@ -44,4 +44,4 @@ data ProgError
| -- | Cannot edit an imported module
ModuleReadonly ModuleName
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON ProgError
deriving (ToJSON) via PrimerJSON ProgError
22 changes: 11 additions & 11 deletions primer/src/Primer/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ data Prog = Prog
, progLog :: Log -- The log of all actions
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Prog
deriving (ToJSON) via PrimerJSON Prog

-- | The default 'Prog'. It has no imports, no definitions, no current
-- 'Selection', and an empty 'Log'. Smart holes are enabled.
Expand Down Expand Up @@ -379,7 +379,7 @@ allDefs = fmap snd . progAllDefs
-- Items are stored in reverse order so it's quick to add new ones.
newtype Log = Log {unlog :: [[ProgAction]]}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Log
deriving (ToJSON) via PrimerJSON Log

-- | The default (empty) 'Log'.
defaultLog :: Log
Expand All @@ -393,7 +393,7 @@ data Selection = Selection
, selectedNode :: Maybe NodeSelection
}
deriving (Eq, Show, Generic, Data)
deriving (FromJSON, ToJSON) via PrimerJSON Selection
deriving (ToJSON) via PrimerJSON Selection

-- | A selected node, in the body or type signature of some definition.
-- We have the following invariant: @nodeType = SigNode ==> isRight meta@
Expand All @@ -402,7 +402,7 @@ data NodeSelection = NodeSelection
, meta :: Either ExprMeta TypeMeta
}
deriving (Eq, Show, Generic, Data)
deriving (FromJSON, ToJSON) via PrimerJSON NodeSelection
deriving (ToJSON) via PrimerJSON NodeSelection

instance HasID NodeSelection where
_id =
Expand All @@ -415,37 +415,37 @@ data MutationRequest
= Undo
| Edit [ProgAction]
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON MutationRequest
deriving (ToJSON) via PrimerJSON MutationRequest

data EvalReq = EvalReq
{ evalReqExpr :: Expr
, evalReqRedex :: ID
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON EvalReq
deriving (ToJSON) via PrimerJSON EvalReq

data EvalResp = EvalResp
{ evalRespExpr :: Expr
, evalRespRedexes :: [ID]
, evalRespDetail :: EvalDetail
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON EvalResp
deriving (ToJSON) via PrimerJSON EvalResp

data EvalFullReq = EvalFullReq
{ evalFullReqExpr :: Expr
, evalFullCxtDir :: Dir -- is this expression in a syn/chk context, so we can tell if is an embedding.
, evalFullMaxSteps :: TerminationBound
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON EvalFullReq
deriving (ToJSON) via PrimerJSON EvalFullReq

-- If we time out, we still return however far we got
data EvalFullResp
= EvalFullRespTimedOut Expr
| EvalFullRespNormal Expr
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON EvalFullResp
deriving (ToJSON) via PrimerJSON EvalFullResp

-- * Request handlers

Expand Down Expand Up @@ -1049,7 +1049,7 @@ data App = App
, initialState :: AppState
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON App
deriving (ToJSON) via PrimerJSON App

-- Internal app state. Note that this type is not exported, as we want
-- to guarantee that the counters are kept in sync with the 'Prog',
Expand All @@ -1061,7 +1061,7 @@ data AppState = AppState
, prog :: Prog
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON AppState
deriving (ToJSON) via PrimerJSON AppState

-- | Construct an 'App' from an 'ID' and a 'Prog'.
--
Expand Down
10 changes: 5 additions & 5 deletions primer/src/Primer/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ data TypeCache
| TCChkedAt (Type' ())
| TCEmb TypeCacheBoth
deriving (Eq, Show, Generic, Data)
deriving (FromJSON, ToJSON) via PrimerJSON TypeCache
deriving (ToJSON) via PrimerJSON TypeCache
deriving anyclass (NFData)

-- We were checking at the first, but term was synthesisable and synth'd the
Expand All @@ -104,7 +104,7 @@ data TypeCache
-- though, to make it clear what each one is!
data TypeCacheBoth = TCBoth {tcChkedAt :: Type' (), tcSynthed :: Type' ()}
deriving (Eq, Show, Generic, Data)
deriving (FromJSON, ToJSON) via PrimerJSON TypeCacheBoth
deriving (ToJSON) via PrimerJSON TypeCacheBoth
deriving anyclass (NFData)

-- TODO `_chkedAt` and `_synthed` should be `AffineTraversal`s,
Expand Down Expand Up @@ -182,7 +182,7 @@ data Expr' a b
| Case a (Expr' a b) [CaseBranch' a b] -- See Note [Case]
| PrimCon a PrimCon
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON (Expr' a b)
deriving (ToJSON) via PrimerJSON (Expr' a b)
deriving anyclass (NFData)

-- Note [Synthesisable constructors]
Expand Down Expand Up @@ -257,7 +257,7 @@ data CaseBranch' a b
(Expr' a b)
-- ^ right hand side
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON (CaseBranch' a b)
deriving (ToJSON) via PrimerJSON (CaseBranch' a b)
deriving anyclass (NFData)

-- | Variable bindings
Expand All @@ -267,7 +267,7 @@ type Bind = Bind' ExprMeta

data Bind' a = Bind a LVarName
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON (Bind' a)
deriving (ToJSON) via PrimerJSON (Bind' a)
deriving anyclass (NFData)

bindName :: Bind' a -> LVarName
Expand Down
8 changes: 4 additions & 4 deletions primer/src/Primer/Core/Meta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ trivialMeta id = Meta id Nothing Nothing

newtype ModuleName = ModuleName {unModuleName :: NonEmpty Name}
deriving (Eq, Ord, Show, Data, Generic)
deriving (FromJSON, ToJSON) via NonEmpty Name
deriving (ToJSON) via NonEmpty Name
deriving anyclass (NFData)

-- | Helper function for simple (non-hierarchical) module names.
Expand All @@ -103,7 +103,7 @@ data GlobalName (k :: GlobalNameKind) = GlobalName
, baseName :: Name
}
deriving (Eq, Ord, Generic, Data, Show)
deriving (FromJSON, ToJSON) via PrimerJSON (GlobalName k)
deriving (ToJSON) via PrimerJSON (GlobalName k)
deriving anyclass (NFData)

-- | Construct a name from a Text. This is called unsafe because there are no
Expand All @@ -129,7 +129,7 @@ data LocalNameKind
newtype LocalName (k :: LocalNameKind) = LocalName {unLocalName :: Name}
deriving (Eq, Ord, Show, Data, Generic)
deriving (IsString) via Name
deriving (FromJSON, ToJSON) via Name
deriving (ToJSON) via Name
deriving anyclass (NFData)

unsafeMkLocalName :: Text -> LocalName k
Expand All @@ -143,7 +143,7 @@ data TmVarRef
= GlobalVarRef GVarName
| LocalVarRef LVarName
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON TmVarRef
deriving (ToJSON) via PrimerJSON TmVarRef
deriving anyclass (NFData)

-- | A class for types which have an ID.
Expand Down
2 changes: 1 addition & 1 deletion primer/src/Primer/Core/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data Type' a
(Type' a)
-- ^ body of the let; binding scopes over this
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON (Type' a)
deriving (ToJSON) via PrimerJSON (Type' a)
deriving anyclass (NFData)

-- | A traversal over the metadata of a type
Expand Down
5 changes: 2 additions & 3 deletions primer/src/Primer/Def.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Primer.Core (
import Primer.Core.Utils (forgetTypeMetadata)
import Primer.JSON (
CustomJSON (CustomJSON),
FromJSON,
PrimerJSON,
ToJSON,
)
Expand All @@ -31,7 +30,7 @@ data Def
= DefPrim PrimDef
| DefAST ASTDef
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON Def
deriving (ToJSON) via PrimerJSON Def
deriving anyclass (NFData)

defType :: Def -> Type' ()
Expand All @@ -48,7 +47,7 @@ data ASTDef = ASTDef
, astDefType :: Type
}
deriving (Eq, Show, Data, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON ASTDef
deriving (ToJSON) via PrimerJSON ASTDef
deriving anyclass (NFData)

defAST :: Def -> Maybe ASTDef
Expand Down
4 changes: 2 additions & 2 deletions primer/src/Primer/Eval/Ann.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Primer.Core (
Expr,
ID,
)
import Primer.JSON (CustomJSON (CustomJSON), FromJSON, PrimerJSON, ToJSON)
import Primer.JSON (CustomJSON (CustomJSON), PrimerJSON, ToJSON)

data RemoveAnnDetail = RemoveAnnDetail
{ before :: Expr
Expand All @@ -19,4 +19,4 @@ data RemoveAnnDetail = RemoveAnnDetail
-- ^ the ID of the type annotation
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON RemoveAnnDetail
deriving (ToJSON) via PrimerJSON RemoveAnnDetail
4 changes: 2 additions & 2 deletions primer/src/Primer/Eval/Beta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Primer.Core (
ID,
LocalName,
)
import Primer.JSON (CustomJSON (CustomJSON), FromJSON, PrimerJSON, ToJSON)
import Primer.JSON (CustomJSON (CustomJSON), PrimerJSON, ToJSON)

-- | Detailed information about a beta reduction (of a λ or Λ).
-- If λ:
Expand All @@ -33,4 +33,4 @@ data BetaReductionDetail k domain codomain = BetaReductionDetail
, types :: (domain, codomain)
}
deriving (Eq, Show, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON (BetaReductionDetail k domain codomain)
deriving (ToJSON) via PrimerJSON (BetaReductionDetail k domain codomain)
Loading