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

Replace every Symbol | string & equiv. with the new interned #1499

Merged
merged 6 commits into from
Sep 15, 2023

Conversation

ParadoxV5
Copy link
Contributor

@ParadoxV5 ParadoxV5 commented Sep 4, 2023

So, with #1469, we have finally decided on what to call Symbol | string 👌.

This PR is a follow-up to #1488 to assimilate ALL Symbol | strings and equivalents to use interned. Regexp: /symbol \| string|string \| symbol/

  • (At this scale, are we sure RBS neophytes can understand what interned is?)
  • A majority of the population actually uses String with an uppercase S, i.e. no _ToStrs accepted. But given that nearly if not all of them are C-implemented, I doubt they actually reject _ToStrs and bet that they’re RBS oversights.
  • Also purged are Object::name and (introduced with Allow Symbol | string to Module methods #1321) Module::id [EDIT: and Net::HTTPHeader::key]. They might be used in the wild, howëver, so backward-compatibility requires undeleting those type defs.
  • There’s also a lot of now-Integer | interneds – how about int_interned?

c.c. @sampersand and @soutaro, author and reviewer of #1469 respectively
#good-first-issue

@ParadoxV5
Copy link
Contributor Author

Unknown alias name: interned? That is not #good-first-issue, need help

@ParadoxV5
Copy link
Contributor Author

ParadoxV5 commented Sep 4, 2023

Another three: there’re many TrueClass rather than true, FalseClass rather than false and TrueClass | FalseClass/true | false rather than bool. Changing things to bool could screw up with the tests, though, so I’m passing.
Mean while, perhaps the RBS community too would benefit from a style guide; since moreover, there’s some inconsistency with the use of ::MyModule vs. MyModule.

@sampersand
Copy link
Contributor

I tried doing this when interned was first added, but there's a lot of places to check—Are things annotated with String | Symbol actually interned and someone just forgot the _ToStr case, or does it actually not accept _ToStrs. I planned on just migrating them as I went.

1 similar comment
@sampersand
Copy link
Contributor

I tried doing this when interned was first added, but there's a lot of places to check—Are things annotated with String | Symbol actually interned and someone just forgot the _ToStr case, or does it actually not accept _ToStrs. I planned on just migrating them as I went.

@soutaro
Copy link
Member

soutaro commented Sep 5, 2023

@ParadoxV5 Thanks for this PR.

  • I'm good to replace existing union types to interned.
  • I'm good too to replace existing id, name, ... to interned while not 100% sure if it can be unified safely, but looks like good.
  • Please keep the existing id and name definitions to avoid breaking existing type definitions (I know it's impossible but deleting the definitions is a clear incompatibility.)

@soutaro
Copy link
Member

soutaro commented Sep 5, 2023

Unknown alias name: interned? That is not #good-first-issue, need help

#1502 will fix the issue.

@ksss
Copy link
Collaborator

ksss commented Sep 5, 2023

Please excuse any disruptive comments.
Is interned a decided name?

Certainly String#intern and Symbol#intern are methods that return Symbols.

But in CRuby's API, interned seems to mean frozen string.

https://github.com/ruby/ruby/blob/89a4fd67453b33b7c709c715f01cfeff8efb2f9d/string.c#L11870

Does the intention come across with "interned"?

core/builtin.rbs Outdated
Comment on lines 272 to 274
%a{steep:deprecated} type Object::name = interned
%a{steep:deprecated} type Module::id = interned
%a{steep:deprecated} type Net::HTTPHeader::key = interned
Copy link
Contributor Author

@ParadoxV5 ParadoxV5 Sep 5, 2023

Choose a reason for hiding this comment

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

Found this annotation in

"title": "Annotation associated to a declaration or a member: `%a{rbs:test}`, `%a{steep:deprecated}`, ...",
but otherwise no deprecation annotation documented in either RBS or Steep. Not sure if it’s appropriate.

Put the previous incarnations back where they once were
@soutaro
Copy link
Member

soutaro commented Sep 6, 2023

@ksss

Is interned a decided name?

We are free to rename it until the RBS 3.3 release. 😃

But in CRuby's API, interned seems to mean frozen string.

My understanding is that intern is an one-to-one operation, which maps a string to an ID. It's not a frozen string. (Frozen string is also interned to reuse it though.)

The type here is for something that will be interned. So I don't think it's a bad name. (Maybe internable would make more sense?)

We may be able to say it's too much connected to the implementation detail. Calling it in more abstract way, like name, may make sense.

@sampersand
Copy link
Contributor

I'm not a huge fan of either name or id for a few reasons.

Just like how Kernel#id was removed in favor of Kernel#object_id so that custom.id functions wouldn't conflict, I'm worried that using name or id in core RBS could lead to people with issues: They seem like fairly common type aliases that people might use. (Moreso id than name, but I could forsee both of them). I picked interned (although it really shoulda been be intern...) because I doubt anyone would actually used it.

Additionally, name doesn't feel entirely right to me: It feels like it should be only used in cases where it's a "key" (such as Class.define_method or Thread#[]), but in other places where Symbol | stringare accepted it feels a bit awkward, such asProcess#kill (def self.kill: (Integer | name signal, *int pids) -> Integer) or Regexp.escape (def self.escape: (name str) -> String`).

I agree that interned/intern is a bit awkward, and I'd be open to other suggestions. Maybe stringy or stringish? IDK, I don't think there's a good answer.

@ksss
Copy link
Collaborator

ksss commented Sep 7, 2023

Thank you for your response. I now understand the reason for using interned.
I won't interject further.

It seems there might be a side effect to the issue related to the public nature of type aliases. Perhaps having private type aliases would be a good idea.

@ParadoxV5
Copy link
Contributor Author

ParadoxV5 commented Sep 7, 2023

Perhaps having private type aliases would be a good idea.

Namespace it, such as Net::HTTPHeader::key. And for truly private-feeling ones, why make then in the first place.

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

👍

Will merge this PR, after reviewing other open PRs to minimize conflicts.

@soutaro soutaro added this pull request to the merge queue Sep 15, 2023
@soutaro soutaro removed this pull request from the merge queue due to a manual request Sep 15, 2023
@ParadoxV5
Copy link
Contributor Author

@soutaro I resolved the merge conflict

@soutaro soutaro added this pull request to the merge queue Sep 15, 2023
Merged via the queue into ruby:master with commit cd5ec54 Sep 15, 2023
23 checks passed
@ParadoxV5 ParadoxV5 deleted the interned branch September 15, 2023 03:40
@soutaro soutaro added this to the RBS 3.3 milestone Oct 31, 2023
@soutaro soutaro added the Released PRs already included in the released version label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

4 participants