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

App spec json #2284

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

App spec json #2284

wants to merge 13 commits into from

Conversation

Martinsos
Copy link
Member

@Martinsos Martinsos commented Sep 15, 2024

@sodic please take this one and finish it! I think I got it quite far: check TODOs in the code, and see how usable is it for you.

Copy link
Member Author

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

@sodic there is a lot of small, boring changes, so I commented here on all the changes that are actually interesting, so you don't have to wonder if you missed any among the boredoom of the rest.

takeDecls,
makeDecl,
fromDecl,
)
where

import Data.Maybe (mapMaybe)
import Data.Typeable (Typeable, cast)

class (Typeable a) => IsDecl a
Copy link
Member Author

Choose a reason for hiding this comment

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

I took IsDecl from here to its own file to avoid circular dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the main logic (well, generated by TH, which is in JSON/TH.hs file). TH logic has to be in another file (in JSON/TH.hs), GHC demanded it, has to do with order in which stuff is compiled.
In this file are the main TODOs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw cool trick I learned: add {-# OPTIONS_GHC -ddump-splices #-} at the top, run cabal build, and you will, in compiler output in stdout, the contents of this file as generated by TH.


import Data.Typeable (Proxy (Proxy), Typeable, typeRep)

class (Typeable a) => IsDecl a where
Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned above, I just moved this from Decl.hs to here, in this standalone file, to avoid circ deps.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which ones?

@@ -25,3 +27,16 @@ deriving instance (IsDecl a, Data a) => Data (Ref a)

refName :: Ref a -> String
refName (Ref name) = name

instance (IsDecl a) => FromJSON (Ref a) where
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we expect JSON to contain not just the declaration identifier name, but also its declaration type. We could drop that if we want, but then all identifiers need to be unique and I actually wasn't sure if that is so now. Also I thought it can't hurt.

@@ -30,6 +31,9 @@ data Entity = Entity

instance IsDecl Entity

instance FromJSON Entity where
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't allow defining entities via Wasp file any more, but we left some of the old machinery in for now since it was easier then purging it, so I just put this error here, I think this should be quite fine for now.

deriving (Show, Eq, Data)
deriving (Show, Eq, Data, Generic)

instance FromJSON ExtImport where
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I manually implemented JSON parsing in order to explain how to parse the StrongPath in question.

Copy link
Contributor

@sodic sodic left a comment

Choose a reason for hiding this comment

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

Leaving some comments for myself.

Comment on lines 1 to 2
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these here? Probably not.

Comment on lines 1 to 2
{-# LANGUAGE TypeApplications #-} -- Needed by generateFromJsonInstanceForDecl (TH)
{-# OPTIONS_GHC -Wno-orphans #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Check why we need this.


import Data.Typeable (Proxy (Proxy), Typeable, typeRep)

class (Typeable a) => IsDecl a where
Copy link
Contributor

Choose a reason for hiding this comment

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

Which ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants