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

Character Literals (#1934) #1964

Merged

Conversation

cabmeurer
Copy link
Contributor

@cabmeurer cabmeurer commented Aug 8, 2022

Put character literals in single quotes, like 'a'. Character literals work
like numeric literals:

  • Every different literal value has its own type.
  • The bit width is determined by the type of the variable the literal is
    assigned to, not the literal itself. Follows the plan from Open design idea: character literals #1934.

@cabmeurer cabmeurer force-pushed the cabmeurer/proposal-character-literals branch from 70f85aa to 8fac93f Compare August 8, 2022 22:22
@cabmeurer cabmeurer changed the title Character Literals Character Literals (#1934) Aug 8, 2022
@cabmeurer cabmeurer force-pushed the cabmeurer/proposal-character-literals branch from 8fac93f to 22a5c69 Compare August 8, 2022 22:46
@Pixep Pixep added the proposal A proposal label Aug 8, 2022
@cabmeurer cabmeurer force-pushed the cabmeurer/proposal-character-literals branch 10 times, most recently from 87b433e to 2660f2f Compare August 9, 2022 21:00
@cabmeurer
Copy link
Contributor Author

@opelolo let me know when you want to start collaborating on this

@cabmeurer cabmeurer force-pushed the cabmeurer/proposal-character-literals branch 13 times, most recently from 5b22640 to 630bfaa Compare August 10, 2022 16:24
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
@cabmeurer cabmeurer requested review from josh11b and chandlerc and removed request for chandlerc and josh11b March 11, 2023 23:13
Copy link
Contributor

@josh11b josh11b left a comment

Choose a reason for hiding this comment

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

Sorry for the delay getting back to you on this. GSoC and so on have been keeping me busy.

Looks good! I think this is ready for the leads to review.

@cabmeurer
Copy link
Contributor Author

@chandlerc could you take another look at this when you have a chance?

@cabmeurer
Copy link
Contributor Author

@zygoloid could you take a look at this when you have a chance?

@geoffromer
Copy link
Contributor

FYI both @zygoloid and @chandlerc have been on vacation (I think Chandler still is), so it may take them a little while to get to this.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Looks good, I'm happy to move forward with this.

proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
Comment on lines +150 to +151
- Only one operand may be a character literal, the other must be an
integer literal.
Copy link
Contributor

Choose a reason for hiding this comment

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

One consequence appears to be that this is invalid:

fn Digit(n: i8) -> Char32 {
  return '0' + n;
}

... and something like return ('0' as Char32) + n; would be needed instead. I think I'm OK with that, but I expect it to be a minor source of friction as that kind of usage is fairly common in C++.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that '0' + n has a value that is only known at runtime, what type should it be? Using the type of n here is a bit worrisome, due to overflow. I would be fine with saying the result would be Char32, but maybe that would only make sense for some types of n? For example if n: i64, a Char32 result would be surprising.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I like keeping this super-explicit for now (requiring a cast to a specific sized type). We can try to add better defaults if in practice this friction is something users dislike. I'm somewhat hopeful that instead we can have a really easily discovered (and targeted in migration) API for mapping to digits, and avoid how much this comes up in practice. But it seems easy to address if it does come up.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
@cabmeurer cabmeurer requested a review from zygoloid June 3, 2023 21:57
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

First off, sorry for all the delays while folks were first at a conference, and then on vacation, and then catching up! I know that really stretched things out way more than we'd like for this proposal, and I appreciate you bearing with us.

Hopefully things will move (much) more steadily now.


On this proposal, I'm pretty happy moving forward here too. =] Thanks so much for the work on this!

All my comments below are just around wording, clarifications, etc. At least, I don't think there are any suggestions for a substantive change here. Hopefully with help from folks we can converge quickly on the remaining wording issues and land this.

proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
Comment on lines +150 to +151
- Only one operand may be a character literal, the other must be an
integer literal.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I like keeping this super-explicit for now (requiring a cast to a specific sized type). We can try to add better defaults if in practice this friction is something users dislike. I'm somewhat hopeful that instead we can have a really easily discovered (and targeted in migration) API for mapping to digits, and avoid how much this comes up in practice. But it seems easy to address if it does come up.

proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
proposals/p1964.md Outdated Show resolved Hide resolved
cabmeurer and others added 2 commits June 15, 2023 13:07
@cabmeurer cabmeurer requested a review from chandlerc June 15, 2023 20:17
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Looks great, thanks so much! Merging!

@chandlerc chandlerc merged commit 766bb7e into carbon-language:trunk Jun 15, 2023
@cabmeurer
Copy link
Contributor Author

Thank you everyone!

@cabmeurer cabmeurer deleted the cabmeurer/proposal-character-literals branch June 15, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal rfc Proposal with request-for-comment sent out proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants