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

Delegation: support generics for delegation from free functions #125929

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

Bryanskiy
Copy link
Contributor

@Bryanskiy Bryanskiy commented Jun 3, 2024

(The PR was split from #123958, explainer - https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

This PR implements generics inheritance from free functions to free functions and trait methods.

free functions to free functions:

fn to_reuse<T: Clone>(_: T) {}

reuse to_reuse as bar;
// desugaring:
fn bar<T: Clone>(x: T) {
  to_reuse(x)
}

Generics, predicates and signature are simply copied. Generic arguments in paths are ignored during generics inheritance:

fn to_reuse<T: Clone>(_: T) {}

reuse to_reuse::<u8> as bar;
// desugaring:
fn bar<T: Clone>(x: T) {
  to_reuse::<u8>(x) // ERROR: mismatched types
}

Due to implementation limitations callee path is lowered without modifications. Therefore, it is a compilation error at the moment.

free functions to trait methods:

trait Trait<'a, A> {
    fn foo<'b, B>(&self, x: A, y: B) {...}
}

reuse Trait::foo;
// desugaring:
fn foo<'a, 'b, This: Trait<'a, A>, A, B>(this: &This, x: A, y: B) {
  Trait::foo(this, x, y)
}

The inheritance is similar to the previous case but with some corrections:

  • Self parameter converted into T: Trait
  • generic parameters need to be reordered so that lifetimes go first

Arguments are similarly ignored.


In the future, we plan to support generic inheritance for delegating from all contexts to all contexts (from free/trait/impl to free/trait /impl). These cases were considered first as the simplest from the implementation perspective.

@rustbot
Copy link
Collaborator

rustbot commented Jun 3, 2024

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 3, 2024

HIR ty lowering was modified

cc @fmease

@Bryanskiy
Copy link
Contributor Author

сс @petrochenkov

@Bryanskiy
Copy link
Contributor Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2024
@petrochenkov petrochenkov self-assigned this Jun 3, 2024
@oli-obk oli-obk removed their assignment Jun 3, 2024
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 3, 2024
@petrochenkov
Copy link
Contributor

r? types
cc @fmease

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jun 3, 2024
@rustbot rustbot assigned lcnr and unassigned petrochenkov Jun 3, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2024
@rust-log-analyzer

This comment has been minimized.

@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 4, 2024
@lcnr
Copy link
Contributor

lcnr commented Jun 4, 2024

r? fmease

@rustbot rustbot assigned fmease and unassigned lcnr Jun 4, 2024
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 29, 2024
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 29, 2024

📌 Commit f2f9aab has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2024
@bors
Copy link
Contributor

bors commented Jul 30, 2024

⌛ Testing commit f2f9aab with merge 1ddedba...

@bors
Copy link
Contributor

bors commented Jul 30, 2024

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 1ddedba to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 30, 2024
@bors bors merged commit 1ddedba into rust-lang:master Jul 30, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Jul 30, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1ddedba): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 0.8%] 11
Regressions ❌
(secondary)
0.5% [0.1%, 1.2%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 2
All ❌✅ (primary) 0.4% [0.2%, 0.8%] 11

Max RSS (memory usage)

Results (primary 0.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.7% [1.6%, 3.8%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.1% [-4.1%, -4.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [-4.1%, 3.8%] 3

Cycles

Results (primary -2.2%, secondary 2.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 770.079s -> 769.935s (-0.02%)
Artifact size: 331.86 MiB -> 331.88 MiB (0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Jul 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2024
Delegation: querify `sig_id` getter

Possible perf fix for rust-lang#125929

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
Delegation: second attempt to improve perf

Possible perf fix for rust-lang#125929

r? `@petrochenkov`
@petrochenkov
Copy link
Contributor

The perf regression is addressed in #128441.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 3, 2024
…enkov

Delegation: second attempt to improve perf

Possible perf fix for rust-lang#125929

r? `@petrochenkov`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Aug 5, 2024
Delegation: second attempt to improve perf

Possible perf fix for rust-lang/rust#125929

r? `@petrochenkov`
@Kobzol
Copy link
Contributor

Kobzol commented Aug 6, 2024

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Aug 6, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Aug 13, 2024
Delegation: second attempt to improve perf

Possible perf fix for rust-lang/rust#125929

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 4, 2024
…try>

Delegation: support generics in associated delegation items

This is a continuation of rust-lang#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 6, 2024
…etrochenkov

Delegation: support generics in associated delegation items

This is a continuation of rust-lang#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 7, 2024
…etrochenkov

Delegation: support generics in associated delegation items

This is a continuation of rust-lang#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 7, 2024
…etrochenkov

Delegation: support generics in associated delegation items

This is a continuation of rust-lang#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 7, 2024
…etrochenkov

Delegation: support generics in associated delegation items

This is a continuation of rust-lang#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Sep 10, 2024
Delegation: support generics in associated delegation items

This is a continuation of rust-lang/rust#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Sep 25, 2024
Delegation: support generics in associated delegation items

This is a continuation of rust-lang/rust#125929.

[design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md)

Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-fn_delegation `#![feature(fn_delegation)]` merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants