Skip to content

Extract Spaces refactor / cleanup#7470

Closed
gamebox wants to merge 2 commits intoroc-lang:mainfrom
gamebox:extract-spaces-refactor
Closed

Extract Spaces refactor / cleanup#7470
gamebox wants to merge 2 commits intoroc-lang:mainfrom
gamebox:extract-spaces-refactor

Conversation

@gamebox
Copy link
Collaborator

@gamebox gamebox commented Jan 5, 2025

Have extract_spaces method of ExtractSpaces trait take an arena so that:

  1. We can remove a lot of todo!()s.
  2. Recursively collapse several layers of SpaceBefore/SpaceAfter into a single Spaces.
  3. Avoid some fuzzer panics (but not all).

if matches!(loc_ann.extract_spaces().item, TypeAnnotation::Wildcard)
&& matches!(ext_problem_kind, ExtensionTypeKind::TagUnion)
if matches!(
loc_ann.extract_spaces(env.arena).item,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be changed to use loc_ann.without_spaces(), since we don't care about the spaces part. Ditto for other cases where we discard the spaces. This way we can avoid unnecessary allocation.

I'm ok doing that in this PR or in a separate PR.

beginning_of_line: bool,
line_indent: u16,
flags: MigrationFlags,
pub arena: &'a Bump,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You actually don't need this - you can just access self.text.bump()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had ownership issue using that....

Comment on lines 2346 to 2207
match self {
$t::SpaceBefore(item, before) => {
match item {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than doing a strict 2-level match here, we should change to doing a recursive call, similar to what happens in expr_lift_spaces (and similar functions) from the formatter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this not recursive? We call extract spaces on the item on line 2354

after,
},
AbilityImpls::SpaceAfter(_, _) => todo!(),
sb @ AbilityImpls::SpaceBefore(_, _) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to use impl_extract_spaces! to handle this type?

Have extract_spaces method of ExtractSpaces trait take an arena so that:

1. We can remove a lot of `todo!()`s.
2. Recursively collapse several layers of SpaceBefore/SpaceAfter into a
   single Spaces.
3. Avoid some fuzzer panics (but not all).

Rename new snapshot
@gamebox gamebox force-pushed the extract-spaces-refactor branch from 006c17b to 8dea8a2 Compare January 14, 2025 15:40
@gamebox
Copy link
Collaborator Author

gamebox commented Jan 14, 2025

@joshuawarner32 This still has one failure - one that i introduce because I was worried about dbg and PNC apply ambiguity. Something doesn't feel right about DbgStmt to me anymore....

@github-actions
Copy link

Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked Closed are not deleted, so no matter what, the PR will still be right here in the repo. You can always access it and reopen it anytime you like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants