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

SR-1378: Rewrite _countFormatSpecifiers(_:) to handle positional specifiers #3555

Closed

Conversation

rsfinn
Copy link

@rsfinn rsfinn commented Jul 16, 2016

What's in this pull request?

Rewrite _countFormatSpecifiers(_:) to handle positional specifiers correctly.

Resolved bug number: (SR-1378)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

// characters (percent, dollar, zero, and nine), we don't need to decode UTF-16.

enum ScanState {
case NoPercent
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really a big deal here, as it's internal, but enum cases should be camelCase.

Copy link
Author

Choose a reason for hiding this comment

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

I was still in Swift 2.2 mode, mentally at least. :-)

@moiseev
Copy link
Contributor

moiseev commented Jul 29, 2016

Overall LGTM. Couple minor comments.
@swift-ci Please test

@moiseev
Copy link
Contributor

moiseev commented Jul 29, 2016

Thanks @rsfinn, and sorry for a much delayed review.

state = .noPercent
}
else if c >= zeroUTF16 && c <= nineUTF16 {
posValue = posValue * 10 + (Int(c) - Int(zeroUTF16))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a though...

Since enums in Swift are more powerful than in C, it is possible to actually attach a posValue variable to the .scanningDigits case. So that it would look like case scanningDigits(current: UInt16). Which means that in the switch you would be able to get the posValue value right from the state itself like this case .scanningDigits(let current). This would eliminate one extra 'global' variable, and move it into state.

This approach can be take even further by representing all the now-global state inside the state, but that is probably unreasonable, because that would require multiple states to hold the values these states don't use, but merely pass around.

Integrating posValue into the .scanningDigits state, on the other hand, is quite natural, as the posValue is only used inside the code that handles this particular state.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

That sounds like a good idea. I'm still accustoming myself to Swift's idioms and that approach had not occurred to me.

I thought I had pushed my previous changes earlier, and this pull request page seems to reflect that; but I had a local file system issue after pushing my initial pull request and had to reconstruct my local repository, so maybe there's a problem with my configuration. I'll make this most recent change at my end and update this page when I've done so; if the update doesn't take here, feel free to go ahead and make the update at your end.

I'll be pleased to see this fix get into 3.0; thanks again for your feedback.

@dabrahams
Copy link
Collaborator

@rsfinn, thank you so much for your efforts! However, we can't repair these checks in Swift 3; rationale is in #3917. As it says there, doing this right introduces even more complexity than your patch (which wouldn't handle "%1$.*2$d", for example), and doing it so it actually guarantees safety is harder still. We think the checks just need to be removed for now.

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