Kindness is a virtue: changing precise AST kinds to support diffing, comments, partial passes and more!#486
Conversation
|
Update: none of the kind adjustments happened due to the new shape being in conflict with |
patrickt
left a comment
There was a problem hiding this comment.
A couple of things to iron out here, but on the whole this is looking really good! Huge kudos to you, @aymannadeem; I know that this was a Herculean level of effort. Once the various pragmas/pattern matches are ironed out, we’ll figure out when and where to merge this!
| # cabal v2-run --project-file=cabal.project.ci semantic-python:test:compiling | ||
| # cabal v2-run --project-file=cabal.project.ci semantic-python:test:graphing |
There was a problem hiding this comment.
We should consult with @joshvera and @BekaValentine about how/when we want to merge the efforts in this branch with the scope-graphing ones. We could make this branch based off of the stack graph one, or vice versa; either way, I’m happy to help with the plug-and-chug addition of Success branches.
There was a problem hiding this comment.
Happy to get this in and deal with the merge on the stack graph branch later.
|
|
||
| instance Applicative Err where | ||
| pure = Success | ||
| Fail e <*> _ = Fail e |
There was a problem hiding this comment.
Might be worth noting that this instance prefers the error message on the LHS of the <*> operator. Alternatively, we could do
data Err a = Fail (NonEmpty String) | Success a
and say that the Applicative instance over Fail concatenates the reasons for failure.
| Language.Python | ||
| Language.Python.AST | ||
| Language.Python.Core | ||
| -- Language.Python.Core |
There was a problem hiding this comment.
Can we file a bug to reenable the Core stuff (or elide it entirely for the time being)?
| docComment | ||
| src | ||
| ( Parse.Success | ||
| ( R1 |
There was a problem hiding this comment.
I think this combination of Success and R1 can be expressed with EPrj (and further on with that L1 pattern match).


This PR introduces refactors that simplify readability, and will also make it easier to transition ASTs to kind
(* -> *) -> (* -> *). This entails:f :: * -> *parameters for the record types, in TH, and add them to the generated datatypeTraversable,Foldable, andFunctorinstances to account for the new kindednessf(except for theannfield)Either StringUnmarshalWhy is this important?
This addresses #480, #481, #482.
TL;DR: it's a byproduct of having strongly-typed trees, where we can't take advantage of historic polymorphic-ness of our nodes and use
Errortypes everywhere.@patrickt explained this to me using the following example. Consider a data type like this which looks like the ALC syntax:
That type is polymorphic in its annotation type
a, but its children are monomorphic. They are alwaysExpressionvalues. And if we get a parse error fromtree-sitter, we can’t construct anExpression. Under a-la-carte syntax, all the children of a node were polymorphic, so we were able just to stick anErrornode in there. But our types are stronger now, so we can’t get away with just stuffingErrors everywhere. Instead, what we’re gonna generate is this:In this new precise world,
Plushas kind(* -> *) -> * -> *where the first parameterfis a “shape” functor that dictates what possible shapes the children could have. If we start substituting values forf, we get different types of trees. For example,Plus Identitymeans thatleft :: Identity (Expression Identity a),right :: Identity (Expression Identity a).Since
Identity ais isomorphic toa, that meansPlus Identityis isomorphic to our old definition ofPlus.But what happens when we start getting some more interesting functors? Let’s consider
Plus (Either String). Substituting inEither Stringforf, that leaves us with children that look likeleft :: Either String (Expression (Either String) a),right :: Either String (Expression (Either String) a)and that lets us handle parse errors. The left field isRightif the parse succeeded andLeftif it failed. This means we can slurp a partial or erroneous tree via Unmarshal.This PR also has a few additional changes that are:
conTinstead ofConT); introducing constructor names in signatures that otherwise had ambiguous types (ex.,DatatypeNameinstead ofString).