Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Introduce the beginning of the scope graph API #497

Merged
merged 11 commits into from
Mar 5, 2020
Merged

Conversation

tclem
Copy link
Member

@tclem tclem commented Feb 21, 2020

Implements the external API plumbing to support producing incremental scope graphs for blobs.

import Serializing.Format (Format)
import Source.Loc as Loc

parseScopeGraph :: ( Has Distribute sig m
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, Distribute is going away soon, as it doesn’t do what it says on the tin (#40), so I wouldn’t introduce it here. If you need to use mapConcurrently, do it in IO if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Left this alone for now as I found it tricky to mix and match task, effects, and things just in IO. This matches existing handling in existing api endpoints, and we've scope threaded to see green thread behavior on this a couple of times.

import Source.Loc as Loc

parseScopeGraph :: ( Has Distribute sig m
, Has (Error SomeException) sig m
Copy link
Contributor

@patrickt patrickt Feb 21, 2020

Choose a reason for hiding this comment

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

Error SomeException is kind of an antipattern, as it is often much too general. Unless we’re planning to throw this interface away, can we stub out a ScopeGraphParseError type or something and use it instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This attempting to protect from any error that might occur in parsing and generating a graph for a single file. One file failing shouldn't bring down the entire response, instead we return the rest of the results and an error placeholder for the failed one.

@@ -174,3 +178,30 @@ message Span {
Position start = 1;
Position end = 2;
}

message ScopeGraphFile {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you consider StackGraphFile for this? @joshvera and @dcreager and I settled on the term “stack graph” rather than “scope graph” to distinguish the Scopes Describe Frames graph structure from the one outlined in our design doc, and I think it’s preferable to use the more precise terminology.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 let me rename these all to StackGraph*

int32 id = 1;
string name = 2;
string line = 3;
string syntax = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does syntax mean in this context? Does this describe the node type (push, pop, etc?) If so I imagine we’ll do some parsing when converting to the native data type.

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'm going to rename this to kind (which is what we call this in the other proto responses) - It's essential the name of the syntax term (Function, Call, etc).

}

message ScopeGraphPath {
string starting_symbol_stack = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

These will be encoded values too, right? Colon-separated or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, these are currently stacks encoded and using ascii delimiters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to have this be a repeated string instead? Are we using different ascii characters as different delimiters, or as sigils at the beginning of a symbol name to indicate its type? If the former, this is worth a comment describing the format more precisely since it becomes part of the API contract. If the latter that would line up well with repeated string, and then only aleph would need to know specifically how we turn the list of symbols on the stack into a scalar string in the db. And the per-language stack graph generators would have full flexibility to choose sigils and whatnot as needed for the language.

}

message ScopeGraphNode {
int32 id = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI Haskell native Int is 64-bits wide, so we could have slightly more efficient conversion (no fromIntegral upcasting) if we went with int64.

pure $ defMessage & P.files .~ toList terms
where
go :: (Has (Error SomeException) sig m, Has Parse sig m) => Blob -> m ScopeGraphFile
go blob = catching $ graphToFile <$> graphForBlob blob
Copy link
Contributor

Choose a reason for hiding this comment

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

Really elegant definition 👍

@tclem tclem merged commit a09b34d into master Mar 5, 2020
@tclem tclem deleted the incremental-sg-api branch March 5, 2020 17:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants