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

Remove some unnecessary Piece classes. #1491

Merged
merged 6 commits into from
May 20, 2024
Merged

Remove some unnecessary Piece classes. #1491

merged 6 commits into from
May 20, 2024

Conversation

munificent
Copy link
Member

@munificent munificent commented May 17, 2024

In exploring various optimizations, it's clear that I'll probably need to make some changes to how all of the Piece classes work. The more of those classes there are, the harder that work is.

Fortunately, there are a few Piece classes that don't really need to exist. Most were created before we had AdjacentPiece or the ability to insert spaces between pieces.

Each commit in this PR removes a Piece class or otherwise simplifies them.

In exploring various optimizations, it's clear that I'll probably need
to make some changes to how all of the Piece classes work. The more of
those classes there are, the harder that work is.

Fortunately, there are a few Piece classes that don't really need to
exist. Most were created before we had AdjacentPiece or the ability to
insert spaces between pieces.

This first commit removes ClausePiece which it turns out behaves exactly
like InfixPiece (and then renames ClausesPiece to ClausePiece).
All it did was write its children with some spaces between them.
It was just like InfixPiece but without a first operand. But it's only
used by imports, where we can use the import header as the first operand
and just use InfixPiece.
It's just an InfixPiece that always splits.
Once you hoist out the optionality of the guard, it's just an
InfixPiece.
Make that Piece just for the header part of a for statement or element.
(We can almost get rid of this entirely and use AdjacentPiece, but it
does some indentation that isn't otherwise supported.)

Then to handle the body, we either write it inline if it's a block (the
most common), or we use IfPiece, which has the same logic. Rename
IfPiece to ControlFlowPiece to emphasize its more general use. It was
already used for while statements, so this makes sense.
@munificent munificent merged commit f8c285f into main May 20, 2024
7 checks passed
@munificent munificent deleted the unneeded-pieces branch May 20, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants