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

Create const block DefIds in typeck instead of ast lowering #124650

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

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 3, 2024

r? @ghost

this is a prerequisite for cleaning up pattern types and the range pattern HIR nodes in general. Right now they contain expressions, but they are supposed to only contain constants. In order to generate the anonymous constants lazily during typeck, we need to support generating new items with bodies during typeck in general. Transforming const blocks was the simplest change I could find to allow us to do that (everything else is much more invasive if we haven't already done it for const blocks).

The guarded call will ICE on its own.

While this improved diagnostics in the presence of bugs somewhat, it is also a blocker to query feeding of constants. If this case is hit again, we should instead improve diagnostics of the root ICE
…am_attrs`

This can cause query cycles in const eval, when const eval checks the ABI of functions, as mir_keys can depend on `typeck` to find all newly generated items (like const blocks)
@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 May 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2024

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

@oli-obk
Copy link
Contributor Author

oli-obk commented May 3, 2024

@bors try @rust-timer queue
w

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 3, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
Create const block DefIds in typeck instead of ast lowering

r? `@ghost`

this is a prerequisite for cleaning up pattern types and the range pattern HIR nodes in general. Right now they contain expressions, but they are supposed to only contain constants. In order to generate the anonymous constants lazily during typeck, we need to support generating new items with bodies during typeck in general. Transforming const blocks was the simplest change I could find to allow us to do that (everything else is much more invasive if we haven't already done it for const blocks).
@bors
Copy link
Contributor

bors commented May 3, 2024

⌛ Trying commit edb59c9 with merge eeec347...

Comment on lines -393 to +392
ty::InstanceDef::Item(def) => {
if ecx.tcx.is_ctfe_mir_available(def) {
Ok(ecx.tcx.mir_for_ctfe(def))
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
ecx.tcx.dcx().bug("This is likely a const item that is missing from its impl");
} else {
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
// so this should be unreachable.
let path = ecx.tcx.def_path_str(def);
bug!("trying to call extern function `{path}` at compile-time");
}
}
ty::InstanceDef::Item(def) => Ok(ecx.tcx.mir_for_ctfe(def)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is_ctfe_mir_available invokes mir_keys, which now invokes typeck, so we'd get cycles

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Getting action download info
Download action repository 'msys2/[email protected]' (SHA:cc11e9188b693c2b100158c3322424c4cc1dadea)
Download action repository 'actions/checkout@v4' (SHA:0ad4b8fadaa221de15dcec353f45205ec38ea70b)
Download action repository 'actions/upload-artifact@v4' (SHA:65462800fd760344b1a7b4382951275a0abb4808)
Complete job name: PR - mingw-check-tidy
git config --global core.autocrlf false
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt \
    && pip3 install virtualenv
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---

#12 [5/8] COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
#12 DONE 0.0s

#13 [6/8] RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt     && pip3 install virtualenv
#13 0.446   Downloading binaryornot-0.4.4-py2.py3-none-any.whl (9.0 kB)
#13 0.465 Collecting boolean-py==4.0
#13 0.472   Downloading boolean.py-4.0-py3-none-any.whl (25 kB)
#13 0.488 Collecting chardet==5.1.0
---
#13 3.669 Building wheels for collected packages: reuse
#13 3.670   Building wheel for reuse (pyproject.toml): started
#13 3.993   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 3.994   Created wheel for reuse: filename=reuse-1.1.0-cp310-cp310-manylinux_2_35_x86_64.whl size=181117 sha256=f5f58750481f69515c2c0d1d503daf565e2565c370d07fc6aeb95fe3498b4269
#13 3.994   Stored in directory: /tmp/pip-ephem-wheel-cache-vhtlp0f2/wheels/c2/3c/b9/1120c2ab4bd82694f7e6f0537dc5b9a085c13e2c69a8d0c76d
#13 3.997 Installing collected packages: boolean-py, binaryornot, setuptools, reuse, python-debian, markupsafe, license-expression, jinja2, chardet
#13 4.020   Attempting uninstall: setuptools
#13 4.020     Found existing installation: setuptools 59.6.0
#13 4.021     Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
---
#13 5.262   Downloading virtualenv-20.26.1-py3-none-any.whl (3.9 MB)
#13 5.320      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 70.7 MB/s eta 0:00:00
#13 5.376 Collecting filelock<4,>=3.12.2
#13 5.383   Downloading filelock-3.14.0-py3-none-any.whl (12 kB)
#13 5.416 Collecting platformdirs<5,>=3.9.1
#13 5.425   Downloading platformdirs-4.2.1-py3-none-any.whl (17 kB)
#13 5.448 Collecting distlib<1,>=0.3.7
#13 5.456   Downloading distlib-0.3.8-py2.py3-none-any.whl (468 kB)
#13 5.462      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 122.2 MB/s eta 0:00:00
#13 5.548 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 5.720 Successfully installed distlib-0.3.8 filelock-3.14.0 platformdirs-4.2.1 virtualenv-20.26.1
#13 DONE 5.8s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      190400 kB
DirectMap2M:     7149568 kB
DirectMap1G:    11534336 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
    Finished `dev` profile [unoptimized] target(s) in 0.03s
##[endgroup]
downloading https://ci-artifacts.rust-lang.org/rustc-builds-alt/79734f1db8dbe322192dea32c0f6b80ab14c4c1d/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
extracting /checkout/obj/build/cache/llvm-79734f1db8dbe322192dea32c0f6b80ab14c4c1d-true/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm
---
   Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
    Finished `release` profile [optimized] target(s) in 25.53s
##[endgroup]
fmt check
##[error]Diff in /checkout/compiler/rustc_parse/src/parser/mod.rs at line 25:
 use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
 use rustc_ast::{
 use rustc_ast::{
-    self as ast, AttrArgs, AttrArgsEq, AttrId, ByRef, Const, CoroutineKind, DelimArgs,
-    Expr, ExprKind, Extern, HasAttrs, HasTokens, Mutability, StrLit, Unsafe, Visibility,
-    VisibilityKind, DUMMY_NODE_ID,
+    self as ast, AttrArgs, AttrArgsEq, AttrId, ByRef, Const, CoroutineKind, DelimArgs, Expr,
+    ExprKind, Extern, HasAttrs, HasTokens, Mutability, StrLit, Unsafe, Visibility, VisibilityKind,
+    DUMMY_NODE_ID,
 use rustc_ast_pretty::pprust;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::fx::FxHashMap;
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_parse/src/parser/stmt.rs" "/checkout/compiler/rustc_parse/src/parser/item.rs" "/checkout/compiler/rustc_parse/src/parser/attr.rs" "/checkout/compiler/rustc_parse/src/parser/pat.rs" "/checkout/compiler/rustc_parse/src/parser/diagnostics.rs" "/checkout/compiler/rustc_parse/src/parser/attr_wrapper.rs" "/checkout/compiler/rustc_parse/src/parser/path.rs" "/checkout/compiler/rustc_parse/src/parser/mod.rs" "/checkout/compiler/rustc_parse/src/parser/ty.rs" "/checkout/compiler/rustc_parse/src/parser/expr.rs" "/checkout/compiler/rustc_parse/src/parser/generics.rs" "/checkout/compiler/rustc_parse/src/parser/nonterminal.rs" "/checkout/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs" "/checkout/compiler/rustc_parse/src/lexer/tokentrees.rs" "/checkout/compiler/rustc_parse/src/lexer/diagnostics.rs" "/checkout/compiler/rustc_parse/src/lexer/mod.rs" "/checkout/compiler/rustc_parse/src/lexer/unicode_chars.rs" "/checkout/compiler/rustc_hir_typeck/src/upvar.rs" "/checkout/compiler/rustc_hir_typeck/src/errors.rs" "/checkout/compiler/rustc_hir_typeck/src/writeback.rs" "/checkout/compiler/rustc_hir_typeck/src/gather_locals.rs" "/checkout/compiler/rustc_hir_typeck/src/place_op.rs" "/checkout/compiler/rustc_hir_typeck/src/diverges.rs" "/checkout/compiler/rustc_hir_typeck/src/pat.rs" "/checkout/compiler/rustc_hir_typeck/src/coercion.rs" "/checkout/compiler/rustc_hir_typeck/src/fallback.rs" "/checkout/compiler/rustc_hir_typeck/src/closure.rs" "/checkout/compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs" "/checkout/compiler/rustc_hir_typeck/src/autoderef.rs" "/checkout/compiler/rustc_hir_typeck/src/lib.rs" "/checkout/compiler/rustc_hir_typeck/src/rvalue_scopes.rs" "/checkout/compiler/rustc_hir_typeck/src/op.rs" "/checkout/compiler/rustc_hir_typeck/src/check.rs" "/checkout/compiler/rustc_hir_typeck/src/_match.rs" "/checkout/compiler/rustc_hir_typeck/src/demand.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs" "/checkout/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs" "/checkout/compiler/rustc_hir_typeck/src/callee.rs" "/checkout/compiler/rustc_hir_typeck/src/expr.rs" "/checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs" "/checkout/compiler/rustc_hir_typeck/src/intrinsicck.rs" "/checkout/compiler/rustc_hir_typeck/src/mem_categorization.rs" "/checkout/compiler/rustc_hir_typeck/src/cast.rs" "/checkout/compiler/rustc_hir_typeck/src/expectation.rs" "/checkout/compiler/rustc_hir_typeck/src/method/suggest.rs" "/checkout/compiler/rustc_hir_typeck/src/method/confirm.rs" "/checkout/compiler/rustc_hir_typeck/src/method/probe.rs" "/checkout/compiler/rustc_hir_typeck/src/method/mod.rs" "/checkout/compiler/rustc_hir_typeck/src/method/prelude2021.rs" "/checkout/compiler/rustc_passes/src/layout_test.rs" "/checkout/compiler/rustc_passes/src/debugger_visualizer.rs" "/checkout/compiler/rustc_passes/src/errors.rs" "/checkout/compiler/rustc_passes/src/diagnostic_items.rs" "/checkout/compiler/rustc_passes/src/liveness.rs" "/checkout/compiler/rustc_passes/src/stability.rs" "/checkout/compiler/rustc_passes/src/reachable.rs" "/checkout/compiler/rustc_passes/src/hir_stats.rs" "/checkout/compiler/rustc_passes/src/hir_id_validator.rs" "/checkout/compiler/rustc_parse/src/lib.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
  local time: Fri May  3 09:37:41 UTC 2024
  network time: Fri, 03 May 2024 09:37:41 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] shlex test:false 0.409
   Compiling rustc-main v0.0.0 (/checkout/compiler/rustc)
error[E0391]: cycle detected when getting a list of all mir_keys
    |
note: ...which requires type-checking `date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::from_julian_day`...
   --> /rust/deps/time-0.3.34/src/date.rs:255:5
    |
255 |     pub const fn from_julian_day(julian_day: i32) -> Result<Self, error::ComponentRange> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires evaluating type-level constant...
   --> /rust/deps/time-0.3.34/src/date.rs:256:36
    |
256 |         type JulianDay = RangedI32<{ Date::MIN.to_julian_day() }, { Date::MAX.to_julian_day() }>;
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::from_julian_day::JulianDay::{constant#0}`...
   --> /rust/deps/time-0.3.34/src/date.rs:256:36
    |
256 |         type JulianDay = RangedI32<{ Date::MIN.to_julian_day() }, { Date::MAX.to_julian_day() }>;
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing call ABI of `date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::to_julian_day`...
   --> /rust/deps/time-0.3.34/src/date.rs:719:5
    |
719 |     pub const fn to_julian_day(self) -> i32 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires deducing parameter attributes for date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::to_julian_day...
   --> /rust/deps/time-0.3.34/src/date.rs:719:5
    |
719 |     pub const fn to_julian_day(self) -> i32 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::to_julian_day`...
   --> /rust/deps/time-0.3.34/src/date.rs:719:5
    |
719 |     pub const fn to_julian_day(self) -> i32 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires checking if item has MIR available: `date::<impl at /rust/deps/time-0.3.34/src/date.rs:58:1: 58:10>::year`...
   --> /rust/deps/time-0.3.34/src/date.rs:311:5
    |
311 |     pub const fn year(self) -> i32 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: ...which again requires getting a list of all mir_keys, completing the cycle
note: cycle used when checking if item has MIR available: `utc_offset::<impl at /rust/deps/time-0.3.34/src/utc_offset.rs:59:1: 59:15>::__from_hms_unchecked`
   --> /rust/deps/time-0.3.34/src/utc_offset.rs:83:5
    |
83  |     pub const unsafe fn __from_hms_unchecked(hours: i8, minutes: i8, seconds: i8) -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = 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
[RUSTC-TIMING] build_script_build test:false 0.172
For more information about this error, try `rustc --explain E0391`.
[RUSTC-TIMING] time test:false 0.641
error: could not compile `time` (lib) due to 1 previous error
---
Caused by:
    Command RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj] has failed with exit code Some(1)

Stack backtrace:
   0: <anyhow::Error>::msg::<alloc::string::String>
             at /rust/deps/anyhow-1.0.81/src/backtrace.rs:27:14
   1: <opt_dist::exec::CmdBuilder>::run
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/exec.rs:78:17
   2: <opt_dist::exec::Bootstrap>::run
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/exec.rs:179:9
   3: opt_dist::execute_pipeline::{closure#1}::{closure#0}
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/main.rs:210:13
   4: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}::{closure#0}, ()>
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/timer.rs:111:22
   5: opt_dist::execute_pipeline::{closure#1}
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/main.rs:199:9
   6: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}, opt_dist::training::RustcPGOProfile>
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/timer.rs:111:22
   7: opt_dist::execute_pipeline
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/main.rs:196:29
             at /rustc/eeec347bcee500a42fb7c74e66b5c765222b8ae6/src/tools/opt-dist/src/main.rs:386:18
   9: <fn() -> core::result::Result<(), anyhow::Error> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/6b544f5ff8d45221d61962651a5f5ab9fe535e16/library/core/src/ops/function.rs:250:5
  10: std::sys_common::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
  10: std::sys_common::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
             at /rustc/6b544f5ff8d45221d61962651a5f5ab9fe535e16/library/std/src/sys_common/backtrace.rs:155:18
  11: std::rt::lang_start::<core::result::Result<(), anyhow::Error>>::{closure#0}
             at /rustc/6b544f5ff8d45221d61962651a5f5ab9fe535e16/library/std/src/rt.rs:159:18
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
  13: std::panicking::try::do_call
             at /rustc/6b544f5ff8d45221d61962651a5f5ab9fe535e16/library/std/src/panicking.rs:559:40
  14: std::panicking::try
             at /rustc/6b544f5ff8d45221d61962651a5f5ab9fe535e16/library/std/src/panicking.rs:523:19

@bors
Copy link
Contributor

bors commented May 3, 2024

💔 Test failed - checks-actions

@bors bors 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 May 3, 2024
@bors
Copy link
Contributor

bors commented May 4, 2024

☔ The latest upstream changes (presumably #124401) 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
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-perf Status: Waiting on a perf run to be completed. 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

5 participants