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

Resolve inherent associated functions & constants defined on function pointer types #108347

Closed
wants to merge 1 commit into from

Conversation

fmease
Copy link
Member

@fmease fmease commented Feb 22, 2023

Fixes #108270.

@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 22, 2023
@fmease fmease changed the title Resolve associated functions & constants defined on function pointer types Resolve inherent associated functions & constants defined on function pointer types Feb 22, 2023
@compiler-errors
Copy link
Member

r? @compiler-errors

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot assigned compiler-errors and unassigned TaKO8Ki Feb 22, 2023
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 22, 2023
@bors
Copy link
Contributor

bors commented Feb 22, 2023

⌛ Trying commit ffad636 with merge 192617ada336ebe7e790566a33fd3b414937e71b...

@compiler-errors
Copy link
Member

Nothing's wrong with the impl, just two things:

  1. Core doesn't currently use this, so we're kinda doing extra work for nothing?
  2. Since we're doing extra work, there's a tiny risk that we're gonna cause a perf regression.

Let's see what rust-timer says, then go from there.

@bors
Copy link
Contributor

bors commented Feb 22, 2023

☀️ Try build successful - checks-actions
Build commit: 192617ada336ebe7e790566a33fd3b414937e71b (192617ada336ebe7e790566a33fd3b414937e71b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (192617ada336ebe7e790566a33fd3b414937e71b): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

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)
1.1% [1.0%, 1.2%] 2
Regressions ❌
(secondary)
2.2% [2.0%, 2.6%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [1.0%, 1.2%] 2

Max RSS (memory usage)

Results

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)
3.7% [3.7%, 3.7%] 1
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.7% [3.7%, 3.7%] 1

Cycles

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 22, 2023
@fmease
Copy link
Member Author

fmease commented Feb 23, 2023

Closing for now due to the perf regression. Might re-open at some point once I have a vague idea how to speed things up.

@fmease fmease closed this Feb 23, 2023
@fmease
Copy link
Member Author

fmease commented Feb 24, 2023

Ah, I just saw #103042 (comment), so potentially keccak and cranelift-codegen are false positives after all. Let's wait and see and I might open this PR at some point w/o any adjustments.

@fmease
Copy link
Member Author

fmease commented Mar 18, 2023

It seems like #108815 fixed the keccak & cranelift-codegen performance ‘bimodalities’. See also keccak bimodility (Zulip).

If the above is true and if I understood the situation correctly, it's worth rechecking the perf of this PR.
@compiler-errors Could you kick off a timing check? That'd be great. Thanks in advance! :)

@fmease fmease reopened this Mar 18, 2023
@compiler-errors
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 18, 2023
@bors
Copy link
Contributor

bors commented Mar 18, 2023

⌛ Trying commit ffad636 with merge e322b72bfaf72c243e2cebc027cfbc2e6b050d00...

@bors
Copy link
Contributor

bors commented Mar 19, 2023

☀️ Try build successful - checks-actions
Build commit: e322b72bfaf72c243e2cebc027cfbc2e6b050d00 (e322b72bfaf72c243e2cebc027cfbc2e6b050d00)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e322b72bfaf72c243e2cebc027cfbc2e6b050d00): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 1

Max RSS (memory usage)

Results

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)
1.8% [0.9%, 2.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) 0.8% [-1.0%, 2.6%] 3

Cycles

Results

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)
- - 0
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-0.6%, -0.6%] 1

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Mar 19, 2023
@compiler-errors compiler-errors added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 19, 2023
@compiler-errors
Copy link
Member

Gonna FCP this for T-types -- The question here is whether or not we want to be able to write incoherent/core impls for fn ptrs. I think it's good for consistency, but not particularly useful (since we can't be generic over argument arity), but also I see no harm in allowing it -- seems along the same lines that we allow incoherent impls for tuples. cc #94963

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Mar 19, 2023

Team member @compiler-errors has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 19, 2023
@lcnr
Copy link
Contributor

lcnr commented Mar 20, 2023

I cannot imagine us ever using this. Any impl for function pointers should go through the FnPtr trait instead 🤔 I guess this is fairly trivially correct so it doesn't matter too much

@oli-obk
Copy link
Contributor

oli-obk commented Mar 20, 2023

We could reject it with an error mentioning the FnPtr trait

@nikomatsakis
Copy link
Contributor

I'm confused here -- we are allowing incoherent impls? I would be more comfortable using FnPtr, are there methods where that doesn't suffice?

@nikomatsakis
Copy link
Contributor

@rfcbot concern fnptr

Nothing against this PR per se, but I'd prefer that we use the FnPtr trait and disallow incoherent fn-based inherent impls, and I want to better understand that option.

@fmease
Copy link
Member Author

fmease commented Mar 21, 2023

we are allowing incoherent impls?

Not outright, only with #![rustc_coherence_is_core], so effectively only in the core library.

FnPtr is definitely superior. This PR is mostly motivated by a drive towards consistency in the area of inherent impls.

@compiler-errors
Copy link
Member

Nothing against this PR per se, but I'd prefer that we use the FnPtr trait and disallow incoherent fn-based inherent impls, and I want to better understand that option.

I don't mind that approach either necessarily, but in that case, we probably should also reject inherent impls on tuples and maybe others...

@compiler-errors compiler-errors added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 26, 2023
@lcnr
Copy link
Contributor

lcnr commented Aug 7, 2023

@rfcbot cancel

@rfcbot
Copy link

rfcbot commented Aug 7, 2023

@lcnr proposal cancelled.

@rfcbot rfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Aug 7, 2023
@lcnr
Copy link
Contributor

lcnr commented Aug 7, 2023

talked about this in the planning meeting today https://rust-lang.zulipchat.com/#narrow/stream/326132-t-types.2Fmeetings/topic/2023-08-07.20planning.20meeting/near/382646902

We would prefer to completely forbid inherent impls on function pointers with a suggestion to use the FnPtr trait instead.

We are open to adding this once there is a valid use case here, but this feels quite unlikely as adding an impl for just one kind of function pointer is far from ideal.

@lcnr lcnr 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-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels Aug 7, 2023
@fmease
Copy link
Member Author

fmease commented Aug 7, 2023

Makes sense. I'm gonna close this PR then & create a new one for forbidding inherent impls on function pointer types.

@fmease fmease closed this Aug 7, 2023
@fmease fmease deleted the assoc-fn-ct-on-fn-ptr-ty branch August 7, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Inherent associated functions and constants defined on function pointer types won't be found
10 participants