Skip to content

Tracking issue for making ASCII ctype inherent methods const fn #68983

Closed

Description

@ecstatic-morse

This is a tracking issue for making the inherent methods introduced in #46077 into const fn. This includes all functions listed in #39658 for both u8 and char, namely:

  • is_ascii_alphabetic
  • is_ascii_uppercase
  • is_ascii_lowercase
  • is_ascii_alphanumeric
  • is_ascii_digit
  • is_ascii_hexdigit
  • is_ascii_punctuation
  • is_ascii_graphic
  • is_ascii_whitespace
  • is_ascii_control

The feature gate for the const version of these functions is #![feature(const_ascii_ctype_on_intrinsics)]. These cannot be const-stabilized until #![feature(const_if_match)] is stable.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Feb 9, 2020
  2. changed the title [-]Tracking issue for making ASCII character type methods on intrinsics[/-] [+]Tracking issue for making ASCII ctype inherent methods `const fn`[/+] on Feb 9, 2020
  3. added a commit that references this issue on Feb 10, 2020
  4. Demi-Marie commented on Apr 15, 2020

    @Demi-Marie

    Could these be implemented by means of a lookup table?

  5. ecstatic-morse commented on May 14, 2020

    @ecstatic-morse
    ContributorAuthor

    @demimarie-parity Sorry I missed your comment.

    They could be, although the generated code would likely be worse than the branchy version. #![feature(const_if_match)] is close to being stabilized (see #49146), so I would prefer to wait until that occurs. If it is delayed for some reason, we could revisit.

  6. Demi-Marie commented on May 14, 2020

    @Demi-Marie

    @ecstatic-morse my experience in practice (albeit in Haskell) has been the opposite ― the lookup table is significantly faster.

  7. ecstatic-morse commented on May 14, 2020

    @ecstatic-morse
    ContributorAuthor

    You're welcome to try it out. If it is indeed faster, that would be a valuable addition to the standard library. I will point out that the obvious microbenchmark will put the lookup table in the L1 cache, so it won't be fair unless you're calling these functions in a tight loop. Perhaps that's the most common mode of use and we should indeed be optimizing for it?

  8. Demi-Marie commented on May 14, 2020

    @Demi-Marie

    My tests were done several years ago, and indeed involved calling these functions in a tight loop. I have no idea if that is the most common use, though.

  9. ecstatic-morse commented on May 14, 2020

    @ecstatic-morse
    ContributorAuthor

    I think if you were able to demonstrate that a lookup table based approach was faster in rust in a tight loop, the libs team would seriously consider switching to it. I'm not on the libs team, so I don't know how they evaluate time/memory trade-offs such as this one.

    If you have any questions about writing microbenchmarks in rust, I'm happy to answer them. If you're not interested, consider opening an issue so someone else can look into it. I think it's an idea that's worth testing.

  10. added
    A-strArea: str and String
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jul 29, 2020
  11. m-ou-se commented on Sep 22, 2021

    @m-ou-se
    Member

    Looks like these were already stabilized as const in 1.47. Closing this issue.

  12. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-sliceArea: `[T]`A-strArea: str and StringB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions