-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Generate slightly better unoptimized code for for-loops #16517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+3
−4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The discriminant for Option values is either 0 or 1, so we can just truncate the value to an i1, which ends up as a no-op for Options containing pointers.
bors
added a commit
that referenced
this pull request
Aug 15, 2014
The discriminant for Option values is either 0 or 1, so we can just truncate the value to an i1, which ends up as a no-op for Options containing pointers.
matthiaskrgr
pushed a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 11, 2024
…tion-function, r=Veykril internal: fix crash inside `filter_unnecessary_bounds` for a missing generic param `@Wilfred` reported a crash here shortly after reporting rust-lang/rust-analyzer#16516, which makes us think that the blast radius of ambiguities in Chalk can be larger than expected. This PR tries to be a bit more defensive as a result. (The 20th frame is the salient frame in the backtrace below.) <details> <summary>Backtrace of the crash</summary> ``` request handler panicked: no entry found for key backtrace: 0: stdx::panic_context::PanicContext::init::{{closure}}::{{closure}}::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/panic_context.rs:32:43 1: stdx::panic_context::with_backtrace::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/panic_context.rs:61:32 2: std::thread::local::LocalKey<T>::try_with at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16 3: std::thread::local::LocalKey<T>::with at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9 4: stdx::panic_context::with_backtrace at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/panic_context.rs:61:5 5: stdx::panic_context::PanicContext::init::{{closure}}::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/panic_context.rs:31:21 6: stdx::panic_context::with_ctx::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/panic_context.rs:53:20 7: std::thread::local::LocalKey<T>::try_with at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16 8: std::thread::local::LocalKey<T>::with at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9 9: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2021:9 10: std::panicking::rust_panic_with_hook at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:783:13 11: std::panicking::begin_panic_handler::{{closure}} at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:657:13 12: std::sys_common::backtrace::__rust_end_short_backtrace at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18 13: rust_begin_unwind at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5 14: core::panicking::panic_fmt at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14 15: core::panicking::panic_display at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:178:5 16: core::panicking::panic_str at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:152:5 17: core::option::expect_failed at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:1985:5 18: core::option::Option<T>::expect at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:894:21 19: <std::collections::hash::map::HashMap<K,V,S> as core::ops::index::Index<&Q>>::index at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/collections/hash/map.rs:1341:23 20: ide_assists::handlers::generate_function::filter_unnecessary_bounds::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:911:71 21: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:305:13 22: core::option::Option<T>::map at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:1072:29 23: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/adapters/map.rs:103:26 24: ide_assists::handlers::generate_function::Graph::compute_reachable_nodes at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:1158:20 25: ide_assists::handlers::generate_function::filter_unnecessary_bounds at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:912:21 26: ide_assists::handlers::generate_function::fn_generic_params at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:640:5 27: ide_assists::handlers::generate_function::FunctionBuilder::from_call at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:283:13 28: ide_assists::handlers::generate_function::gen_fn at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:78:28 29: ide_assists::handlers::generate_function::generate_function at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/handlers/generate_function.rs:55:5 30: ide_assists::assists::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/lib.rs:99:9 31: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::for_each at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/slice/iter/macros.rs:254:21 32: ide_assists::assists at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide-assists/src/lib.rs:98:5 33: ide::Analysis::assists_with_fixes::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide/src/lib.rs:667:27 34: ide::Analysis::with_db::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide/src/lib.rs:764:29 35: std::panicking::try::do_call at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40 36: std::panicking::try at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19 37: std::panic::catch_unwind at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14 38: salsa::Cancelled::catch at /var/twsvcscm/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rust-analyzer-salsa-0.17.0-pre.5/src/lib.rs:631:15 39: ide::Analysis::with_db at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide/src/lib.rs:764:9 40: ide::Analysis::assists_with_fixes at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/ide/src/lib.rs:656:9 41: rust_analyzer::handlers::request::handle_code_action at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/rust-analyzer/src/handlers/request.rs:1149:19 42: rust_analyzer::dispatch::RequestDispatcher::on_with_thread_intent::{{closure}}::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/rust-analyzer/src/dispatch.rs:198:54 43: std::panicking::try::do_call at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40 44: std::panicking::try at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19 45: std::panic::catch_unwind at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14 46: rust_analyzer::dispatch::RequestDispatcher::on_with_thread_intent::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/rust-analyzer/src/dispatch.rs:198:26 47: rust_analyzer::task_pool::TaskPool<T>::spawn::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/rust-analyzer/src/task_pool.rs:26:33 48: stdx::thread::pool::Pool::spawn::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/thread/pool.rs:82:13 49: core::ops::function::FnOnce::call_once{{vtable.shim}} at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5 50: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9 51: stdx::thread::pool::Pool::new::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/thread/pool.rs:61:29 52: stdx::thread::Builder::spawn::{{closure}} at /data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/third-party/rust-analyzer/master/crates/stdx/src/thread.rs:66:13 53: std::sys_common::backtrace::__rust_begin_short_backtrace at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:154:18 54: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}} at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:529:17 55: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9 56: std::panicking::try::do_call at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40 57: std::panicking::try at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19 58: std::panic::catch_unwind at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14 59: std::thread::Builder::spawn_unchecked_::{{closure}} at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:528:30 60: core::ops::function::FnOnce::call_once{{vtable.shim}} at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5 61: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9 62: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9 63: std::sys::unix::thread::Thread::new::thread_start at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/unix/thread.rs:108:17 64: start_thread 65: clone3 ``` </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The discriminant for Option values is either 0 or 1, so we can just
truncate the value to an i1, which ends up as a no-op for Options
containing pointers.