-
Notifications
You must be signed in to change notification settings - Fork 21
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
Change Edge::label
from optional to required
#1205
base: main
Are you sure you want to change the base?
Change Edge::label
from optional to required
#1205
Conversation
This involves a couple of changes outside of just changing the field type: 1. `CursorIterator` must be able to produce a label for every node now. This wasn't possible before because the root nodes of a cursor had no parent, and so could not derive a label. I've changed `Cursor` in the following ways to fix this: * `Cursor::parent` is a new type, `Parent<T>`, instead of `Option<Rc<PathAncestor<T>>>`. `Parent<T>` is an enum with three variants - `None`, `Open(Rc<PathAncestor<T>>)`, and `Closed(Rc<PathAncestor<T>>)`. A `Closed` parent is used when a cursor is spawned from an arbitrary non-root node, and means that the parent can be read but not traversed to. `None` is only used for the true root node. 2. `KindTypes::EdgeLabel` is given a `Default` implementation, which for now just returns the first `PredefinedLabel` variant. This is needed in order to be able to set a "concrete" `EdgeLabel` value from the `metaslang_cst` crate. 3. Added a `Root` variant to `PredefinedLabel`. This will be used when a node is the true root node. For now this will be the default value for `KindTypes::EdgeLabel`.
🦋 Changeset detectedLatest commit: 68614b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
crates/codegen/runtime/cargo/crate/src/runtime/cst/edge_label.rs.jinja2
Outdated
Show resolved
Hide resolved
crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/cst.wit
Outdated
Show resolved
Hide resolved
crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/cst.wit
Outdated
Show resolved
Hide resolved
crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/generated/selectors.rs
Outdated
Show resolved
Hide resolved
crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/generated/selectors.rs
Outdated
Show resolved
Hide resolved
crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/cst/mod.rs
Outdated
Show resolved
Hide resolved
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.
Thanks for working on this!
.../testing/snapshots/cst_output/Block/postfix_recovery_regression/generated/0.4.11-failure.yml
Outdated
Show resolved
Hide resolved
...ots/cst_output/Statements/recovery_ignore_multiple_empty_matches/generated/0.6.0-failure.yml
Outdated
Show resolved
Hide resolved
…ted/cst.wit Co-authored-by: Omar Tawfik <[email protected]>
…rs.jinja2 Co-authored-by: Omar Tawfik <[email protected]>
…ted/cst.wit Co-authored-by: Omar Tawfik <[email protected]>
…geLabel, Node)>`
…o `Parent::Disconnected` * Change the inner type of `Parent::Disconnected` from another PathAncestor to `T::EdgeLabel` so that an ancestor can't be misused
I've added an All the other comments should be addressed now so this PR is ready for another review. |
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.
Made another pass on all unresoved comments.
Thanks!
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.
I think there is one unresolved comment still: #1205 (comment)
So, for the time being, WDYT of adding a similar EdgeLabel::MISSING for now, so that we don't mislabel them as root in the meantime?
Additionally, I suggest adding a changeset to describe the changes here.
Thanks!
Wasn't that added to the backlog as #1215? I thought that that was going to be resolved in the future. |
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.
I believe there are a few root
labels in sub-trees still. For example, root꞉ Comma
in
crates/solidity/testing/snapshots/cst_output/ContractMembers/separated_recovery/generated/0.6.0-failure.yml
.
Maybe to catch such cases, we can add a check in crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs
to make sure we never put Label::default()
in sub-trees. Thoughts?
let cursor = output.create_tree_cursor();
while cursor.go_to_next() {
assert!(!cursor.label.is_default());
}
…the current node is the root and if it has the default label * Use these utility functions in `cst_output/runner.rs` to assert that child nodes never have the default label (`root`).
I added the assertion but haven't fixed the issue, so some tests should be failing right now. I've found some places where the Using this I narrowed down the failures to three test cases:
These all occur in the context of a parsing failure, and the node given the @OmarTawfik do you have any thoughts on these? |
@mjoerussell Thanks for the analysis! I think there are two separate issues here: For For For example, in
But instead, because of the current implementation, the three children are promoted to the top - (root꞉ Expression): # "2 * new\n" (0..8)
- (variant꞉ DecimalNumberExpression) ► (literal꞉ DecimalLiteral): "2" # (0..1)
- (root꞉ MultiplicativeExpression): # " *" (1..3)
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (operator꞉ Asterisk): "*" # (2..3)
- (variant꞉ NewExpression): # " new\n" (3..8)
- (leading_trivia꞉ Whitespace): " " # (3..4)
- (new_keyword꞉ NewKeyword): "new" # (4..7)
- (trailing_trivia꞉ EndOfLine): "\n" # (7..8)
- (missing꞉ MISSING): "" # (8..8) I'm not sure what is the exact fix for |
This was exactly the issue, and it was a pretty simple fix to get this case working again.
I don't think that there's an issue with |
@OmarTawfik Diving into If it's OK with you, I can fix the current errors by forcing the flattened pratt expressions to be given a different label, perhaps |
…root node of the flattened expression the label `Unrecognized` instead of `Root`.
Since the current labels we produce are already inaccurate, so changing it to |
This involves a couple of changes outside of just changing the field type:
CursorIterator
must be able to produce a label for every node now. This wasn't possible before because the root nodes of a cursor had no parent, and so could not derive a label. I've changedCursor
in the following ways to fix this:Cursor::parent
is a new type,Parent<T>
, instead ofOption<Rc<PathAncestor<T>>>
.Parent<T>
is an enum with three variants -None
,Open(Rc<PathAncestor<T>>)
, andClosed(Rc<PathAncestor<T>>)
. AClosed
parent is used when a cursor is spawned from an arbitrary non-root node, and means that the parent can be read but not traversed to.None
is only used for the true root node.KindTypes::EdgeLabel
is given aDefault
implementation, which for now just returns the firstPredefinedLabel
variant. This is needed in order to be able to set a "concrete"EdgeLabel
value from themetaslang_cst
crate.Root
variant toPredefinedLabel
. This will be used when a node is the true root node. For now this will be the default value forKindTypes::EdgeLabel
.Closes #815