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

ast: Replace can_parse with static dispatch #10373

Merged
merged 1 commit into from Mar 16, 2024

Conversation

The0x539
Copy link
Contributor

Description

My original goal was to get rid of the None variants on StatementVariant and BlockStatementHeaderVariant, but I discovered that that would require a larger refactor.
This change stands on its own, but doubles as a small step towards that refactor by reducing our reliance on "uninitialized" node values.

No intended behavior changes, but I wouldn't be surprised by a minor performance boost.

TODOs:

  • User-visible changes noted in CHANGELOG.rst

@The0x539
Copy link
Contributor Author

I have no idea why make test / ubuntu-asan keeps failing.

@Xiretza
Copy link
Contributor

Xiretza commented Mar 15, 2024

Known issue, nothing to do with your PR.

trait CheckParse {
/// A true return means we should descend into the production, false means stop.
fn can_be_parsed(pop: &mut Populator<'_>) -> bool;
}
Copy link
Member

Choose a reason for hiding this comment

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

Really nice work.

Getting rid of virtual dispatch seems like a good direction, a big one would be #9636 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll look into that once this step is merged.
I'm quite fond of enum_dispatch, but it might not be the best fit here. A custom macro (perhaps with the help of paste) would allow us to deduplicate more code (I'm mostly thinking about the downcasting).

Copy link
Member

Choose a reason for hiding this comment

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

possibly but we also need to implement generic methods like Node::typ() and Node::source_range(), ideally without splitting the node definition paragraphs.

My original goal was to get rid of the None variants on StatementVariant and BlockStatementHeaderVariant, but I discovered that that would require a larger refactor.

One problem is that those union nodes are not real nodes. It's unclear if they should be but the status quo requires a lot of boilerplate that even spreads to macros (visit_union_field_mut).
Maybe we should remove union nodes like Statement and replace them with something that's not a full node but simply delegates to the concrete statement.

src/ast.rs Outdated Show resolved Hide resolved
src/ast.rs Outdated Show resolved Hide resolved
src/ast.rs Show resolved Hide resolved
@krobelus krobelus merged commit b8d1dc9 into fish-shell:master Mar 16, 2024
5 of 7 checks passed
@zanchey zanchey added the rust label Mar 16, 2024
@zanchey zanchey added this to the fish next-3.x milestone Mar 16, 2024
@The0x539 The0x539 deleted the ast-changes branch March 19, 2024 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants