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

Regression: Fail to evaluate self-referential static slices #120949

Closed
nvzqz opened this issue Feb 11, 2024 · 5 comments · Fixed by #120960
Closed

Regression: Fail to evaluate self-referential static slices #120949

nvzqz opened this issue Feb 11, 2024 · 5 comments · Fixed by #120960
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nvzqz
Copy link
Contributor

nvzqz commented Feb 11, 2024

Code

I tried this code:

struct Value {
    values: &'static [&'static Value],
}

static VALUE: Value = Value {
    values: &[&VALUE],
};

I expected to see this happen: compile fine, with the VALUE static containing a slice that references VALUE.

Instead, this happened:

error[E0391]: cycle detected when const-evaluating + checking `VALUE`
 --> src/main.rs:6:13
  |
6 |     values: &[&VALUE],
  |             ^^^^^^^^^
  |
note: ...which requires simplifying constant for the type system `VALUE::promoted[0]`...
 --> src/main.rs:5:1
  |
5 | static VALUE: Value = Value {
  | ^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `VALUE::promoted[0]`...
 --> src/main.rs:5:1
  |
5 | static VALUE: Value = Value {
  | ^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires const-evaluating + checking `VALUE`, completing the cycle
note: cycle used when linting top-level module
 --> src/main.rs:1:1
  |
1 | / struct Value {
2 | |     values: &'static [&'static Value],
3 | | }
4 | |
... |
8 | |
9 | | fn main() {}
  | |____________^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

Version it worked on

It most recently worked on: nightly-2024-02-10

Version with regression

nightly-2024-02-11

rustc --version --verbose:

rustc 1.78.0-nightly (6cc484351 2024-02-10)
binary: rustc
commit-hash: 6cc4843512d613f51ec81aba689180c31b0b28b6
commit-date: 2024-02-10
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 17.0.6
@nvzqz nvzqz added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Feb 11, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 11, 2024
@saethlin saethlin added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Feb 11, 2024
@DaniPopes
Copy link
Contributor

searched nightlies: from nightly-2024-02-10 to nightly-2024-02-11
regressed nightly: nightly-2024-02-11
searched commit range: d44e3b9...6cc4843
regressed commit: 6cc4843

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc -vv --start 2024-02-10 --without-cargo -vv --script rustc -- src/lib.rs 

#119614 cc @RalfJung @oli-obk

@nvzqz
Copy link
Contributor Author

nvzqz commented Feb 11, 2024

Context for how I found this: I use this technique in Divan in code generation for benchmarks of generic functions. The simple example I gave is just a minimal reproduction of the issue.

@saethlin saethlin added A-const-eval Area: constant evaluation (mir interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 12, 2024
@RalfJung
Copy link
Member

Hm, that is very strange. Not sure if there is a good way to get the backtrace of where in the code the cyclic queries are made?

My first guess is that it is the new call to type_of here:

let is_mut =
matches!(self.ecx.tcx.def_kind(did), DefKind::Static(Mutability::Mut))
|| !self
.ecx
.tcx
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters")
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());

But... surely we can ask for the type of a static while evaluating that very static, that can't be cyclic?

@RalfJung
Copy link
Member

Ah no, probably it is related to the fact that we now recursively validate when a constant points to a static. Previously we stopped there. I guess we should not do that for promoteds.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high -E-needs-bisection +T-compiler

@rustbot rustbot added P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Feb 12, 2024
@RalfJung RalfJung added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Feb 12, 2024
@bors bors closed this as completed in ed19532 Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants