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

[WIP] Rewrite handling of universe-leaking placeholder regions into outlives constraints #123720

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

amandasystems
Copy link
Contributor

This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint.

This variant is a work in progress but seems to pass most tests.

Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

r? @davidtwco

rustbot has assigned @davidtwco.
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 Apr 10, 2024
@amandasystems
Copy link
Contributor Author

amandasystems commented Apr 10, 2024

?r @nikomatsakis

(it's not 100% ready for review yet probably maybe, but I figured I might as well start the PR now)

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

the syntax is r? nikomatsakis 😆

@rustbot rustbot assigned nikomatsakis and unassigned davidtwco Apr 10, 2024
@amandasystems
Copy link
Contributor Author

the syntax is r? nikomatsakis 😆

That’s funny because I tried that first, thought I made a mistake, and went back to “fix” it

@amandasystems
Copy link
Contributor Author

amandasystems commented Apr 12, 2024

Update: I had a brainwave during my investigations of the failing UI tests (there's 20-ish of them if you enable the new logic everywhere, depending on whether you count duplicates). I tried adding a new constraint category so that I could easily not blame it (ever, actually), and that reduces the errors down to one, tiny span diff:

---- [ui] tests/ui/higher-ranked/trait-bounds/due-to-where-clause.rs stdout ----
diff of stderr:

2         --> $DIR/due-to-where-clause.rs:2:5
3          |
4       LL |     test::<FooS>(&mut 42);
-          |     ^^^^^^^^^^^^ implementation of `Foo` is not general enough
+          |     ^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
6          |
7          = note: `FooS<'_>` must implement `Foo<'0>`, for any lifetime `'0`...
8          = note: ...but `FooS<'_>` actually implements `Foo<'1>`, for some specific lifetime `'1`

I'm pretty confident this works now. Removing the WIP label!

@amandasystems amandasystems changed the title [WIP] Rewrite handling of universe-leaking placeholder regions into outlives constraints Rewrite handling of universe-leaking placeholder regions into outlives constraints Apr 12, 2024
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Efficiency nit

compiler/rustc_borrowck/src/constraints/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/constraints/mod.rs Outdated Show resolved Hide resolved
@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 Apr 12, 2024
@amandasystems
Copy link
Contributor Author

I think it's ready for a perf run, @lqd!

@lqd
Copy link
Member

lqd commented Apr 12, 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 Apr 12, 2024
@bors
Copy link
Contributor

bors commented Apr 12, 2024

⌛ Trying commit 5a1c148 with merge 1b9e1e6...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 12, 2024
…=<try>

Rewrite handling of universe-leaking placeholder regions into outlives constraints

This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint.

This variant is a work in progress but seems to pass most tests.

Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

OK, so, I reviewed and left a (tiny) nit. I don't know that a perf run is really needed, this is pretty clearly grossly inefficient. That's precisely what I expected, of course.

r=me but I'd like to hand this off to somebody else to drive over the finish line

compiler/rustc_borrowck/src/constraints/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/constraints/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/constraints/mod.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Apr 12, 2024

☀️ Try build successful - checks-actions
Build commit: 1b9e1e6 (1b9e1e65acb35d4d1d734c6461ace5c4e50a9fd0)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1b9e1e6): 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

Warning ⚠: The following benchmark(s) failed to build:

  • rustc
  • wg-grammar
  • webrender-2022

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)
113.9% [0.3%, 3862.1%] 236
Regressions ❌
(secondary)
393.2% [0.1%, 7855.4%] 184
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 113.9% [0.3%, 3862.1%] 236

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.7% [-10.5%, -0.7%] 57
Improvements ✅
(secondary)
-5.6% [-7.4%, -3.5%] 21
All ❌✅ (primary) -3.7% [-10.5%, -0.7%] 57

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)
215.7% [0.9%, 3636.4%] 98
Regressions ❌
(secondary)
1147.6% [1.0%, 7887.5%] 61
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 215.7% [0.9%, 3636.4%] 98

Binary size

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

Bootstrap: missing data
Artifact size: 315.97 MiB -> 305.14 MiB (-3.43%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 13, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 16, 2024

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

This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint.

This variant is a work in progress.

Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!

Add a new constraint category for our outlives static constraints

This makes the origin of these synthetic constraints clearer and allows us to make sure that they are literally never blamed during error reporting, massively reducing the number of failing UI tests.

In addition, this commit contains a few drive-by refactors, in particular of debug printing.
@rust-log-analyzer

This comment has been minimized.

@amandasystems amandasystems changed the title Rewrite handling of universe-leaking placeholder regions into outlives constraints [WIP] Rewrite handling of universe-leaking placeholder regions into outlives constraints Apr 18, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

This is clearly buggy (I get 24 test failures, out of which 9 are clearly serious), but it's a start.
@rust-log-analyzer

This comment has been minimized.

This is a bit inelegant, but works for now.
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#17 exporting to docker image format
#17 sending tarball 29.9s done
#17 DONE 37.3s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
diff of stderr:

2   --> $DIR/due-to-where-clause.rs:2:5
3    |
4 LL |     test::<FooS>(&mut 42);
-    |     ^^^^^^^^^^^^ implementation of `Foo` is not general enough
+    |     ^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
6    |
7    = note: `FooS<'_>` must implement `Foo<'0>`, for any lifetime `'0`...
8    = note: ...but `FooS<'_>` actually implements `Foo<'1>`, for some specific lifetime `'1`

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/higher-ranked/trait-bounds/due-to-where-clause/due-to-where-clause.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args higher-ranked/trait-bounds/due-to-where-clause.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/higher-ranked/trait-bounds/due-to-where-clause.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/higher-ranked/trait-bounds/due-to-where-clause" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/higher-ranked/trait-bounds/due-to-where-clause/auxiliary"
--- stderr -------------------------------
error: implementation of `Foo` is not general enough
##[error]  --> /checkout/tests/ui/higher-ranked/trait-bounds/due-to-where-clause.rs:2:5
   |
   |
LL |     test::<FooS>(&mut 42); //~ ERROR implementation of `Foo` is not general enough
   |     ^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
   |
   = note: `FooS<'_>` must implement `Foo<'0>`, for any lifetime `'0`...
   = note: ...but `FooS<'_>` actually implements `Foo<'1>`, for some specific lifetime `'1`
error: aborting due to 1 previous error
------------------------------------------


@bors
Copy link
Contributor

bors commented Apr 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants