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

Handle missing comma i func params #3014

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Mar 12, 2025

I saw this PR: #886

Then I tought I would finish it 😄

@kimdv kimdv requested review from ahoppen and bnbarham as code owners March 12, 2025 18:40
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks for picking up the PR, Kim!

@ahoppen
Copy link
Member

ahoppen commented Mar 12, 2025

I’m fixing the license header check failure here: swiftlang/github-workflows#105

@kimdv kimdv force-pushed the kimdv/fix-paramter-missing-comma branch 2 times, most recently from b5af6bb to 2449ca8 Compare March 14, 2025 12:45
@kimdv kimdv requested a review from ahoppen March 14, 2025 12:45
@kimdv kimdv force-pushed the kimdv/fix-paramter-missing-comma branch from 2449ca8 to 0fa02d8 Compare March 14, 2025 17:52
trailingComma = self.consume(if: .comma)
} else if !self.at(.rightParen) {
let canParseIdentifier: Bool = withLookahead {
$0.canParseTypeIdentifier(allowKeyword: false) || $0.canParseCustomAttribute()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

    assertParse(
      "func f(_: any borrowing 1️⃣~Copyable) {}",
      diagnostics: [
        DiagnosticSpec(
          message: "unexpected code '~Copyable' in parameter clause"
        )
      ]
    )

This test is failing @ahoppen.

failed - Expected 1 diagnostics but received 2:
1:24: expected ',' in parameter
1:25: expected identifier and ':' in parameter

Not sure how to handle this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$0.canParseCustomAttribute() return true for ~Copyable

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, let’s just remove canParseCustomAttribute then. Attributes on parameters aren’t very common anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahoppen I added an self.at(.atSign) that fixes the issue.
I self only know @ attributes for names. Is there others?

Copy link
Member

@ahoppen ahoppen Mar 18, 2025

Choose a reason for hiding this comment

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

Oh, I just looked at canParesCustomAttribute and it assumes that the @ has already been consumed. So, self.at(.atSign) should be a consume(if:).

And we should probably check for the at sign first because canParseTypeIdentifier can modify the Lookahead’s state.

Copy link
Contributor Author

@kimdv kimdv Mar 19, 2025

Choose a reason for hiding this comment

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

Changed it to consuming it.

@kimdv kimdv force-pushed the kimdv/fix-paramter-missing-comma branch 3 times, most recently from 004b40b to eff3eb3 Compare March 19, 2025 09:51
@kimdv
Copy link
Contributor Author

kimdv commented Mar 19, 2025

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Mar 19, 2025

@swift-ci please test windows

@kimdv kimdv force-pushed the kimdv/fix-paramter-missing-comma branch from eff3eb3 to 8a70081 Compare March 20, 2025 07:25
Comment on lines 163 to 173
let canParseIdentifier: Bool = withLookahead {
$0.canParseTypeIdentifier(allowKeyword: false)
}

let canParseAttribute: Bool = withLookahead {
($0.consume(if: .atSign) != nil && $0.canParseCustomAttribute())
}

if canParseIdentifier || canParseAttribute {
trailingComma = Token(missing: .comma, arena: self.arena)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there is any noteworthy performance hit here?
We have two withLookahead where we potentially only use canParseIdentifier.

Was considering

let canParseIdentifier: Bool = withLookahead {
  $0.canParseTypeIdentifier(allowKeyword: false)
}

if canParseIdentifier {
  trailingComma = Token(missing: .comma, arena: self.arena)
}

let canParseAttribute: Bool = withLookahead {
  $0.consume(if: .atSign) != nil && $0.canParseCustomAttribute()
}

if canParseAttribute {
  trailingComma = Token(missing: .comma, arena: self.arena)
}

Copy link
Member

Choose a reason for hiding this comment

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

I think your current implementation is good. This will only be hit for invalid code and we tend to not squeeze the last bit of performance for invalid code because it’s A LOT less common than valid code.

@kimdv
Copy link
Contributor Author

kimdv commented Mar 20, 2025

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Mar 21, 2025

@swift-ci please test macOS

@kimdv
Copy link
Contributor Author

kimdv commented Mar 21, 2025

@swift-ci please test Windows

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Just one nitpick. Feel free to merge after you addressed it.

Comment on lines 163 to 173
let canParseIdentifier: Bool = withLookahead {
$0.canParseTypeIdentifier(allowKeyword: false)
}

let canParseAttribute: Bool = withLookahead {
($0.consume(if: .atSign) != nil && $0.canParseCustomAttribute())
}

if canParseIdentifier || canParseAttribute {
trailingComma = Token(missing: .comma, arena: self.arena)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think your current implementation is good. This will only be hit for invalid code and we tend to not squeeze the last bit of performance for invalid code because it’s A LOT less common than valid code.

@kimdv kimdv force-pushed the kimdv/fix-paramter-missing-comma branch from 8a70081 to ea8f816 Compare March 23, 2025 08:36
@kimdv
Copy link
Contributor Author

kimdv commented Mar 23, 2025

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Mar 23, 2025

@swift-ci please test windows

@kimdv
Copy link
Contributor Author

kimdv commented Mar 23, 2025

@swift-ci please test macOS

1 similar comment
@kimdv
Copy link
Contributor Author

kimdv commented Mar 24, 2025

@swift-ci please test macOS

@kimdv
Copy link
Contributor Author

kimdv commented Mar 24, 2025

@ahoppen not sure I know why it failed. Tried to dig in the logs, and I don't seem to find anything 🤔

@ahoppen
Copy link
Member

ahoppen commented Mar 24, 2025

Looks like a non-deterministic failure. Let’s try again.

@swift-ci Please test macOS

@kimdv
Copy link
Contributor Author

kimdv commented Mar 25, 2025

@kimdv now it was something else that failed

It still seem unrelated?

Tests Times:
--------------------------------------------------------------------------
[    Range    ] :: [               Percentage               ] :: [   Count   ]
--------------------------------------------------------------------------
[1100s,1200s) :: [                                        ] :: [    1/18842]
[1000s,1100s) :: [                                        ] :: [    0/18842]
[ 900s,1000s) :: [                                        ] :: [    0/18842]
[ 800s, 900s) :: [                                        ] :: [    0/18842]
[ 700s, 800s) :: [                                        ] :: [    0/18842]
[ 600s, 700s) :: [                                        ] :: [    1/18842]
[ 500s, 600s) :: [                                        ] :: [    0/18842]
[ 400s, 500s) :: [                                        ] :: [    0/18842]
[ 300s, 400s) :: [                                        ] :: [    0/18842]
[ 200s, 300s) :: [                                        ] :: [    3/18842]
[ 100s, 200s) :: [                                        ] :: [   35/18842]
[   0s, 100s) :: [*************************************** ] :: [18802/18842]
--------------------------------------------------------------------------
********************
Failed Tests (1):
  Swift-validation(macosx-x86_64) :: Python/swift_build_support.swift

@kimdv
Copy link
Contributor Author

kimdv commented Mar 25, 2025

@swift-ci please test macOS

@kimdv kimdv merged commit 347879f into swiftlang:main Mar 25, 2025
24 checks passed
@kimdv kimdv deleted the kimdv/fix-paramter-missing-comma branch March 25, 2025 13:42
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

2 participants