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

Single Quoted Literals. #61477

Closed
wants to merge 10 commits into from

Conversation

johnno1962
Copy link
Contributor

@johnno1962 johnno1962 commented Oct 6, 2022

Hi Apple,

As the last potential holdouts for using the single quote character in Swift (raw strings & perhaps regexes) have been adjudicated, perhaps it is time for a new implementation + pitch for "Character literals" using a single quoted 'c' syntax. This new implementation is additive rather than source breaking as was the previously proposed implementation apple/swift#21873 adding the single quoted syntax as a synonym for double quoted syntax specifically for Character and UnicodeScalar literals, the difference being they have a default type of Character (configurable) instead of String.

In addition, single quoted ASCII character literals can express/initialise integers for use in "old school" code point arithmetic as was proposed previously but without requiring a source breaking change at some point in the future. Many issues discussed in the last review have been addressed by implementing better differentiation between double and single quoted literals using the two new marker protocols ExpressibleBySingleQuotedLiteral and ExpressibleByASCIILiteral which are refined by the existing string literal protocols. This should not affect their ABI as the new protocols use the @_marker attribute.

Consult the test/Parse/single_quoted_literal.swift file in the diff for a sample of new capabilities.

I'd be very interested in the results of a run of the "Source compatibility Suite" if someone would be kind enough to run one as this is intended to be a non-source breaking addition by using the single quote character which not currently valid Swift syntax. The changes are relatively minor overall.

A toolchain is available for evaluation on google drive

Resolves #51535, originally SR-9032 .

@CodaFi
Copy link
Contributor

CodaFi commented Oct 7, 2022

Hey @johnno1962, this is good work. Before I review it, is there a corresponding re-pitch on the forums?

@johnno1962
Copy link
Contributor Author

Hi @CodaFi, thanks for noticing the PR. I'm a little back-to-front when I attempt to evolve Swift: I start with an exploratory implementation to see what is possible, write the proposal then pitch it 🙃. At the moment I'm looking through the last epic review thread to see how much further along we are. Adding the two new ExpressibleBy protocols helps differentiate the two forms and the integer convertibility is more focused and won't even compile if the literal isn't ASCII but '*' * '*' as Int will still compile if you ask it to. Also, the new implementation no longer requires any source breaking so the proposal requires quite a rewrite. At this point it would be a big help if you could kick off a test run for me to make sure they are working.

@CodaFi CodaFi added swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal labels Oct 8, 2022
@johnno1962
Copy link
Contributor Author

johnno1962 commented Oct 10, 2022

Some progress on a a draft proposal: https://github.com/johnno1962/swift-evolution/pull/4/files. Should be enough to form an opinion on the PR; There isn't much to it. It offers nearly the same functionality as the previously rejected implementation without the cost of some source breaks that were identified.

@johnno1962
Copy link
Contributor Author

I'm closing this now as there doesn't seem to be much appetite for a proposal that would drag Swift back into the 20th century when characters were convertible to integer values. Sad.

@johnno1962 johnno1962 closed this Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SR-9032] Add ability to create ‘character' literals to compiler.
2 participants