-
Notifications
You must be signed in to change notification settings - Fork 52
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
Annotate ASTs with types at every node #991
Conversation
- Split out `Swarm.Language.Module`, put annotated AST in a `Module` - Update module typechecking appropriately - Still some `undefined` things that need to be filled in!
Need to rewrite `elaborate`.
Getting very bogged down. Might need to throw this code away and start again with some kind of more principled approach...
mkProg = TApp (TConst Make) (TText (e ^. entityName)) | ||
mkPT = ProcessedTerm mkProg (Module mkTy empty) mkReq empty | ||
let name = e ^. entityName | ||
mkPT = [tmQ| make $str:name |] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of TH! 👍
src/Swarm/Language/Syntax.hs
Outdated
pattern Syntax :: SrcLoc -> Term -> Syntax | ||
pattern Syntax l t = Syntax' l t () | ||
|
||
{-# COMPLETE Syntax #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does COMPLETE
do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It specifies a set of constructors/pattern synonyms which should be considered "complete" for the purposes of pattern match coverage checking. i.e. if you pattern-match on everything listed in the COMPLETE
pragma then GHC will not warn about missing cases. Using COMPLETE
is common when creating pattern synonyms since there's no way in general to know whether an arbitrary set of pattern synonyms is going to cover all possible cases, so without the pragma in general GHC will generate lots of warnings about incomplete pattern matches.
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complete-pragmas
`Testing/479-atomic` timed out, not sure why.
Was accidentally deleting the `atomic` constant.
I've realized a big issue with the way this works: in particular it doesn't make sense to annotate every node of the AST with a |
@byorgey won't every definition and let binding have a I would not mind if the type was stored in the |
Yes, they should. Still trying to figure out a good way to annotate different things with |
@byorgey could you merge this as is and improve on it in the main branch? 🙂 The types are morally wrong with the I would like to rebase and merge my OnHover rework and the types added here are invaluable. Not that I am in a rush, I just don't want to have merge conflicts with @kostmo if he works on the LSP further. 😅 |
You're right, I will do that. Can't let the perfect become the enemy of the good. 😄 |
As discussed above, we can merge this as-is now, and I've created #1042 for tracking the remaining issue. |
Co-authored-by: Restyled.io <[email protected]>
test/unit/TestLanguagePipeline.hs
Outdated
|
||
isVar (TVar {}) = True | ||
isVar _ = False | ||
getVars = map (_sTerm &&& _sType) . filter (isVar . _sTerm) . universe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
universe
🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See, I put that in there on purpose to give people ideas. 😄 https://hackage.haskell.org/package/lens-5.2/docs/Control-Lens-Plated.html has some pretty powerful tools for working with ASTs.
Values of type
Syntax
are as before: parsed syntax, with each node annotated withSrcLoc
.Values of type
Syntax' Polytype
, however, have each node annotated with both aSrcLoc
and aPolytype
. (Syntax
is really just a synonym forSyntax' ()
.)Type inference takes a
Syntax
and outputs aTModule
, which now contains aSyntax' Polytype
, in other words, a new version of the AST where every node has been annotated with the inferred type of the subterm rooted there.Why is this useful?
OnHover
LSP handler, e.g. to show the type of the term under the mouse.I imagine the code changes might look kind of intimidating but I don't think it's really that bad once you understand what is going on, so I'm happy to answer any questions or explain anything.