Skip to content

Print a backtrace in const eval if interrupted#111769

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

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

Conversation

@saethlin
Copy link
Member

@saethlin saethlin commented May 19, 2023

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
Copy link
Collaborator

rustbot commented May 19, 2023

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
Copy link
Contributor

oli-obk commented May 22, 2023

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
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).

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

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.

@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
Copy link
Collaborator

rustbot commented May 22, 2023

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
Copy link
Member Author

saethlin commented May 22, 2023

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 )

@oli-obk
Copy link
Contributor

oli-obk commented May 23, 2023

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

@RalfJung
Copy link
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
Copy link
Collaborator

bors commented May 24, 2023

☔ 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
Copy link
Collaborator

rustbot commented May 24, 2023

The Miri subtree was changed

cc @rust-lang/miri

@saethlin saethlin force-pushed the ctfe-backtrace-ctrlc branch from f42df5f to cf2055b Compare May 24, 2023 21:52
@RalfJung
Copy link
Member

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

@bors
Copy link
Collaborator

bors commented May 25, 2023

☔ 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
Member Author

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

@Mark-Simulacrum
Copy link
Member

@bors r=RalfJung

@bors
Copy link
Collaborator

bors commented May 29, 2023

📌 Commit 38a5fee has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 9, 2024

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

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Mar 9, 2024

💔 Test failed - checks-actions

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member Author

saethlin commented Mar 9, 2024

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
Copy link
Collaborator

bors commented Mar 10, 2024

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

@saethlin
Copy link
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
Copy link
Collaborator

bors commented Mar 10, 2024

📌 Commit f7bf976 has been approved by RalfJung

It is now in the queue for this repository.

Cargo.lock Outdated
dependencies = [
"cfg-if",
"windows-targets 0.52.4",
"windows-targets 0.48.5",
Copy link
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
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
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
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
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
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
Copy link
Member

RalfJung commented Mar 10, 2024

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

@RalfJung
Copy link
Member

@bors r-

Copy link
Member

@RalfJung RalfJung 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 with some last nits, but we'll have to figure out this approval for the new dependency

@RalfJung
Copy link
Member

RalfJung commented Mar 11, 2024 via email

@bors
Copy link
Collaborator

bors commented Mar 17, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2024

Some changes occurred in run-make tests.

cc @jieyouxu

@saethlin saethlin mentioned this pull request Mar 18, 2024
@saethlin
Copy link
Member Author

@bors r=RalfJung

@bors
Copy link
Collaborator

bors commented Mar 25, 2024

📌 Commit 9e0d1a3 has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 26, 2024

⌛ Testing commit 9e0d1a3 with merge c98ea0d...

@bors
Copy link
Collaborator

bors commented Mar 26, 2024

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

@rust-timer
Copy link
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
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.