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

Combine Sub and Equate #121462

Merged
merged 7 commits into from
Mar 1, 2024
Merged

Combine Sub and Equate #121462

merged 7 commits into from
Mar 1, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Feb 22, 2024

Combine Sub and Equate into a new relation called TypeRelating (that name sounds familiar...)

Tracks the difference between Sub and Equate via ambient_variance: ty::Variance much like the NllTypeRelating relation, but implemented slightly jankier because it's a more general purpose relation.

r? lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Feb 22, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2024

Type relation code was changed

cc @compiler-errors, @lcnr

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

I am not too happy with RelateDirection. Because it doesn't really feel appropriate given that it is used in relate only together with a_is_expected.

I would personally prefer tracking the variance in TypeRelating - supporting Contravariance - and changing relate_with_variance to simply be self.variance = self.variance.xform(variance);. This means we then don't need a_is_expected at all and (after removing (it from) Lub) can change the Generalizer to not compare a_is_expected with target_is_expected.

Apart from that 👍

compiler/rustc_infer/src/infer/relate/type_relating.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the eq-and-sub branch 2 times, most recently from 27da982 to 8ba73e7 Compare February 22, 2024 21:00
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the eq-and-sub branch 2 times, most recently from 5508ab5 to 4d1c58b Compare February 22, 2024 21:40
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 23, 2024
…rors

fix generalizer unsoundness

I ended up getting confused while trying to flip the variances when flipping the order. Should be all right now.

This is only exploitable when generalizing if the `ambient_variance` of the relation is `Contravariant`. This can currently only be the case in the NLL generalizer which only rarely generalizes, causing us to miss this regression. Very much an issue with rust-lang#121462 however.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2024
Rollup merge of rust-lang#121479 - lcnr:fix-generalize, r=compiler-errors

fix generalizer unsoundness

I ended up getting confused while trying to flip the variances when flipping the order. Should be all right now.

This is only exploitable when generalizing if the `ambient_variance` of the relation is `Contravariant`. This can currently only be the case in the NLL generalizer which only rarely generalizes, causing us to miss this regression. Very much an issue with rust-lang#121462 however.
@bors
Copy link
Contributor

bors commented Feb 23, 2024

☔ The latest upstream changes (presumably #121491) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

Comment on lines 1 to 2
//! There are four type combiners: [TypeRelating], [Lub], and [Glb],
//! (and `NllTypeRelating` in rustc_borrowck, which is only used for NLL).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! There are four type combiners: [TypeRelating], [Lub], and [Glb],
//! (and `NllTypeRelating` in rustc_borrowck, which is only used for NLL).
//! There are four type combiners: [TypeRelating], [Lub], and [Glb],
//! and `NllTypeRelating` in rustc_borrowck, which is only used for NLL.

/// Enforce that `a` is equal to or a subtype of `b`.
pub struct TypeRelating<'combine, 'a, 'tcx> {
fields: &'combine mut CombineFields<'a, 'tcx>,
a_is_expected: bool,
Copy link
Contributor

@lcnr lcnr Feb 26, 2024

Choose a reason for hiding this comment

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

a_is_expected should be unnecessary now, as we can instead flip the related types by using xform(ty::Contravariance). Where do we modify a_is_expected right now?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not that we modify a_is_expected from within the relation. It's that we construct the relation (and therefore pass in a_is_expected) separately from where we use it. I think this is prohibitively invasive to fix right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, we could then simpy flip the args if Trace { a_is_expected } is false. But yeah, am fine with doing that in a separate PR

@lcnr
Copy link
Contributor

lcnr commented Feb 26, 2024

@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 Feb 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2024
Combine `Sub` and `Equate`

Combine `Sub` and `Equate` into a new relation called `TypeRelating` (that name sounds familiar...)

Tracks the difference between `Sub` and `Equate` via `ambient_variance: ty::Variance` much like the `NllTypeRelating` relation, but implemented slightly jankier because it's a more general purpose relation.

r? lcnr
@bors
Copy link
Contributor

bors commented Feb 26, 2024

⌛ Trying commit 3034b2b with merge c30f81e...

@bors
Copy link
Contributor

bors commented Feb 26, 2024

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

@rust-timer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 29, 2024

☔ The latest upstream changes (presumably #121770) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me after final comment cleanup.

Thanks for your work ❤️

compiler/rustc_infer/src/infer/relate/generalize.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/relate/type_relating.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/relate/type_relating.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Feb 29, 2024

☔ The latest upstream changes (presumably #118247) made this pull request unmergeable. Please resolve the merge conflicts.

@lcnr
Copy link
Contributor

lcnr commented Mar 1, 2024

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Mar 1, 2024

📌 Commit 5072b65 has been approved by lcnr

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 Mar 1, 2024
@bors
Copy link
Contributor

bors commented Mar 1, 2024

⌛ Testing commit 5072b65 with merge b0696a5...

@bors
Copy link
Contributor

bors commented Mar 1, 2024

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing b0696a5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 1, 2024
@bors bors merged commit b0696a5 into rust-lang:master Mar 1, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 1, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b0696a5): 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.5% [0.2%, 0.9%] 13
Regressions ❌
(secondary)
0.5% [0.3%, 0.8%] 17
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.9%, -0.4%] 7
All ❌✅ (primary) 0.5% [0.2%, 0.9%] 13

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

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

Binary size

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

Bootstrap: 653.924s -> 651.828s (-0.32%)
Artifact size: 311.55 MiB -> 311.10 MiB (-0.15%)

@lcnr
Copy link
Contributor

lcnr commented Mar 1, 2024

as stated in #121462 (comment):

Some ideas how to reduce the perf impact. Even if they don't completely remove it, this will allow significant improvements and cleanups going forward and generally simplifies the core type system. I would merge this even with these regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants