profile
viewpoint
Wesley Wiser wesleywiser HighGear Maryland @rust-lang Compiler Team

rust-lang/measureme 70

Support crate for rustc's self-profiling feature

wesleywiser/process_path 4

A Rust library to get the path of the currently executing process

JasonKleban/Unbounded 2

F# to T-SQL. Remote command execution and domain invariant enforcement

wesleywiser/Expert-System 1

An example expert system for CS 428

wesleywiser/FSharpSnippets 1

Snippets and modules of F# code.

wesleywiser/IronJS 1

IronJS - A JavaScript implementation for .NET written in F#

wesleywiser/jquery-mobile 1

jQuery Mobile Framework

wesleywiser/Reconnect-wifi-daemon 1

A simple daemon for Ubuntu which causes your computer to automatically reconnect to a specific wifi access point.

issue commentrust-lang/blog.rust-lang.org

Rust Unstable Book link is broken

Ah, that makes sense. Thank you!

iliekturtles

comment created time in 2 hours

PR opened rust-lang/blog.rust-lang.org

Fix unstable rust book link

Fixes #524

+1 -1

0 comment

1 changed file

pr created time in 2 hours

create barnchwesleywiser/blog.rust-lang.org

branch : fix_link

created branch time in 2 hours

pull request commentrust-lang/rust

[experiment] Test different inline costs

@bors try @rust-timer queue

wesleywiser

comment created time in 2 hours

PR opened rust-lang/rust

[experiment] Test different inline costs

r? @ghost

+2 -2

0 comment

1 changed file

pr created time in 2 hours

push eventwesleywiser/rust

Camille GILLOT

commit sha 369f3601592f38b0689bb58b38094edd3164c9d9

Move rustc::traits datatypes to module traits::types.

view details

Camille GILLOT

commit sha a2cd0715fd3b3121512887e2a1e84e26cd6706f4

Move traits::Reveal to traits::types.

view details

Camille GILLOT

commit sha a77da35ed425b46a8df1df33ffc9563a47bbee6f

Move traits::select datatypes to traits::types.

view details

Camille GILLOT

commit sha 4e42f388c375b0d6eb25af087cb2a66069419529

Move traits::query datatypes to traits::types.

view details

Camille GILLOT

commit sha 9c07dad7258fad6b7504f9e2569fece97fa394b6

Move infer::region_constraints::MemberConstraint to infer::types module.

view details

Camille GILLOT

commit sha 005f14d51809e385eb396bb2c1a115cf9ba21872

Move infer::canonical datatypes to infer::types.

view details

Camille GILLOT

commit sha b3f13b00f5fadad44efd048c69136d18108e0647

Move implementation of UnifyKey to unify_key.rs.

view details

Brian Anderson

commit sha c00d8aa5179ef38f7d83067a8d010bcc26fa0cc3

Reorder declarations of Result::export/unwrap to match Option

view details

Brian Anderson

commit sha db9b578b71190540cfd84f16f5d310d6ce4cb659

Reorder declarations of Result::expect_err/unwrap_err to match Option

view details

Mazdak Farrokhzad

commit sha 17e632d382dfae46e9dfa684db9bddec3e8951a7

or_patterns: test default binding modes

view details

Mazdak Farrokhzad

commit sha b5aca3128d5c0ee2441ec9ca9a9c3ae4f391ef16

typeck: refactor default binding mode logic & improve docs

view details

ljedrz

commit sha 28b0ed020a36e94fe233e2a0ef950fd888b16256

merge item id stable hashing functions

view details

ljedrz

commit sha e8b72f44b0064d0e591f078f6b7f2cf3aa28f540

move item reference comment

view details

bors

commit sha eda1a7adfcf6de70afa4ca0a6f709ed0e507516a

Auto merge of #68755 - Tyg13:update_stdarch, r=alexcrichton Update `rust-lang/stdarch` submodule Update submodule [rust-lang/stdarch](https://github.com/rust-lang/stdarch/)

view details

Mazdak Farrokhzad

commit sha 9a4eac3944e2e2668b4aea0b5afd3d83b88e992e

ast_validation: fix visiting bug.

view details

Josh White

commit sha 82684ad30a0929afba9463b89232730a9c6dadf4

Added long error description & modifed error_codes.rs

view details

Camille GILLOT

commit sha 9444975e96e417beaf9a261292f02c29f0eb7b2b

Split traits::structural_impls in two.

view details

Camille GILLOT

commit sha c851db94951643c2b200b13bf6d8ab6d5fdb541e

Move specialization_graph definition in traits::types.

view details

Camille GILLOT

commit sha 551cc5ebe626e93b23d02eb9ff363943e7505e52

Move ExpectedFound::new to ty::error.

view details

Camille GILLOT

commit sha 735d664e7401de8f272cf26f404d1f0a44db5471

Move EvaluationCache::clear.

view details

push time in 2 hours

pull request commentrust-lang/blog.rust-lang.org

Fix a bad path and simplify one of the examples

r? @XAMPPRocky

wesleywiser

comment created time in 5 hours

issue commentrust-lang/blog.rust-lang.org

Rust Unstable Book link is broken

The links should go live the next time the Rust Unstable Book is deployed which I thought would happen nightly. Perhaps it's on a different schedule than that?

iliekturtles

comment created time in 6 hours

issue commentrust-lang/rust

Miri exception improvements

Didn't we also discuss checking the current query name somewhere?

Yes, it was proposed here but at least for ctfe-stress-4, that didn't pay off because most of the errors were created during const_eval-raw (see here).

RalfJung

comment created time in 8 hours

PR opened rust-lang/blog.rust-lang.org

Fix a bad path and simplify one of the examples

Feedback from @andjo403

r? @nikomatsakis

+2 -3

0 comment

1 changed file

pr created time in a day

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha f2118fd55b7ce075c6244cb5bf3b14fa7866a3e5

Fix a bad path and simplify one of the examples

view details

push time in a day

delete branch wesleywiser/blog.rust-lang.org

delete branch : self_profiler

delete time in a day

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha 85e32c9afc621b013207e85c11703fa87c0136cf

[Inside Rust] Intro to rustc's self-profile feature

view details

push time in 2 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

Thanks @nikomatsakis! Once this lands, I'll update the blog post to link to these docs, update the post date and then we'll be ready to post it.

wesleywiser

comment created time in 2 days

issue openedrust-lang/measureme

`summarize` shouldn't show columns that don't apply to the profile

For example, most people do not enable query cache hit events or use a parallel compiler so the "Cache Hits" and "Blocked time" columns never have values. We should hide those columns in this case.

created time in 2 days

delete branch wesleywiser/measureme

delete branch : update_docs

delete time in 4 days

push eventrust-lang/measureme

Wesley Wiser

commit sha b70537d825ef0b4ac50c48d6c145497f4440d04b

Update the docs to use `cargo install` instead of manually compiling

view details

Wesley Wiser

commit sha 8872e70531b4afef9a2ed54ccfe0c94558eaf59e

Merge pull request #111 from wesleywiser/update_docs Update the docs to use `cargo install` instead of manually compiling

view details

push time in 4 days

push eventwesleywiser/measureme

Wesley Wiser

commit sha b70537d825ef0b4ac50c48d6c145497f4440d04b

Update the docs to use `cargo install` instead of manually compiling

view details

push time in 4 days

create barnchwesleywiser/measureme

branch : update_docs

created branch time in 6 days

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha d94aceafa58f46c40e1da8331ffffa5a05bed734

[Inside Rust] Intro to rustc's self-profile feature

view details

push time in 6 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

Thanks @michaelwoerister! I applied your suggestions.

wesleywiser

comment created time in 6 days

push eventwesleywiser/rust

Wesley Wiser

commit sha 5b7e6c0f3c71891a40a77493bb251fccd5944feb

Add documentation for the `-Zself-profile-events` flag

view details

push time in 6 days

PR opened rust-lang/rust

Add test for #69312

This bug was fixed by #67501.

Closes #69312

+10 -0

0 comment

1 changed file

pr created time in 6 days

create barnchwesleywiser/rust

branch : test_for_69312

created branch time in 6 days

issue commentrust-lang/rust

beta regression: ICE on Tried to access field 0 of union Layout

Given the backtrace, I think it's probably

  • #67501 (Reduce special treatment for zsts)
Mark-Simulacrum

comment created time in 6 days

issue commentrust-lang/rust

ICE in constprop due to out of bounds access in a zero sized array

cargo bisect-rustc points to #67501 as being responsible for fixing this.

gwafotapa

comment created time in 6 days

delete branch rust-lang/compiler-team

delete branch : wesleywiser-patch-3

delete time in 7 days

delete branch rust-lang/compiler-team

delete branch : wesleywiser-patch-1

delete time in 7 days

delete branch rust-lang/compiler-team

delete branch : wesleywiser-patch-2

delete time in 7 days

delete branch rust-lang/compiler-team

delete branch : wesleywiser-patch-5

delete time in 7 days

pull request commentrust-lang/blog.rust-lang.org

[Inside Rust] Intro to rustc's self-profile feature

Updated post for today's date.

wesleywiser

comment created time in 7 days

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha 703d40a3461bea3547da000e68da56366bdb2df5

[Inside Rust] Intro to rustc's self-profile feature

view details

push time in 7 days

Pull request review commentrust-lang/blog.rust-lang.org

[Inside Rust] Intro to rustc's self-profile feature

+---+layout: post+title: "Intro to rustc's self profiler"+author: Wesley Wiser+description: "Learn how to use the -Zself-profile rustc flag"+team: the self-profile working group <https://rust-lang.github.io/compiler-team/working-groups/self-profile/>+---++Over the last year, the [Self-Profile Working Group] has been building tools to profile `rustc` because we often hear requests to know where compilation time is being spent.+This is useful when optimizing the compiler, one of the Compiler Team's ongoing efforts to improve compile times, but it's also useful to users who want to refactor their crate so that it will compile faster.+We've been working on a new feature that will help with that and this blog post gives a preview of how it works.+Be warned, though: it is still experimental and we expect the interface to change over time.+The Rust Unstable Book has [documentation for this feature] and we'll keep that up to date so you can always find the latest instructions there.++In this post, we'll look at the tools currently available and use them to profile `rustc` while it compiles an example crate.++## Setup++First, we'll download and build the `measureme` repository which provides tools to analyze self-profile trace data.++```sh+$ git clone https://github.com/rust-lang/measureme.git+$ cd measureme+$ cargo build --release --all+```++Now that we have our tools, let's download an example crate to profile its build.++```sh+$ cd ..+$ git clone https://github.com/rust-lang/regex.git+$ cd regex+```++We'll need to use a recent nightly compiler to get access to unstable `-Z` flags.++```sh+$ rustup override set nightly+```++If you haven't installed a nightly compiler before, this will download the nightly compiler for you.+If you have, then update it to make sure you're on a recent version.++```sh+$ rustup update nightly+```++## Profiling the compiler++Now we can build it and tell `rustc` to profile the build of the `regex` crate.+This will cause three new files to be created in the working directory which contain the profling data.++```sh+$ cargo rustc -- -Zself-profile+$ ls+CHANGELOG.md        LICENSE-APACHE       UNICODE.md              regex-17088.string_data       regex-syntax         target+Cargo.lock          LICENSE-MIT          bench                   regex-17088.string_index      rustfmt.toml         test+Cargo.toml          PERFORMANCE.md       examples                regex-capi                    scripts              tests+HACKING.md          README.md            regex-17088.events      regex-debug                   src+```++The new files follow the format `{crate name}-{rustc process id}.{events,string_data,string_index}`.++We'll use each of the three main tools to analyze the profiling data:++### `summarize`++As its name suggests, this tool summarizes the data found in the trace files.+Additionally, `summarize` can also show a "diff" between two trace files but we won't be using this mode.++Let's run the tool, passing just the file name (but not the extension) for the trace:++```sh+$ ../measureme/target/release/summarize summarize regex-17088++-----------------------------------------------+-----------+-----------------+----------+------------++| Item                                          | Self time | % of total time | Time     | Item count |++-----------------------------------------------+-----------+-----------------+----------+------------++| LLVM_module_codegen_emit_obj                  | 4.89s     | 42.752          | 4.89s    | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| codegen_module                                | 1.25s     | 10.967          | 1.37s    | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| LLVM_module_optimize_module_passes            | 1.15s     | 10.022          | 1.15s    | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| LLVM_module_codegen_make_bitcode              | 786.56ms  | 6.875           | 960.73ms | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| typeck_tables_of                              | 565.18ms  | 4.940           | 689.39ms | 848        |++-----------------------------------------------+-----------+-----------------+----------+------------++| LLVM_module_codegen                           | 408.01ms  | 3.566           | 6.26s    | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| mir_borrowck                                  | 224.03ms  | 1.958           | 543.33ms | 848        |++-----------------------------------------------+-----------+-----------------+----------+------------++| LLVM_module_codegen_emit_compressed_bitcode   | 174.17ms  | 1.522           | 174.17ms | 159        |++-----------------------------------------------+-----------+-----------------+----------+------------++| optimized_mir                                 | 157.91ms  | 1.380           | 205.29ms | 1996       |++-----------------------------------------------+-----------+-----------------+----------+------------++| evaluate_obligation                           | 146.50ms  | 1.281           | 184.17ms | 8304       |++-----------------------------------------------+-----------+-----------------+----------+------------++| codegen_crate                                 | 139.48ms  | 1.219           | 1.58s    | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++| mir_built                                     | 123.88ms  | 1.083           | 168.01ms | 848        |++-----------------------------------------------+-----------+-----------------+----------+------------++| metadata_decode_entry                         | 88.36ms   | 0.772           | 117.77ms | 55642      |++-----------------------------------------------+-----------+-----------------+----------+------------++| incr_comp_copy_cgu_workproducts               | 64.21ms   | 0.561           | 64.21ms  | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++| monomorphization_collector_graph_walk         | 54.11ms   | 0.473           | 344.00ms | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++| link_rlib                                     | 43.21ms   | 0.378           | 43.21ms  | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++| check_impl_item_well_formed                   | 41.36ms   | 0.362           | 77.14ms  | 736        |++-----------------------------------------------+-----------+-----------------+----------+------------++| codegen_fulfill_obligation                    | 40.36ms   | 0.353           | 51.56ms  | 1759       |++-----------------------------------------------+-----------+-----------------+----------+------------++| expand_crate                                  | 37.24ms   | 0.326           | 48.52ms  | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++| symbol_name                                   | 36.31ms   | 0.317           | 39.06ms  | 5513       |++-----------------------------------------------+-----------+-----------------+----------+------------++| free_global_ctxt                              | 34.34ms   | 0.300           | 34.34ms  | 1          |++-----------------------------------------------+-----------+-----------------+----------+------------++...+Total cpu time: 11.440758871s+```++The output is sorted by the self time (time spent in the query or activity but not other queries or activities called by itself).+As you can see, most of the compilation time is spent in LLVM generating the binary code for the executable.++### `flamegraph`++As you may have guessed, `flamegraph` will produce a [flame graph] of the profiling data.+To run the tool, we'll pass just the filename without a file extension like we did for `summarize`:++```sh+$ ../measureme/target/release/flamegraph regex-17088+```++This will create a file called `rustc.svg` in the working directory:++[![Image of flamegraph output][flame graph img]][flame graph img]++[Click here] to try the interactive svg.++### `crox`++This tool processes self-profiling data into the JSON format that the Chromium profiler understands.+You can use it to create a graphical timeline showing exactly when various traced events occurred.++In this section, we'll cover a few different modes `crox` can run in such as profiling an entire crate compilation including dependencies and filtering out small events.+Let's get started with the basics!++#### Basic usage++To run the tool, we'll just pass the filename without a file extension like we've done before:++```sh+$ ../measureme/target/release/crox regex-17088+```++This creates a file called `chrome_profiler.json` in the working directory.+To open it, we'll use the regular Chromium performance tools you might already be familiar with:++1. Open Chrome+2. Open the Developer Tools console by pressing `Ctrl` + `Shift` + `i` (Windows/Linux) or `Cmd` + `Option` + `i` (macOS)+3. Click the Performance tab at the top of the console.+4. Click the "Load profile" button which looks like an arrow pointing up.+5. Select the `chrome_profiler.json` file we created.++You should now see something similar to this:

Yes, that's true. I've used that in the past with large trace files which caused the regular tools to choke but it seemed to work fine in this case so I thought it best to keep this as simple as possible. We should document this though probably in the Crox docs.

wesleywiser

comment created time in 7 days

create barnchrust-lang/compiler-team

branch : wesleywiser-patch-5

created branch time in 7 days

create barnchrust-lang/compiler-team

branch : wesleywiser-patch-2

created branch time in 7 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

cc @michaelwoerister

wesleywiser

comment created time in 7 days

pull request commentrust-lang/rust

Tune inlining for query execution

@bors r+ rollup=never

Zoxc

comment created time in 7 days

pull request commentrust-lang/rust

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors

@bors r=RalfJung

wesleywiser

comment created time in 7 days

push eventwesleywiser/rust

Wesley Wiser

commit sha 9f3bc82fe40fd38fadfd24b7968548929abc9d4c

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors Before this change, `get_size_and_align()` calls `get_fn_alloc()` *a lot* in CTFE heavy code. This previously returned an `Error` which would check if `RUSTC_CTFE_BACKTRACE` was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in #68792. This is an alternate take on that PR which resolves the performance issue by generating *many* fewer errors. Previously, `ctfe-stress-4` would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30.

view details

push time in 7 days

push eventwesleywiser/rust

Wesley Wiser

commit sha eb6a44f0a181d6d975471787af7f5e69399e1953

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors Before this change, `get_size_and_align()` calls `get_fn_alloc()` *a lot* in CTFE heavy code. This previously returned an `Error` which would check if `RUSTC_CTFE_BACKTRACE` was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in #68792. This is an alternate take on that PR which resolves the performance issue by generating *many* fewer errors. Previously, `ctfe-stress-4` would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30. # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Wed Feb 19 07:59:21 2020 -0500 # # HEAD detached from 17597cfb34f # Changes to be committed: # modified: src/librustc_mir/interpret/memory.rs # # Untracked files: # after.log # before.log # before2.log # before3.log # liblib.rlib # processed.before #

view details

push time in 7 days

pull request commentrust-lang/rust

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors

@RalfJung Yeah, that's correct. PRs that impact performance shouldn't be rolled up.

wesleywiser

comment created time in 7 days

pull request commentrust-lang/rust

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors

Heh. Vim word-wrapped the line as I was typing the issue number and since git-commit ignores lines that start with #, it removed the line.

wesleywiser

comment created time in 8 days

pull request commentrust-lang/rust

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors

@bors try @rust-timer queue

wesleywiser

comment created time in 8 days

PR opened rust-lang/rust

Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors

Before this change, get_size_and_align() calls get_fn_alloc() a lot in CTFE heavy code. This previously returned an Error which would check if RUSTC_CTFE_BACKTRACE was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in

This is an alternate take on that PR which resolves the performance issue by generating many fewer errors. Previously, ctfe-stress-4 would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30.

r? @RalfJung

+6 -6

0 comment

1 changed file

pr created time in 8 days

create barnchwesleywiser/rust

branch : speed_up_ctfe_stress_4

created branch time in 8 days

pull request commentrust-lang/rust

Fix how the `RUSTC_CTFE_BACKTRACE` env var is gotten.

I instrumented the function to dump the query stack at the time the function is called. Here's the results:

Count Stack
5767192 const_eval_raw, const_eval_validated, const_eval_validated, analysis
270 optimized_mir, const_eval_raw, const_eval_validated, const_eval_validated, analysis
144 const_eval_raw, const_eval_validated, const_eval_validated, optimized_mir, const_eval_raw, const_eval_validated, const_eval_validated, analysis
43 const_eval_validated, const_eval_validated, analysis
6 const_eval_validated, const_eval_validated, check_item_well_formed, analysis
3 const_eval_validated, const_eval_validated, typeck_tables_of, check_mod_item_types, analysis
2 const_eval_raw, const_eval_raw, const_eval_validated, const_eval_validated, analysis

Backtrace for the top group:

<details>

An error occurred in miri:
stack backtrace:
   0: <rustc::mir::interpret::error::InterpErrorInfo as core::convert::From<rustc::mir::interpret::error::InterpError>>::from
             at src/librustc/mir/interpret/error.rs:248
   1: <T as core::convert::Into<U>>::into
             at src/libcore/convert/mod.rs:558
      rustc_mir::interpret::memory::Memory<M>::get_fn_alloc
             at src/librustc_mir/interpret/memory.rs:612
   2: rustc_mir::interpret::memory::Memory<M>::get_size_and_align
             at src/librustc_mir/interpret/memory.rs:563
   3: rustc_mir::interpret::memory::Memory<M>::check_ptr_access_align
             at src/librustc_mir/interpret/memory.rs:372
   4: rustc_mir::interpret::memory::Memory<M>::check_ptr_access
             at src/librustc_mir/interpret/memory.rs:321
      rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::check_mplace_access
             at src/librustc_mir/interpret/place.rs:359
      rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::try_read_immediate_from_mplace
             at src/librustc_mir/interpret/operand.rs:263
      rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::try_read_immediate
             at src/librustc_mir/interpret/operand.rs:316
   5: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::copy_op_no_validate
             at src/librustc_mir/interpret/place.rs:863
   6: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::copy_op
             at src/librustc_mir/interpret/place.rs:834
      rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
             at src/librustc_mir/interpret/step.rs:150
   7: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::statement
             at src/librustc_mir/interpret/step.rs:91
      rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::step
             at src/librustc_mir/interpret/step.rs:67
      rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
             at src/librustc_mir/interpret/step.rs:34
   8: rustc_mir::const_eval::eval_queries::eval_body_using_ecx
             at src/librustc_mir/const_eval/eval_queries.rs:56
      rustc_mir::const_eval::eval_queries::const_eval_raw_provider::{{closure}}
             at src/librustc_mir/const_eval/eval_queries.rs:306
      core::result::Result<T,E>::and_then
             at src/libcore/result.rs:727
      rustc_mir::const_eval::eval_queries::const_eval_raw_provider
             at src/librustc_mir/const_eval/eval_queries.rs:306
   9: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute::{{closure}}
             at src/librustc/ty/query/plumbing.rs:951
      rustc::ty::query::__query_compute::const_eval_raw
             at src/librustc/ty/query/plumbing.rs:902
  10: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
             at src/librustc/ty/query/plumbing.rs:943
  11: rustc::dep_graph::graph::DepGraph::with_task_impl
             at src/librustc/dep_graph/graph.rs:341
      rustc::dep_graph::graph::DepGraph::with_task
             at src/librustc/dep_graph/graph.rs:209
  12: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:557
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1682
      rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1697
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::with_related_context::{{closure}}
             at src/librustc/ty/context.rs:1785
      rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1758
      rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_related_context
             at src/librustc/ty/context.rs:1782
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at src/librustc/ty/query/plumbing.rs:267
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at src/librustc/ty/query/plumbing.rs:547
      rustc::ty::query::plumbing::with_diagnostics
             at src/librustc/ty/query/plumbing.rs:212
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at src/librustc/ty/query/plumbing.rs:546
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at src/librustc/ty/query/plumbing.rs:380
  13: rustc::ty::query::TyCtxtAt::const_eval_raw
             at src/librustc/ty/query/plumbing.rs:1057
      rustc::ty::query::<impl rustc::ty::context::TyCtxt>::const_eval_raw
             at src/librustc/ty/query/plumbing.rs:1020
      rustc_mir::const_eval::eval_queries::const_eval_validated_provider
             at src/librustc_mir/const_eval/eval_queries.rs:253
  14: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute::{{closure}}
             at src/librustc/ty/query/plumbing.rs:951
      rustc::ty::query::__query_compute::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:902
  15: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
             at src/librustc/ty/query/plumbing.rs:943
  16: rustc::dep_graph::graph::DepGraph::with_task_impl
             at src/librustc/dep_graph/graph.rs:341
      rustc::dep_graph::graph::DepGraph::with_task
             at src/librustc/dep_graph/graph.rs:209
  17: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:557
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1682
      rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1697
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::with_related_context::{{closure}}
             at src/librustc/ty/context.rs:1785
      rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1758
      rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_related_context
             at src/librustc/ty/context.rs:1782
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at src/librustc/ty/query/plumbing.rs:267
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at src/librustc/ty/query/plumbing.rs:547
      rustc::ty::query::plumbing::with_diagnostics
             at src/librustc/ty/query/plumbing.rs:212
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at src/librustc/ty/query/plumbing.rs:546
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at src/librustc/ty/query/plumbing.rs:380
  18: rustc::ty::query::TyCtxtAt::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:1057
      rustc::ty::query::<impl rustc::ty::context::TyCtxt>::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:1020
      rustc_mir::const_eval::eval_queries::const_eval_validated_provider
             at src/librustc_mir/const_eval/eval_queries.rs:230
  19: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute::{{closure}}
             at src/librustc/ty/query/plumbing.rs:951
      rustc::ty::query::__query_compute::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:902
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
             at src/librustc/ty/query/plumbing.rs:943
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
             at src/librustc/dep_graph/graph.rs:341
      rustc::dep_graph::graph::DepGraph::with_task
             at src/librustc/dep_graph/graph.rs:209
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:557
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1682
      rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1697
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::with_related_context::{{closure}}
             at src/librustc/ty/context.rs:1785
      rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1758
      rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_related_context
             at src/librustc/ty/context.rs:1782
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at src/librustc/ty/query/plumbing.rs:267
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at src/librustc/ty/query/plumbing.rs:547
      rustc::ty::query::plumbing::with_diagnostics
             at src/librustc/ty/query/plumbing.rs:212
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at src/librustc/ty/query/plumbing.rs:546
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at src/librustc/ty/query/plumbing.rs:380
  23: rustc::ty::query::TyCtxtAt::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:1057
      rustc::ty::query::<impl rustc::ty::context::TyCtxt>::const_eval_validated
             at src/librustc/ty/query/plumbing.rs:1020
      rustc::mir::interpret::queries::<impl rustc::ty::context::TyCtxt>::const_eval_poly
             at src/librustc/mir/interpret/queries.rs:22
  24: <rustc_lint::builtin::UnusedBrokenConst as rustc_lint::passes::LateLintPass>::check_item
             at src/librustc_lint/builtin.rs:0
  25: <rustc_lint::BuiltinCombinedLateLintPass as rustc_lint::passes::LateLintPass>::check_item
             at src/librustc_lint/passes.rs:113
  26: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_item::{{closure}}::{{closure}}
             at src/librustc_lint/late.rs:42
      rustc_lint::late::LateContextAndPass<T>::with_param_env
             at src/librustc_lint/late.rs:73
      <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_item::{{closure}}
             at src/librustc_lint/late.rs:131
      rustc_lint::late::LateContextAndPass<T>::with_lint_attrs
             at src/librustc_lint/late.rs:61
      <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_item
             at src/librustc_lint/late.rs:130
      rustc_hir::intravisit::Visitor::visit_nested_item
             at <::syntax::visit::walk_list macros>:2
  27: rustc_hir::intravisit::walk_mod
             at src/librustc_hir/intravisit.rs:455
  28: rustc_lint::late::LateContextAndPass<T>::process_mod
             at src/librustc_lint/late.rs:79
      <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_mod
             at src/librustc_lint/late.rs:236
  29: rustc_hir::intravisit::walk_crate
             at src/librustc_hir/intravisit.rs:441
  30: rustc_lint::late::late_lint_pass_crate::{{closure}}
             at src/librustc_lint/late.rs:427
      rustc_lint::late::LateContextAndPass<T>::with_lint_attrs
             at src/librustc_lint/late.rs:61
      rustc_lint::late::late_lint_pass_crate
             at src/librustc_lint/late.rs:422
      rustc_lint::late::late_lint_crate
             at src/librustc_lint/late.rs:441
  31: rustc_lint::late::check_crate::{{closure}}::{{closure}}
             at src/librustc_lint/late.rs:471
      rustc_data_structures::profiling::VerboseTimingGuard::run
             at src/librustc_data_structures/profiling.rs:555
      rustc_session::utils::<impl rustc_session::session::Session>::time
             at src/librustc_session/utils.rs:9
  32: rustc_lint::late::check_crate::{{closure}}
             at src/librustc_lint/late.rs:469
      rustc_data_structures::sync::join
             at src/librustc_data_structures/sync.rs:160
  33: rustc_lint::late::check_crate
             at src/librustc_lint/late.rs:467
      rustc_interface::passes::analysis::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at src/librustc_interface/passes.rs:866
      rustc_data_structures::profiling::VerboseTimingGuard::run
             at src/librustc_data_structures/profiling.rs:555
      rustc_session::utils::<impl rustc_session::session::Session>::time
             at src/librustc_session/utils.rs:9
  34: rustc_interface::passes::analysis::{{closure}}::{{closure}}::{{closure}}
             at src/librustc_interface/passes.rs:865
      core::ops::function::FnOnce::call_once
             at src/libcore/ops/function.rs:232
      <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at src/libstd/panic.rs:318
      std::panicking::try::do_call
             at src/libstd/panicking.rs:303
  35: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  36: std::panicking::try
             at src/libstd/panicking.rs:281
  37: std::panic::catch_unwind
             at src/libstd/panic.rs:394
      rustc_interface::passes::analysis::{{closure}}::{{closure}}
             at src/librustc_interface/passes.rs:852
      core::ops::function::FnOnce::call_once
             at src/libcore/ops/function.rs:232
      <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at src/libstd/panic.rs:318
  38: std::panicking::try::do_call
             at src/libstd/panicking.rs:303
  39: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  40: std::panicking::try
             at src/libstd/panicking.rs:281
  41: std::panic::catch_unwind
             at src/libstd/panic.rs:394
      rustc_interface::passes::analysis::{{closure}}
             at src/librustc_interface/passes.rs:848
      rustc_data_structures::profiling::VerboseTimingGuard::run
             at src/librustc_data_structures/profiling.rs:555
      rustc_session::utils::<impl rustc_session::session::Session>::time
             at src/librustc_session/utils.rs:9
  42: rustc_interface::passes::analysis
             at src/librustc_interface/passes.rs:847
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute::{{closure}}
             at src/librustc/ty/query/plumbing.rs:951
      rustc::ty::query::__query_compute::analysis
             at src/librustc/ty/query/plumbing.rs:902
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
             at src/librustc/dep_graph/graph.rs:341
      rustc::dep_graph::graph::DepGraph::with_eval_always_task
             at src/librustc/dep_graph/graph.rs:388
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:549
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1682
      rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1697
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at src/librustc/ty/query/plumbing.rs:278
      rustc::ty::context::tls::with_related_context::{{closure}}
             at src/librustc/ty/context.rs:1785
      rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1758
      rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1769
      rustc::ty::context::tls::with_related_context
             at src/librustc/ty/context.rs:1782
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at src/librustc/ty/query/plumbing.rs:267
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at src/librustc/ty/query/plumbing.rs:547
      rustc::ty::query::plumbing::with_diagnostics
             at src/librustc/ty/query/plumbing.rs:212
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at src/librustc/ty/query/plumbing.rs:546
      rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at src/librustc/ty/query/plumbing.rs:380
  46: rustc::ty::query::TyCtxtAt::analysis
             at src/librustc/ty/query/plumbing.rs:1057
      rustc::ty::query::<impl rustc::ty::context::TyCtxt>::analysis
             at src/librustc/ty/query/plumbing.rs:1020
      rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}
             at src/librustc_driver/lib.rs:390
      rustc_interface::passes::QueryContext::enter::{{closure}}
             at src/librustc_interface/passes.rs:696
      rustc::ty::context::tls::enter_global::{{closure}}
             at src/librustc/ty/context.rs:1720
      rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1682
      rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1697
      rustc::ty::context::tls::enter_global
             at src/librustc/ty/context.rs:1720
  47: rustc_interface::passes::QueryContext::enter
             at src/librustc_interface/passes.rs:696
      rustc_driver::run_compiler::{{closure}}::{{closure}}
             at src/librustc_driver/lib.rs:390
      rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at src/librustc_interface/queries.rs:339
      rustc_driver::run_compiler::{{closure}}
             at src/librustc_driver/lib.rs:290
      rustc_interface::interface::run_compiler_in_existing_thread_pool
             at src/librustc_interface/interface.rs:186
  48: rustc_interface::interface::run_compiler::{{closure}}
             at src/librustc_interface/interface.rs:200
      rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at src/librustc_interface/util.rs:155
      scoped_tls::ScopedKey<T>::set
             at /home/wesley/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
      rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at src/librustc_interface/util.rs:151
      scoped_tls::ScopedKey<T>::set
             at /home/wesley/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
      syntax::attr::with_globals::{{closure}}
             at src/libsyntax/attr/mod.rs:44
      scoped_tls::ScopedKey<T>::set
             at /home/wesley/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  49: syntax::attr::with_globals
             at src/libsyntax/attr/mod.rs:44
  50: rustc_interface::util::spawn_thread_pool::{{closure}}
             at src/librustc_interface/util.rs:150
      rustc_interface::util::scoped_thread::{{closure}}
             at src/librustc_interface/util.rs:125
      std::sys_common::backtrace::__rust_begin_short_backtrace
             at src/libstd/sys_common/backtrace.rs:129
  51: std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}
             at src/libstd/thread/mod.rs:475
      <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at src/libstd/panic.rs:318
      std::panicking::try::do_call
             at src/libstd/panicking.rs:303
  52: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  53: std::panicking::try
             at src/libstd/panicking.rs:281
  54: std::panic::catch_unwind
             at src/libstd/panic.rs:394
      std::thread::Builder::spawn_unchecked::{{closure}}
             at src/libstd/thread/mod.rs:474
      core::ops::function::FnOnce::call_once{{vtable.shim}}
             at src/libcore/ops/function.rs:232
  55: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at src/liballoc/boxed.rs:1016
  56: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at src/liballoc/boxed.rs:1016
  57: std::sys_common::thread::start_thread
             at src/libstd/sys_common/thread.rs:13
  58: std::sys::unix::thread::Thread::new::thread_start
             at src/libstd/sys/unix/thread.rs:80
  59: start_thread
             at /usr/src/debug/glibc-2.30-1.2.x86_64/nptl/pthread_create.c:479
  60: __clone

</details>

nnethercote

comment created time in 8 days

create barnchwesleywiser/rust

branch : instrument_ctfe_backtrace

created branch time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceFile {             hasher.finish::<u128>()         };         let end_pos = start_pos.to_usize() + src.len();-        if end_pos > u32::max_value() as usize {-            return Err(OffsetOverflowError);-        }+        assert!(end_pos <= u32::max_value() as usize);

Yes, exactly!

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceFile {             hasher.finish::<u128>()         };         let end_pos = start_pos.to_usize() + src.len();-        if end_pos > u32::max_value() as usize {-            return Err(OffsetOverflowError);-        }+        assert!(end_pos <= u32::max_value() as usize);

There's no usize::to_u32() :)

If you do u32::try_from() you get Option<u32> which is None if the value is too large. If you do foo as u32 that never fails but will truncate data if it's too large.

There's no convenience method because u32::try_from(val).expect("too large") is simple enough.

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceFile {             hasher.finish::<u128>()         };         let end_pos = start_pos.to_usize() + src.len();-        if end_pos > u32::max_value() as usize {-            return Err(OffsetOverflowError);-        }+        assert!(end_pos <= u32::max_value() as usize);

Oh, it's because end_pos as u32 <= u32::max_value() is always true. Even on 64 bit environments because the value will be truncated. Doing it this way means it's essentially a no-op on 32 bit platforms and it works correctly on 64 bit platforms.

The very cautious thing to do would be to use checked_add here as well but this should already have been checked down here where we use checked_add

Zoxc

comment created time in 8 days

pull request commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

@mlodato517 If you have additional questions feel free to ask! Otherwise I'm going to mark those parts of your review resolved to keep this PR clean.

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceFile {             hasher.finish::<u128>()         };         let end_pos = start_pos.to_usize() + src.len();-        if end_pos > u32::max_value() as usize {-            return Err(OffsetOverflowError);-        }+        assert!(end_pos <= u32::max_value() as usize);

The type we use here is 32bit so it this needs to fit within it. The reason that's an AtomicU32 is because AtomicU64 is not available on 32 bit platforms.

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceMap {         self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone())     } -    fn next_start_pos(&self) -> usize {-        match self.files.borrow().source_files.last() {-            None => 0,-            // Add one so there is some space between files. This lets us distinguish-            // positions in the `SourceMap`, even in the presence of zero-length files.-            Some(last) => last.end_pos.to_usize() + 1,+    fn allocate_address_space(&self, size: usize) -> Result<usize, OffsetOverflowError> {+        let size = u32::try_from(size).map_err(|_| OffsetOverflowError)?;++        loop {+            let current = self.used_address_space.load(Ordering::Relaxed);+            let next = current+                .checked_add(size)+                // Add one so there is some space between files. This lets us distinguish+                // positions in the `SourceMap`, even in the presence of zero-length files.+                .and_then(|next| next.checked_add(1))+                .ok_or(OffsetOverflowError)?;++            if self+                .used_address_space+                .compare_exchange(current, next, Ordering::Relaxed, Ordering::Relaxed)

Is this updating used_address_space if it already equals current or something?

Yes. To understand why you'd want to do this, think about the use case for atomics. Typically the alternative to atomics is to use some kind of lock. In that scenario, you acquire a read/write lock on a value, perform a calculation, update the value and then release the lock. This kind of design is usually correct and easy to understand but can be bad for performance in some situations because you have to acquire a lock just to read the current value.

Atomics on the other hand, don't lock. Your CPU typically gives you special instructions or guarantees about existing instructions for certain sizes of data. These allow you to do things like read the entire value or write the entire value without the reads\writes becoming mangled with data from other threads. compare_exchange uses an instruction that says "if this is the same as the value I'm providing then update it". This lets you do things like the above where we read the value, perform a calculation to get a new value and if the value hasn't changed since we read it, then we can write the new value. If the value has changed, we loop around again and redo the operation until it succeeds.

This operation is sometimes called compare and swap.

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceMap {         self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone())     } -    fn next_start_pos(&self) -> usize {-        match self.files.borrow().source_files.last() {-            None => 0,-            // Add one so there is some space between files. This lets us distinguish-            // positions in the `SourceMap`, even in the presence of zero-length files.-            Some(last) => last.end_pos.to_usize() + 1,+    fn allocate_address_space(&self, size: usize) -> Result<usize, OffsetOverflowError> {+        let size = u32::try_from(size).map_err(|_| OffsetOverflowError)?;

Yes, exactly. u32 is always 32bits, u64 is always 64bits but usize is basically the size of a reference/pointer on the target platform. So for 32 bit environments, usize will be 32bits and for 64 bit environments, usize will be 64bits. So in a 64 bit environment, this conversion might fail because the value of size is larger than will fit in a 32 bit integer.

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceMap {         self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone())     } -    fn next_start_pos(&self) -> usize {-        match self.files.borrow().source_files.last() {-            None => 0,-            // Add one so there is some space between files. This lets us distinguish-            // positions in the `SourceMap`, even in the presence of zero-length files.-            Some(last) => last.end_pos.to_usize() + 1,+    fn allocate_address_space(&self, size: usize) -> Result<usize, OffsetOverflowError> {+        let size = u32::try_from(size).map_err(|_| OffsetOverflowError)?;

Yeah, that's true. That would imply src is usize::max long though. Wouldn't we already have OOM'd trying to read that in?

Zoxc

comment created time in 8 days

Pull request review commentrust-lang/rust

Fix race condition when allocating source files in SourceMap

 impl SourceMap {         self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone())     } -    fn next_start_pos(&self) -> usize {-        match self.files.borrow().source_files.last() {-            None => 0,-            // Add one so there is some space between files. This lets us distinguish-            // positions in the `SourceMap`, even in the presence of zero-length files.-            Some(last) => last.end_pos.to_usize() + 1,+    fn allocate_address_space(&self, size: usize) -> Result<usize, OffsetOverflowError> {+        let size = u32::try_from(size).map_err(|_| OffsetOverflowError)?;

I think you can do

        // Add one so there is some space between files. This lets us distinguish
        // positions in the `SourceMap`, even in the presence of zero-length files.
        let size = u32::try_from(size + 1).map_err(|_| OffsetOverflowError)?;

here which avoids needing to and_then() the checked_add below.

Zoxc

comment created time in 8 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

r? @nikomatsakis

wesleywiser

comment created time in 9 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

Thanks!

wesleywiser

comment created time in 9 days

pull request commentrust-lang/rust

Add documentation for the `-Zself-profile` flag

@andjo403 Yeah, that's a good idea!

wesleywiser

comment created time in 10 days

push eventwesleywiser/rust

Wesley Wiser

commit sha 535fc0f43ab40a1f4982f80a3d922e6e202c6702

Add documentation for the `-Zself-profile` flag

view details

Wesley Wiser

commit sha 58ec5d25e946da2bcb7ca884188f5f856a9e1643

Add documentation for the `-Zself-profile-events` flag

view details

push time in 10 days

pull request commentrust-lang/rust

Combine `HaveBeenBorrowedLocals` and `IndirectlyMutableLocals` into one dataflow analysis

@ecstatic-morse Do you there there is the possibility for a compiler performance change here? Should we do a perf run before landing this?

ecstatic-morse

comment created time in 10 days

Pull request review commentrust-lang/rust

Combine `HaveBeenBorrowedLocals` and `IndirectlyMutableLocals` into one dataflow analysis

 pub use super::*; -use crate::dataflow::{BitDenotation, GenKillSet};+use crate::dataflow::generic::{AnalysisDomain, GenKill, GenKillAnalysis}; use rustc::mir::visit::Visitor; use rustc::mir::*;+use rustc::ty::{ParamEnv, TyCtxt};+use rustc_span::DUMMY_SP;++pub type MaybeMutBorrowedLocals<'mir, 'tcx> = MaybeBorrowedLocals<MutBorrow<'mir, 'tcx>>;++/// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points+/// to a given local.+///+/// The `K` parameter determines what kind of borrows are tracked. By default,+/// `MaybeBorrowedLocals` looks for *any* borrow of a local. If you are only interested in borrows+/// that might allow mutation, use the `MaybeMutBorrowedLocals` type alias instead.+///+/// At present, this is used as a very limited form of alias analysis. For example,+/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for+/// immovable generators. `MaybeMutBorrowedLocals` is used during const checking to prove that a+/// local has not been mutated via indirect assignment (e.g., `*p = 42`), the side-effects of a+/// function call or inline assembly.+pub struct MaybeBorrowedLocals<K = AnyBorrow> {+    kind: K,+} -/// This calculates if any part of a MIR local could have previously been borrowed.-/// This means that once a local has been borrowed, its bit will be set-/// from that point and onwards, until we see a StorageDead statement for the local,-/// at which points there is no memory associated with the local, so it cannot be borrowed.-/// This is used to compute which locals are live during a yield expression for-/// immovable generators.-#[derive(Copy, Clone)]-pub struct HaveBeenBorrowedLocals<'a, 'tcx> {-    body: &'a Body<'tcx>,+impl MaybeBorrowedLocals {+    /// A dataflow analysis that records whether a pointer or reference exists that may alias the+    /// given local.+    pub fn new() -> Self {+        MaybeBorrowedLocals { kind: AnyBorrow }+    } } -impl<'a, 'tcx> HaveBeenBorrowedLocals<'a, 'tcx> {-    pub fn new(body: &'a Body<'tcx>) -> Self {-        HaveBeenBorrowedLocals { body }+impl MaybeMutBorrowedLocals<'mir, 'tcx> {+    /// A dataflow analysis that records whether a pointer or reference exists that may *mutably*+    /// alias the given local.+    pub fn new_mut_only(+        tcx: TyCtxt<'tcx>,+        body: &'mir mir::Body<'tcx>,+        param_env: ParamEnv<'tcx>,+    ) -> Self {+        MaybeBorrowedLocals { kind: MutBorrow { body, tcx, param_env } }     }+} -    pub fn body(&self) -> &Body<'tcx> {-        self.body+impl<K> MaybeBorrowedLocals<K> {+    fn transfer_function<'a, T>(&'a self, trans: &'a mut T) -> TransferFunction<'a, T, K> {+        TransferFunction { kind: &self.kind, trans }     } } -impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {+impl<K> AnalysisDomain<'tcx> for MaybeBorrowedLocals<K>+where+    K: BorrowAnalysisKind<'tcx>,+{     type Idx = Local;-    fn name() -> &'static str {-        "has_been_borrowed_locals"++    const NAME: &'static str = K::ANALYSIS_NAME;++    fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize {+        body.local_decls().len()+    }++    fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut BitSet<Self::Idx>) {+        // No locals are aliased on function entry+    }+}++impl<K> GenKillAnalysis<'tcx> for MaybeBorrowedLocals<K>+where+    K: BorrowAnalysisKind<'tcx>,+{+    fn statement_effect(+        &self,+        trans: &mut impl GenKill<Self::Idx>,+        statement: &mir::Statement<'tcx>,+        location: Location,+    ) {+        self.transfer_function(trans).visit_statement(statement, location);     }-    fn bits_per_block(&self) -> usize {-        self.body.local_decls.len()++    fn terminator_effect(+        &self,+        trans: &mut impl GenKill<Self::Idx>,+        terminator: &mir::Terminator<'tcx>,+        location: Location,+    ) {+        self.transfer_function(trans).visit_terminator(terminator, location);     } -    fn start_block_effect(&self, _on_entry: &mut BitSet<Local>) {-        // Nothing is borrowed on function entry+    fn call_return_effect(+        &self,+        _trans: &mut impl GenKill<Self::Idx>,+        _block: mir::BasicBlock,+        _func: &mir::Operand<'tcx>,+        _args: &[mir::Operand<'tcx>],+        _dest_place: &mir::Place<'tcx>,+    ) {     }+} -    fn statement_effect(&self, trans: &mut GenKillSet<Local>, loc: Location) {-        let stmt = &self.body[loc.block].statements[loc.statement_index];+impl<K> BottomValue for MaybeBorrowedLocals<K> {+    // bottom = unborrowed+    const BOTTOM_VALUE: bool = false;+} -        BorrowedLocalsVisitor { trans }.visit_statement(stmt, loc);+/// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`.+struct TransferFunction<'a, T, K> {+    trans: &'a mut T,+    kind: &'a K,+} -        // StorageDead invalidates all borrows and raw pointers to a local-        match stmt.kind {-            StatementKind::StorageDead(l) => trans.kill(l),-            _ => (),+impl<T, K> Visitor<'tcx> for TransferFunction<'a, T, K>+where+    T: GenKill<Local>,+    K: BorrowAnalysisKind<'tcx>,+{+    fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location) {+        self.super_statement(stmt, location);++        // When we reach a `StorageDead` statement, we can assume that any pointers to this memory+        // are now invalid.+        if let StatementKind::StorageDead(local) = stmt.kind {+            self.trans.kill(local);         }     } -    fn terminator_effect(&self, trans: &mut GenKillSet<Local>, loc: Location) {-        let terminator = self.body[loc.block].terminator();-        BorrowedLocalsVisitor { trans }.visit_terminator(terminator, loc);-        match &terminator.kind {-            // Drop terminators borrows the location-            TerminatorKind::Drop { location, .. }-            | TerminatorKind::DropAndReplace { location, .. } => {-                if let Some(local) = find_local(location) {-                    trans.gen(local);+    fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {+        self.super_rvalue(rvalue, location);++        match rvalue {+            mir::Rvalue::AddressOf(mt, borrowed_place) => {+                if !borrowed_place.is_indirect() && self.kind.in_address_of(*mt, borrowed_place) {+                    self.trans.gen(borrowed_place.local);                 }             }-            _ => (),++            mir::Rvalue::Ref(_, kind, borrowed_place) => {+                if !borrowed_place.is_indirect() && self.kind.in_ref(*kind, borrowed_place) {+                    self.trans.gen(borrowed_place.local);+                }+            }++            mir::Rvalue::Cast(..)+            | mir::Rvalue::Use(..)+            | mir::Rvalue::Repeat(..)+            | mir::Rvalue::Len(..)+            | mir::Rvalue::BinaryOp(..)+            | mir::Rvalue::CheckedBinaryOp(..)+            | mir::Rvalue::NullaryOp(..)+            | mir::Rvalue::UnaryOp(..)+            | mir::Rvalue::Discriminant(..)+            | mir::Rvalue::Aggregate(..) => {}         }     } -    fn propagate_call_return(-        &self,-        _in_out: &mut BitSet<Local>,-        _call_bb: mir::BasicBlock,-        _dest_bb: mir::BasicBlock,-        _dest_place: &mir::Place<'tcx>,-    ) {-        // Nothing to do when a call returns successfully+    fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {+        self.super_terminator(terminator, location);++        match terminator.kind {+            // Drop terminators may call custom drop glue (`Drop::drop`), which takes `&mut self`+            // as a parameter. Hypothetically, a drop impl could launder that reference into the+            // surrounding environment through a raw pointer, thus creating a valid `*mut` pointing+            // to the dropped local. We are not yet willing to declare this particular case UB, so+            // we must treat all dropped locals as mutably borrowed for now. See discussion on+            // [#61069].+            //+            // [#61069]: https://github.com/rust-lang/rust/pull/61069+            mir::TerminatorKind::Drop { location: dropped_place, .. }+            | mir::TerminatorKind::DropAndReplace { location: dropped_place, .. } => {+                self.trans.gen(dropped_place.local);+            }++            TerminatorKind::Abort+            | TerminatorKind::Assert { .. }+            | TerminatorKind::Call { .. }+            | TerminatorKind::FalseEdges { .. }+            | TerminatorKind::FalseUnwind { .. }+            | TerminatorKind::GeneratorDrop+            | TerminatorKind::Goto { .. }+            | TerminatorKind::Resume+            | TerminatorKind::Return+            | TerminatorKind::SwitchInt { .. }+            | TerminatorKind::Unreachable+            | TerminatorKind::Yield { .. } => {}+        }     } } -impl<'a, 'tcx> BottomValue for HaveBeenBorrowedLocals<'a, 'tcx> {-    // bottom = unborrowed-    const BOTTOM_VALUE: bool = false;+pub struct AnyBorrow;++pub struct MutBorrow<'mir, 'tcx> {+    tcx: TyCtxt<'tcx>,+    body: &'mir Body<'tcx>,+    param_env: ParamEnv<'tcx>, } -struct BorrowedLocalsVisitor<'gk> {-    trans: &'gk mut GenKillSet<Local>,+impl MutBorrow<'mir, 'tcx> {+    // `&` and `&raw` only allow mutation if the borrowed place is `!Freeze`.

Should be a doc comment IMO.

ecstatic-morse

comment created time in 10 days

Pull request review commentrust-lang/rust

Combine `HaveBeenBorrowedLocals` and `IndirectlyMutableLocals` into one dataflow analysis

 pub use super::*; -use crate::dataflow::{BitDenotation, GenKillSet};+use crate::dataflow::generic::{AnalysisDomain, GenKill, GenKillAnalysis}; use rustc::mir::visit::Visitor; use rustc::mir::*;+use rustc::ty::{ParamEnv, TyCtxt};+use rustc_span::DUMMY_SP;++pub type MaybeMutBorrowedLocals<'mir, 'tcx> = MaybeBorrowedLocals<MutBorrow<'mir, 'tcx>>;++/// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points+/// to a given local.+///+/// The `K` parameter determines what kind of borrows are tracked. By default,+/// `MaybeBorrowedLocals` looks for *any* borrow of a local. If you are only interested in borrows+/// that might allow mutation, use the `MaybeMutBorrowedLocals` type alias instead.+///+/// At present, this is used as a very limited form of alias analysis. For example,+/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for+/// immovable generators. `MaybeMutBorrowedLocals` is used during const checking to prove that a+/// local has not been mutated via indirect assignment (e.g., `*p = 42`), the side-effects of a+/// function call or inline assembly.+pub struct MaybeBorrowedLocals<K = AnyBorrow> {+    kind: K,+} -/// This calculates if any part of a MIR local could have previously been borrowed.-/// This means that once a local has been borrowed, its bit will be set-/// from that point and onwards, until we see a StorageDead statement for the local,-/// at which points there is no memory associated with the local, so it cannot be borrowed.-/// This is used to compute which locals are live during a yield expression for-/// immovable generators.-#[derive(Copy, Clone)]-pub struct HaveBeenBorrowedLocals<'a, 'tcx> {-    body: &'a Body<'tcx>,+impl MaybeBorrowedLocals {+    /// A dataflow analysis that records whether a pointer or reference exists that may alias the+    /// given local.+    pub fn new() -> Self {+        MaybeBorrowedLocals { kind: AnyBorrow }+    } } -impl<'a, 'tcx> HaveBeenBorrowedLocals<'a, 'tcx> {-    pub fn new(body: &'a Body<'tcx>) -> Self {-        HaveBeenBorrowedLocals { body }+impl MaybeMutBorrowedLocals<'mir, 'tcx> {+    /// A dataflow analysis that records whether a pointer or reference exists that may *mutably*+    /// alias the given local.+    pub fn new_mut_only(+        tcx: TyCtxt<'tcx>,+        body: &'mir mir::Body<'tcx>,+        param_env: ParamEnv<'tcx>,+    ) -> Self {+        MaybeBorrowedLocals { kind: MutBorrow { body, tcx, param_env } }     }+} -    pub fn body(&self) -> &Body<'tcx> {-        self.body+impl<K> MaybeBorrowedLocals<K> {+    fn transfer_function<'a, T>(&'a self, trans: &'a mut T) -> TransferFunction<'a, T, K> {+        TransferFunction { kind: &self.kind, trans }     } } -impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {+impl<K> AnalysisDomain<'tcx> for MaybeBorrowedLocals<K>+where+    K: BorrowAnalysisKind<'tcx>,+{     type Idx = Local;-    fn name() -> &'static str {-        "has_been_borrowed_locals"++    const NAME: &'static str = K::ANALYSIS_NAME;++    fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize {+        body.local_decls().len()+    }++    fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut BitSet<Self::Idx>) {+        // No locals are aliased on function entry+    }+}++impl<K> GenKillAnalysis<'tcx> for MaybeBorrowedLocals<K>+where+    K: BorrowAnalysisKind<'tcx>,+{+    fn statement_effect(+        &self,+        trans: &mut impl GenKill<Self::Idx>,+        statement: &mir::Statement<'tcx>,+        location: Location,+    ) {+        self.transfer_function(trans).visit_statement(statement, location);     }-    fn bits_per_block(&self) -> usize {-        self.body.local_decls.len()++    fn terminator_effect(+        &self,+        trans: &mut impl GenKill<Self::Idx>,+        terminator: &mir::Terminator<'tcx>,+        location: Location,+    ) {+        self.transfer_function(trans).visit_terminator(terminator, location);     } -    fn start_block_effect(&self, _on_entry: &mut BitSet<Local>) {-        // Nothing is borrowed on function entry+    fn call_return_effect(+        &self,+        _trans: &mut impl GenKill<Self::Idx>,+        _block: mir::BasicBlock,+        _func: &mir::Operand<'tcx>,+        _args: &[mir::Operand<'tcx>],+        _dest_place: &mir::Place<'tcx>,+    ) {     }+} -    fn statement_effect(&self, trans: &mut GenKillSet<Local>, loc: Location) {-        let stmt = &self.body[loc.block].statements[loc.statement_index];+impl<K> BottomValue for MaybeBorrowedLocals<K> {+    // bottom = unborrowed+    const BOTTOM_VALUE: bool = false;+} -        BorrowedLocalsVisitor { trans }.visit_statement(stmt, loc);+/// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`.+struct TransferFunction<'a, T, K> {+    trans: &'a mut T,+    kind: &'a K,+} -        // StorageDead invalidates all borrows and raw pointers to a local-        match stmt.kind {-            StatementKind::StorageDead(l) => trans.kill(l),-            _ => (),+impl<T, K> Visitor<'tcx> for TransferFunction<'a, T, K>+where+    T: GenKill<Local>,+    K: BorrowAnalysisKind<'tcx>,+{+    fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location) {+        self.super_statement(stmt, location);++        // When we reach a `StorageDead` statement, we can assume that any pointers to this memory+        // are now invalid.+        if let StatementKind::StorageDead(local) = stmt.kind {+            self.trans.kill(local);         }     } -    fn terminator_effect(&self, trans: &mut GenKillSet<Local>, loc: Location) {-        let terminator = self.body[loc.block].terminator();-        BorrowedLocalsVisitor { trans }.visit_terminator(terminator, loc);-        match &terminator.kind {-            // Drop terminators borrows the location-            TerminatorKind::Drop { location, .. }-            | TerminatorKind::DropAndReplace { location, .. } => {-                if let Some(local) = find_local(location) {-                    trans.gen(local);+    fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {+        self.super_rvalue(rvalue, location);++        match rvalue {+            mir::Rvalue::AddressOf(mt, borrowed_place) => {+                if !borrowed_place.is_indirect() && self.kind.in_address_of(*mt, borrowed_place) {+                    self.trans.gen(borrowed_place.local);                 }             }-            _ => (),++            mir::Rvalue::Ref(_, kind, borrowed_place) => {+                if !borrowed_place.is_indirect() && self.kind.in_ref(*kind, borrowed_place) {+                    self.trans.gen(borrowed_place.local);+                }+            }++            mir::Rvalue::Cast(..)+            | mir::Rvalue::Use(..)+            | mir::Rvalue::Repeat(..)+            | mir::Rvalue::Len(..)+            | mir::Rvalue::BinaryOp(..)+            | mir::Rvalue::CheckedBinaryOp(..)+            | mir::Rvalue::NullaryOp(..)+            | mir::Rvalue::UnaryOp(..)+            | mir::Rvalue::Discriminant(..)+            | mir::Rvalue::Aggregate(..) => {}         }     } -    fn propagate_call_return(-        &self,-        _in_out: &mut BitSet<Local>,-        _call_bb: mir::BasicBlock,-        _dest_bb: mir::BasicBlock,-        _dest_place: &mir::Place<'tcx>,-    ) {-        // Nothing to do when a call returns successfully+    fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {+        self.super_terminator(terminator, location);++        match terminator.kind {+            // Drop terminators may call custom drop glue (`Drop::drop`), which takes `&mut self`+            // as a parameter. Hypothetically, a drop impl could launder that reference into the+            // surrounding environment through a raw pointer, thus creating a valid `*mut` pointing+            // to the dropped local. We are not yet willing to declare this particular case UB, so+            // we must treat all dropped locals as mutably borrowed for now. See discussion on+            // [#61069].+            //+            // [#61069]: https://github.com/rust-lang/rust/pull/61069

Nit: we generally only do this style in doc comments since regular comments are never rendered as markdown. Either just an issue number or the full url is appropriate here.

ecstatic-morse

comment created time in 10 days

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha 268332c71aa6c51fbb7bd68e85384ea7b5ea9948

[Inside Rust] Intro to rustc's self-profile feature

view details

push time in 10 days

issue commentrust-lang/rust

MIR inliner ICEs trying to inline async closures

@pnkfelix I'm not sure how async closures desugar, so this could be way off base, but this looks very similar to the other ICEs tracked in #62529. Does this look like another instance of that issue to you?

wesleywiser

comment created time in 10 days

pull request commentrust-lang/rust

Fix how the `RUSTC_CTFE_BACKTRACE` env var is gotten.

Interestingly, the vast majority of errors do not seem to be coming from const-prop. So checking what the active query is doesn't make a noticeable difference in terms of performance.

@oli-obk @RalfJung what do you think of this approach instead? This seems to recover all of the performance of this PR and miri can still setup its loggers here by setting compiler.tcx.sess.ctfe_backtrace.

nnethercote

comment created time in 10 days

create barnchwesleywiser/rust

branch : wip_remove_ctfe_env_var_checking

created branch time in 10 days

create barnchwesleywiser/rust

branch : doc_self_profile_unstable_book

created branch time in 10 days

pull request commentrust-lang/blog.rust-lang.org

[Inside Rust] Intro to rustc's self-profile feature

@nikomatsakis and I chatted a bit about this and we decided not to move it to the main blog at this time. While we both agree that the main blog is a perhaps underutilized, I think that this post is a bit too in-the-weeds for the main blog.

Instead, we'd like to run a short series of posts on the main blog advertising the improvements that have been made to Rust compile times over the years as well as the contributors driving those improvements, the current state of things including profiling tools like these and anticipated in-progress or future improvements.

As for this post, I'm going to

  • [ ] adapt the into to include a modified version of what @nikomatsakis suggested:

Over the last year, the Self-Profile Working Group has been building tools to profile rustc because we often hear requests to know where compilation time is being spent. This is useful when optimizing the compiler, but it's also useful to users who want to refactor their crate so that it will compile faster. We've been working on an experimental feature that will help with that and this blog post gives a preview of how it works. Be warned, though: it is still experimental and we expect the interface to change over time. We'll be adding these examples to the Rust unstable book, as well, and we plan to keep that up to date, so you can always find the latest instructions there.

  • [ ] update the Rust unstable book with these examples so we can link directly to it in the last sentence.

  • [ ] update the dates in the post to be 2020-02-18 because I do not anticipate having time today or tomorrow to make these changes and @nikomatsakis is out on Monday.

wesleywiser

comment created time in 12 days

PR opened rust-lang/blog.rust-lang.org

[Inside Rust] Intro to rustc's self-profile feature

r? @nikomatsakis

cc @michaelwoerister who gave feedback on an earlier draft of this post

+667 -0

0 comment

7 changed files

pr created time in 13 days

push eventwesleywiser/blog.rust-lang.org

Wesley Wiser

commit sha 8963969e8536e62f98df67c18d78aed2cafddaf9

[Inside Rust] Intro to rustc's self-profile feature

view details

push time in 13 days

Pull request review commentwesleywiser/blog.rust-lang.org

[Inside Rust] Self-Profile tutorial

+---+layout: post+title: "Introduction to profiling rustc using the self profiler"+author: Wesley Wiser+description: "Learn how to use the -Zself-profile rustc flag"+team: the self-profile working group <https://rust-lang.github.io/compiler-team/working-groups/self-profile/>+---++Over the last year, the [Self-Profile Working Group] has been building tools to profile `rustc`.+This is part of the Compiler Team's ongoing efforts to improve `rustc`'s performance.+In this post, we'll look at the tooling currently available and use them to profile an example crate's compile time.++First, we'll download and build the `measureme` repository which provides tools to analyze self-profile trace data.++```sh+$ git clone https://github.com/rust-lang/measureme.git+$ cd measureme+$ cargo build --release --all+```++Now that we have our tools, let's download an example crate to profile its build.++```sh+$ cd ..+$ git clone https://github.com/rust-lang/regex.git+$ cd regex+```++We'll need to use a recent nightly compiler to get access to unsable `-Z` flags.++```sh+$ rustup override set nightly+```++If you haven't installed a nightly compiler before, this will download the nightly compiler for you.+If you have, then update it to make sure you're on a recent version.++```sh+$ rustup update nightly+```++Now we can build it and tell `rustc` to profile the build of the `regex` crate.+This will cause three new files to be created in the working directory which contain the profling data.++```sh+$ cargo rustc -- -Zself-profile+$ ls+CHANGELOG.md        LICENSE-APACHE       UNICODE.md              regex-17088.string_data       regex-syntax         target+Cargo.lock          LICENSE-MIT          bench                   regex-17088.string_index      rustfmt.toml         test+Cargo.toml          PERFORMANCE.md       examples                regex-capi                    scripts              tests+HACKING.md          README.md            regex-17088.events      regex-debug                   src+```++The new files follow the format `{crate name}-{rustc process id}.{events,string_data,string_index}`.++We'll use each of the three main tools to analyze the profling data:++## `summarize`++As its name suggests, this tool summarizes the data found in the trace files.+Additionally, `summarize` can also show a "diff" between two trace files but we won't be using this mode.++Let's run the tool, passing just the file name (but not the extension) for the trace:++```sh+$ ../measureme/target/release/summarize summarize regex-17088++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| Item                                          | Self time | % of total time | Time     | Item count | Cache hits | Blocked time | Incremental load time |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| LLVM_module_codegen_emit_obj                  | 4.89s     | 42.752          | 4.89s    | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| codegen_module                                | 1.25s     | 10.967          | 1.37s    | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| LLVM_module_optimize_module_passes            | 1.15s     | 10.022          | 1.15s    | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| LLVM_module_codegen_make_bitcode              | 786.56ms  | 6.875           | 960.73ms | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| typeck_tables_of                              | 565.18ms  | 4.940           | 689.39ms | 848        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| LLVM_module_codegen                           | 408.01ms  | 3.566           | 6.26s    | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| mir_borrowck                                  | 224.03ms  | 1.958           | 543.33ms | 848        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| LLVM_module_codegen_emit_compressed_bitcode   | 174.17ms  | 1.522           | 174.17ms | 159        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| optimized_mir                                 | 157.91ms  | 1.380           | 205.29ms | 1996       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| evaluate_obligation                           | 146.50ms  | 1.281           | 184.17ms | 8304       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| codegen_crate                                 | 139.48ms  | 1.219           | 1.58s    | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| mir_built                                     | 123.88ms  | 1.083           | 168.01ms | 848        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| metadata_decode_entry                         | 88.36ms   | 0.772           | 117.77ms | 55642      | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| incr_comp_copy_cgu_workproducts               | 64.21ms   | 0.561           | 64.21ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| monomorphization_collector_graph_walk         | 54.11ms   | 0.473           | 344.00ms | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| link_rlib                                     | 43.21ms   | 0.378           | 43.21ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| check_impl_item_well_formed                   | 41.36ms   | 0.362           | 77.14ms  | 736        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| codegen_fulfill_obligation                    | 40.36ms   | 0.353           | 51.56ms  | 1759       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| expand_crate                                  | 37.24ms   | 0.326           | 48.52ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| symbol_name                                   | 36.31ms   | 0.317           | 39.06ms  | 5513       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| free_global_ctxt                              | 34.34ms   | 0.300           | 34.34ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| type_op_prove_predicate                       | 29.99ms   | 0.262           | 31.24ms  | 1903       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| encode_query_results                          | 28.59ms   | 0.250           | 28.59ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| layout_raw                                    | 28.09ms   | 0.245           | 76.62ms  | 9023       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| parse_crate                                   | 27.60ms   | 0.241           | 27.60ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| build_hir_map                                 | 26.37ms   | 0.230           | 31.47ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| link_binary_remove_temps                      | 26.23ms   | 0.229           | 26.23ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| resolve_crate                                 | 25.38ms   | 0.222           | 25.38ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| check_item_well_formed                        | 25.37ms   | 0.222           | 47.45ms  | 836        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| param_env                                     | 22.64ms   | 0.198           | 31.63ms  | 2519       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| region_scope_tree                             | 21.71ms   | 0.190           | 21.71ms  | 1366       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| specialization_graph_of                       | 19.92ms   | 0.174           | 75.86ms  | 65         | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| check_match                                   | 18.78ms   | 0.164           | 30.05ms  | 848        | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| is_freeze_raw                                 | 17.58ms   | 0.154           | 62.67ms  | 3214       | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| hir_lowering                                  | 17.58ms   | 0.154           | 17.58ms  | 1          | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++| check_mod_privacy                             | 16.21ms   | 0.142           | 22.75ms  | 31         | 0          | 0.00ns       | 0.00ns                |++-----------------------------------------------+-----------+-----------------+----------+------------+------------+--------------+-----------------------++...+Total cpu time: 11.440758871s+```++The output is sorted by the self time (time spent in the query or activity but not other queries or activites called by itself).+As you can see, most of the compilation time is spent in LLVM generating the binary code for the executable.++## `flamegraph`++As you may have guessed, `flamegraph` will produce a [flame graph] of the profiling data.+To run the tool, we'll pass just the filename without a file extension like we did for `summarize`:++```sh+$ ../measureme/target/release/flamegraph regex-17088+```++This will create a file called `rustc.svg` in the working directory:++![Image of flamegraph output][flame graph img]++[Click here] to try the interactive svg.++## `crox`++This tool processes self-profiling data into the JSON format that the Chromium profiler understands.+You can use it to create a graphical timeline showing exactly when various traced events occurred.++In this section, we'll cover a few different modes `crox` can run in such as profiling an entire crate compilation including dependencies and filtering out small events.+Let's get started with the basics!++### Basic usage++To run the tool, we'll just pass the filename without a file extension like we've done before:++```sh+$ ../measureme/target/release/crox regex-17088+```++This creates a file called `chrome_profiler.json` in the working directory.+To open it, we'll use the regular Chromium performance tools you might already be familar with:++1. Open Chrome+2. Open the Developer Tools console by pressing `Ctrl` + `Shift` + `i` (Windows/Linux) or `Cmd` + `Option` + `i` (macOS)+3. Click the Performance tab at the top of the console.+4. Click the "Load profile" button which looks like an arrow pointing up.+5. Select the `chrome_profiler.json` file we crated.++You should now see something similar to this:++![Image of chrome profiler][chrome profiler img1]++You can use the scroll wheel on a mouse or the appropriate gesture on a touchpad to zoom in or out of the timeline.++### Filtering short events++If the `chrome_profiler.json` file gets too large, the normal Chromium performance tools have issues opening the file.+One easy way to deal with this is to tell `crox` to remove events shorter than a chosen duration:++```sh+$ ../measureme/target/release/crox --minumum-duration 2 regex-17088+```++Filtering out events less than 2 microseconds shrinks our `chrome_profiler.js` file from 27mb to 11mb.++### Capturing event arguments++The self-profiler can be configured to record event arguments during compilation.+For example, queries will include their query key.+This fuctionality is turned off by default because it significantly increases the self-profiler overhead.

Looks like the overhead is ~5% on most of the crates I've looked at. I'll change this to omit the "significantly" adjective.

wesleywiser

comment created time in 13 days

pull request commentrust-lang/rust

[self-profiler] add selfprofiling to llvm

@bors r+ rollup=never

andjo403

comment created time in 13 days

pull request commentrust-lang/rust

perf: Reuse a Vec in mir simplification

@bors try @rust-timer queue

Marwes

comment created time in 14 days

push eventwesleywiser/blog.rust-lang.org

Niko Matsakis

commit sha 40d0b76e3bff17accc1e43cfd436198f5f62da59

announce LLVM ICE-breaker group

view details

Daniel Henry-Mantilla

commit sha 9f6497c1e09bdabe611c04312ba1b1597caa49a3

Fix enum representation of future `g: MutexGuard<'_, u32>` does not exist in the scope of the "unresumed" generator / future, so this fixes it. On top of that, I have taken the freedom to add a the `Return` variant to the enum, and have also added some comments on top of it, in order to have a precise recap' of the cited post about generators.

view details

qutesy

commit sha eb26567970e4ee8263ea0308f10842f6e5858af3

fix typo If I'm reading the code correctly, and if I understand the Sync requirement correctly, the problem here is that bar() _locks_ the mutex, not that bar() unlocks the mutex.

view details

Lachezar Lechev

commit sha 433113c9cb91e2b7f0fb009083af853bdcf920f8

Typo fix for PR link in "AsyncAwait Not Send" post

view details

Wesley Wiser

commit sha 078ecff337dd10cea2391d238e4051acab76aab7

[inside-rust] Add triage meeting post for 2019-10-10

view details

ashley williams

commit sha 171512c2ab952a9e3e7111eae81470608520db6b

Merge pull request #424 from elpiel/patch-1 Typo fix for PR link in "AsyncAwait Not Send" post

view details

Pietro Albini

commit sha 295df301147d84354d6cf015dbf0fab335975d2b

add post about rustup 1.20.0

view details

Pietro Albini

commit sha 1a9082ae4927f91167d050a459333e3b48bf6bb0

Update posts/2019-10-15-Rustup-1.20.0.md Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>

view details

Pietro Albini

commit sha 4c20208c44320634fa8a68b2bd3e95c75806f328

Update posts/2019-10-15-Rustup-1.20.0.md Co-Authored-By: Nick Cameron <nrc@ncameron.org>

view details

Pietro Albini

commit sha d41cdf3d4b568f262c2736410674ce049ebe3bff

Update posts/2019-10-15-Rustup-1.20.0.md

view details

Pietro Albini

commit sha 6b7c3dc37fc989d0d6a5c51d26f5836b4a648d92

last updates to the blog post

view details

Pietro Albini

commit sha eee74c922b9b7f70cbfc595147c97944c0b090e2

Merge pull request #425 from rust-lang/rustup-1.20.0 Add post about rustup 1.20.0

view details

Alex Crichton

commit sha 67634db6dfa559cc9de204b42b48d53992c62861

Merge pull request #422 from qutesy/patch-1 fix typo in blog post about async-await diagnostics

view details

Daniel Henry-Mantilla

commit sha 192ac8703c1ba9c3c6f59014e6158fead8304070

Added @davidtwco suggestions Co-authored-by: David Wood <hello@davidtw.co>

view details

Alex Crichton

commit sha b474a220fa561f7a23eced10965e0d6e7a1c88aa

Merge pull request #421 from danielhenrymantilla/patch-1 Fix (and improve) enum representation of an async fn future

view details

Tshepang Lekhonkhobe

commit sha 28af9b131bb6a487a525479052206c1a7d94f77f

flags accept no arguments, and options do

view details

Niko Matsakis

commit sha db3f36196c9cf28f071383f09e38436e095e480a

Rename 2019-10-10-compiler-team-meeting.md to 2019-10-15-compiler-team-meeting.md

view details

Niko Matsakis

commit sha 10f3af27bfab9b291dadc9a4970330fc42302477

Merge pull request #423 from wesleywiser/2019-10-10 [inside-rust] Add triage meeting post for 2019-10-10

view details

Niko Matsakis

commit sha 1ab84d65d7e15ea88b35f2b3df3bae297c992ba4

Merge pull request #426 from tshepang/patch-2 flags accept no arguments, and options do

view details

Pietro Albini

commit sha 6b52c18557b34e7eff15da592460905a9714788e

add 2019-10-15 infra team meeting minutes

view details

push time in 14 days

create barnchwesleywiser/blog.rust-lang.org

branch : self_profiler

created branch time in 14 days

issue commentrust-lang/rust

non-deterministic syn-opt run

Something interesting I noticed, apologies if this is already known;

image

Perhaps this is LLVM optimization related?

Mark-Simulacrum

comment created time in 14 days

pull request commentrust-lang/rust

[self-profiler] add selfprofiling to llvm

Placement of the warning seems fine to me

andjo403

comment created time in 14 days

pull request commentrust-lang/rust

miri: improve and simplify overflow detection

It's been buggy lately but I think it got confused when I edited my comment.

Perf looks unaffected.

@bors r=oli-obk,wesleywiser

RalfJung

comment created time in 16 days

pull request commentrust-lang/rust

miri: improve and simplify overflow detection

@rust-timer build 0f7a6fbaf793dfb724765f4d67fe0fa0addb53fb

RalfJung

comment created time in 16 days

pull request commentrust-lang/rust

rustc: don't resolve Instances which would produce malformed shims.

r? @wesleywiser

eddyb

comment created time in 16 days

pull request commentrust-lang/rust

self-profile: Support arguments for generic_activities.

@bors r+

michaelwoerister

comment created time in 16 days

pull request commentrust-lang/rust

Fix how the `RUSTC_CTFE_BACKTRACE` env var is gotten.

I will work on that this week.

nnethercote

comment created time in 16 days

pull request commentrust-lang/rust

miri: improve and simplify overflow detection

Let's to a perf run just to be sure there's no regressions and then we can land this.

@bors try @rust-timer queue

RalfJung

comment created time in 16 days

issue commentrust-lang/rust

Choose a naming scheme for codegen debuginfo emission.

LLVM on Windows using the msvc toolchain will output PDBs.

I think I would also prefer the generic terminology instead of DWARF specific.

eddyb

comment created time in 16 days

pull request commentrust-lang/rust

Small graphviz improvements for the new dataflow framework

@bors r+

(Assuming CI passes since the other PR is green)

ecstatic-morse

comment created time in 17 days

Pull request review commentrust-lang/rust

miri: improve and simplify overflow detection

 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {                     Not => !val,                     _ => bug!("Invalid bool op {:?}", un_op),                 };-                Ok(ImmTy::from_scalar(Scalar::from_bool(res), self.layout_of(self.tcx.types.bool)?))+                Ok((Scalar::from_bool(res), false, self.tcx.types.bool))             }             ty::Float(fty) => {                 let res = match (un_op, fty) {                     (Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),                     (Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),                     _ => bug!("Invalid float op {:?}", un_op),                 };-                Ok(ImmTy::from_scalar(res, layout))+                Ok((res, false, layout.ty))             }             _ => {                 assert!(layout.ty.is_integral());                 let val = self.force_bits(val, layout.size)?;-                let res = match un_op {-                    Not => !val,+                let (res, overflow) = match un_op {+                    Not => (self.truncate(!val, layout), false), // bitwise negation, then truncate                     Neg => {+                        // arithmetic negation                         assert!(layout.abi.is_signed());-                        (-(val as i128)) as u128

I see bunch of tests in src/tests/ui/consts/const-eval/, specifically the const-eval-overflow-* tests. There's also some incidental coverage in src/tests/mir-opt/const-prop.

RalfJung

comment created time in 17 days

Pull request review commentrust-lang/rust

miri: improve and simplify overflow detection

 impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {         }     } -    fn check_unary_op(&mut self, arg: &Operand<'tcx>, source_info: SourceInfo) -> Option<()> {+    fn check_unary_op(

It seems a bit weird to me that we added an assert here for op == UnOp::Neg but at the same time removed the checking at this function's callsite for Neg. Perhaps we should check in the body of this function that op == UnOp::Neg and if it isn't early return Some(()) since as the assert mentions, "Neg is the only UnOp that can overflow". This function doesn't do anything else so that's the only UnOp we care about.

RalfJung

comment created time in 17 days

Pull request review commentrust-lang/rust

rustc_mir: track inlined callees in SourceScopeData.

 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {     /// `None` is returned and the callsite of the function invocation itself should be used.     crate fn find_closest_untracked_caller_location(&self) -> Option<Span> {         let mut caller_span = None;-        for next_caller in self.stack.iter().rev() {-            if !next_caller.instance.def.requires_caller_location(*self.tcx) {+        for frame in self.stack.iter().rev() {+            if let Some(source_info) = frame.current_source_info() {+                // Walk up the `SourceScope`s, in case some of them are from MIR inlining.+                let mut scope = source_info.scope;+                loop {

Would be great if we could deduplicate this logic.

eddyb

comment created time in 18 days

Pull request review commentrust-lang/rust

remove Panic variant from InterpError

 impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {         // in MIR. However, if overflow checking is disabled, then there won't be any         // `Assert` statement and so we have to do additional checking here.         if !overflow_check {-            self.use_ecx(source_info, |this| {+            if let Some(op) = self.use_ecx(|this| {                 let l = this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)?;                 let (_, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?;                  if overflow {-                    let err = err_panic!(Overflow(op)).into();-                    return Err(err);+                    Ok(Some(op))+                } else {+                    Ok(None)                 }--                Ok(())-            })?;+            })? {+                self.report_panic_as_lint(source_info, PanicInfo::Overflow(op))?;

Looks like @oli-obk consolidated a lint into this code in 8c8a4335323c3c5fe917aff4ba4acb22804abf3e

RalfJung

comment created time in 18 days

Pull request review commentrust-lang/rust

remove Panic variant from InterpError

 impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {         // in MIR. However, if overflow checking is disabled, then there won't be any         // `Assert` statement and so we have to do additional checking here.         if !overflow_check {-            self.use_ecx(source_info, |this| {+            if let Some(op) = self.use_ecx(|this| {                 let l = this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)?;                 let (_, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?;                  if overflow {-                    let err = err_panic!(Overflow(op)).into();-                    return Err(err);+                    Ok(Some(op))+                } else {+                    Ok(None)                 }--                Ok(())-            })?;+            })? {+                self.report_panic_as_lint(source_info, PanicInfo::Overflow(op))?;

Looks like @oli-obk consolidated this lint from a separate pass in 8c8a4335323c3c5fe917aff4ba4acb22804abf3e

RalfJung

comment created time in 18 days

Pull request review commentrust-lang/rust

remove Panic variant from InterpError

 impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {         self.dump_place(*dest);         return Ok(true);     }++    /// "Intercept" a function call to a panic-related function+    /// because we have something special to do for it.+    /// Returns `true` if an intercept happened.

Doesn't this return an Err if an intercept happens?

RalfJung

comment created time in 18 days

more