Skip to content

Print a backtrace in const eval if interrupted#111769

Merged
bors merged 1 commit into
rust-lang:masterfrom
saethlin:ctfe-backtrace-ctrlc
Mar 26, 2024
Merged

Print a backtrace in const eval if interrupted#111769
bors merged 1 commit into
rust-lang:masterfrom
saethlin:ctfe-backtrace-ctrlc

Conversation

@saethlin

@saethlin saethlin commented May 19, 2023

Copy link
Copy Markdown
Member

Demo:

#![feature(const_eval_limit)]
#![const_eval_limit = "0"]

const OW: u64 = {
    let mut res: u64 = 0;
    let mut i = 0;
    while i < u64::MAX {
        res = res.wrapping_add(i);
        i += 1;
    }
    res
};

fn main() {
    println!("{}", OW);
}
╭ ➜ ben@archlinux:~/rust
╰ ➤ rustc +stage1 spin.rs 
^Cerror[E0080]: evaluation of constant value failed
 --> spin.rs:8:33
  |
8 |         res = res.wrapping_add(i);
  |                                 ^ Compilation was interrupted

note: erroneous constant used
  --> spin.rs:15:20
   |
15 |     println!("{}", OW);
   |                    ^^

note: erroneous constant used
  --> spin.rs:15:20
   |
15 |     println!("{}", OW);
   |                    ^^
   |
   = note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.

@rustbot

rustbot commented May 19, 2023

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

(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 May 19, 2023
@rust-log-analyzer

This comment has been minimized.

@oli-obk

oli-obk commented May 22, 2023

Copy link
Copy Markdown
Contributor

Yea, this is exactly what I wanted. Do any of the new deps have problematic licenses? Otherwise seems fine to just add them to the list of allowed crates.

@saethlin

Copy link
Copy Markdown
Member Author

ctrlc is MIT or Apache-2.0, nix is MIT. I'll try to spruce up the implementation then get this reviewed.

Jynn said Mark has previously been uncomfortable with signal handlers or atexit code, so I'd prefer Mark approve this before it goes in (got lucky with the random selection I suppose).

@Mark-Simulacrum Mark-Simulacrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems broadly fine to me, my main concern here is that we don't write custom code where we need to be worried about signal safety etc to a great degree. But it seems like that's not being done here, which is good.

Comment thread compiler/rustc_const_eval/src/const_eval/eval_queries.rs Outdated
@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from 8666de9 to a875a94 Compare May 22, 2023 20:26
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 22, 2023
@saethlin saethlin marked this pull request as ready for review May 22, 2023 20:37
@rustbot

rustbot commented May 22, 2023

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@saethlin

saethlin commented May 22, 2023

Copy link
Copy Markdown
Member Author

Just so everyone follows along, we recently added a mechanism like this to Miri: rust-lang/miri#2899

Since we ctrlc::set_hook inside rustc_driver::main, Miri should probably keep installing its own hook, but it might be nice to use the static inside rustc_*. cc @RalfJung (ah duh the bot has pinged you already, well now you know I really care about you knowing :p )

Comment thread compiler/rustc_driver_impl/Cargo.toml Outdated
@oli-obk

oli-obk commented May 23, 2023

Copy link
Copy Markdown
Contributor

Miri should probably keep installing its own hook, but it might be nice to use the static inside rustc_*.

You could do this change in this PR, subtrees ftw

Comment thread compiler/rustc_data_structures/src/lib.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

You could do this change in this PR, subtrees ftw

We should first push Miri changes to rustc though or else we'll get conflicts.

@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from a875a94 to 83d59c7 Compare May 23, 2023 13:24
@bors

bors commented May 24, 2023

Copy link
Copy Markdown
Collaborator

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

@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from 83d59c7 to f42df5f Compare May 24, 2023 03:02
@rustbot

rustbot commented May 24, 2023

Copy link
Copy Markdown
Collaborator

The Miri subtree was changed

cc @rust-lang/miri

Comment thread compiler/rustc_middle/src/mir/interpret/error.rs Outdated
@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from f42df5f to cf2055b Compare May 24, 2023 21:52
@RalfJung

Copy link
Copy Markdown
Member

r=me on the interpreter changes. Do we still need to get some approval for the new rustc dependencies?

@bors

bors commented May 25, 2023

Copy link
Copy Markdown
Collaborator

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

@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from cf2055b to 38a5fee Compare May 25, 2023 12:07
@saethlin

Copy link
Copy Markdown
Member Author

I'm happy to wait for @Mark-Simulacrum to swing by again and offer an opinion :)

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r=RalfJung

@bors

bors commented May 29, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit 38a5fee has been approved by RalfJung

It is now in the queue for this repository.

@bors

bors commented Mar 9, 2024

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 64cbfac with merge 0f63e28...

@rust-log-analyzer

This comment has been minimized.

@bors

bors commented Mar 9, 2024

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@saethlin

saethlin commented Mar 9, 2024

Copy link
Copy Markdown
Member Author

CI failed (because I added a dist job to CI) but the freebsd dist build finished, which is what held us up last time.

I didn't want to put something in the bors queue that will just fail, because the queue is so busy right now. If this doesn't work, I'm just going to reimplement ctrlc on top of libc instead of using nix because that crate has been so much trouble.

@bors

bors commented Mar 10, 2024

Copy link
Copy Markdown
Collaborator

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

@saethlin

Copy link
Copy Markdown
Member Author

There's been no changes to the actual code in this PR, other than bumping the ctrlc version. Let's try again.

@bors r=RalfJung

@bors

bors commented Mar 10, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit f7bf976 has been approved by RalfJung

It is now in the queue for this repository.

Comment thread Cargo.lock Outdated
dependencies = [
"cfg-if",
"windows-targets 0.52.4",
"windows-targets 0.48.5",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did this get downgraded?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

rebase mistake probably.

/// `rustc_driver::main` installs a handler that will set this to `true` if
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
/// This static is placed here so that it is available to all parts of the compiler.
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rustc_data_structures seems like a strange place to put this. You're using this in rustc_const_eval and rustc_driver_impl. rustc_driver_impl depends on rustc_const_eval. Can't you put the static into rustc_const_eval?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup.

fn run_threads(&mut self) -> InterpResult<'tcx, !> {
static SIGNALED: AtomicBool = AtomicBool::new(false);
// In normal rustc, rustc_driver::main installs this handler. But we don't use that
// function, see src/bin/miri.rs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this is a "thing the driver would do", then it probably makes more sense to install this in miri.rs than in the library.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably. I factored the installation into a rustc_driver function that we call in miri.rs.

@RalfJung

RalfJung commented Mar 10, 2024

Copy link
Copy Markdown
Member

Sorry, I came up with some more questions in the ~10 months since I wrote the previous r=me. ;)

@RalfJung

Copy link
Copy Markdown
Member

@bors r-

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

r=me with some last nits, but we'll have to figure out this approval for the new dependency

Comment thread compiler/rustc_driver_impl/src/lib.rs Outdated
Comment thread src/tools/miri/src/bin/miri.rs Outdated
Comment thread src/tools/tidy/src/deps.rs
@RalfJung

RalfJung commented Mar 11, 2024 via email

Copy link
Copy Markdown
Member

@bors

bors commented Mar 17, 2024

Copy link
Copy Markdown
Collaborator

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

@rustbot

rustbot commented Mar 17, 2024

Copy link
Copy Markdown
Collaborator

Some changes occurred in run-make tests.

cc @jieyouxu

@saethlin saethlin mentioned this pull request Mar 18, 2024
@saethlin

Copy link
Copy Markdown
Member Author

@bors r=RalfJung

@bors

bors commented Mar 25, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 9e0d1a3 has been approved by RalfJung

It is now in the queue for this repository.

@bors

bors commented Mar 26, 2024

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 9e0d1a3 with merge c98ea0d...

@bors

bors commented Mar 26, 2024

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing c98ea0d to master...

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (c98ea0d): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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)
4.3% [3.4%, 5.1%] 2
Improvements ✅
(primary)
-1.6% [-3.2%, -0.9%] 12
Improvements ✅
(secondary)
-2.3% [-3.1%, -1.2%] 16
All ❌✅ (primary) -1.6% [-3.2%, -0.9%] 12

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

Binary size

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

Bootstrap: 671.315s -> 675.795s (0.67%)
Artifact size: 315.65 MiB -> 315.67 MiB (0.00%)

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  PR_MESSAGE: Automation to keep dependencies in `Cargo.lock` current.
following is the output from `cargo update`:
  COMMIT_MESSAGE: cargo update 
##[endgroup]
Starting download for Cargo-lock
##[error]Unable to find any artifacts for the associated workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.