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

Extract Spaces refactor / cleanup #7470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.

@@ -21,6 +21,7 @@ pub struct Buf<'a> {
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

AbilityImpls::SpaceAfter(AbilityImpls::AbilityImpls(inner), after) => Spaces {
before,
item: *inner,
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....

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.

3 participants