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

Use the correct type for Self in generic classes and generic interfaces #4087

Merged
merged 7 commits into from
Jun 28, 2024

Conversation

zygoloid
Copy link
Contributor

In a class C(T:! type), the type Self should be C(T), not merely C. Similarly, in an interface I(T:! type), the type of self should be I(T), not merely I.

@zygoloid

This comment was marked as resolved.

@zygoloid zygoloid removed the dependent Depends on another issue/PR label Jun 27, 2024
@zygoloid zygoloid marked this pull request as ready for review June 27, 2024 20:45
@github-actions github-actions bot requested a review from josh11b June 27, 2024 20:45

// Builds the generic instance corresponding to the generic itself. For example,
// for a generic `G(T:! type)`, this is `G(T)`.
auto MakeUnsubstitutedGenericInstance(Context& context,
Copy link
Contributor

Choose a reason for hiding this comment

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

"Unsubstituted" doesn't convey this to me, maybe?

Suggested change
auto MakeUnsubstitutedGenericInstance(Context& context,
auto MakeSelfGenericInstance(Context& context,

or

Suggested change
auto MakeUnsubstitutedGenericInstance(Context& context,
auto MakeCanonicalGenericInstance(Context& context,

or

Suggested change
auto MakeUnsubstitutedGenericInstance(Context& context,
auto MakeRepresentativeGenericInstance(Context& context,

Copy link
Contributor Author

@zygoloid zygoloid Jun 27, 2024

Choose a reason for hiding this comment

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

Went with a variation of the first option and updated the generics-in-the-toolchain design doc to call this the "self instance" rather than the "unsubstituted instance".

Comment on lines 13 to 15
fn F[addr self: Self*]() -> Class(T)* {
return self;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Test it works in both directions?

Suggested change
fn F[addr self: Self*]() -> Class(T)* {
return self;
}
fn F[addr self: Self*]() -> Class(T)* {
return self;
}
fn G[addr self: Class(T)*]() -> Self* {
return self;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I'm trying to test that it's the exact same type, not just that it's convertible. Maybe there's a better way to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed this a bit to try to better test the types are the same. I'm still not really happy with it, but hopefully this will do for now.

@zygoloid zygoloid requested a review from josh11b June 28, 2024 00:54
@josh11b josh11b added this pull request to the merge queue Jun 28, 2024
Merged via the queue into carbon-language:trunk with commit 10a198a Jun 28, 2024
7 checks passed
@zygoloid zygoloid deleted the toolchain-generic-4 branch June 28, 2024 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants