rust/compiler
bors 8fb67fb37f Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk
Toggle assert_unsafe_precondition in codegen instead of expansion

The goal of this PR is to make some of the unsafe precondition checks in the standard library available in debug builds. Some UI tests are included to verify that it does that.

The diff is large, but most of it is blessing mir-opt tests and I've also split up this PR so it can be reviewed commit-by-commit.

This PR:
1. Adds a new intrinsic, `debug_assertions` which is lowered to a new MIR NullOp, and only to a constant after monomorphization
2. Rewrites `assume_unsafe_precondition` to check the new intrinsic, and be monomorphic.
3. Skips codegen of the `assume` intrinsic in unoptimized builds, because that was silly before but with these checks it's *very* silly
4. The checks with the most overhead are `ptr::read`/`ptr::write` and `NonNull::new_unchecked`. I've simply added `#[cfg(debug_assertions)]` to the checks for `ptr::read`/`ptr::write` because I was unable to come up with any (good) ideas for decreasing their impact. But for `NonNull::new_unchecked` I found that the majority of callers can use a different function, often a safe one.

Yes, this PR slows down the compile time of some programs. But in our benchmark suite it's never more than 1% icount, and the average icount change in debug-full programs is 0.22%. I think that is acceptable for such an improvement in developer experience.

https://github.com/rust-lang/rust/issues/120539#issuecomment-1922687101
2024-02-09 13:33:38 +00:00
..
rustc Clean up `rustc_*/Cargo.toml`. 2023-10-30 08:46:02 +11:00
rustc_abi Fix `rustc_abi` build on stable 2024-01-16 21:15:31 +01:00
rustc_arena Fix `Stable` trait and its impls to work with the new `with_tables` 2024-01-19 09:42:51 +00:00
rustc_ast Add async bound modifier to enable async Fn bounds 2024-01-31 16:59:19 +00:00
rustc_ast_lowering Rollup merge of #120750 - compiler-errors:itctx-by-val, r=cjgillot 2024-02-08 20:34:58 +01:00
rustc_ast_passes Add `SubdiagnosticMessageOp` as a trait alias. 2024-02-08 13:02:44 +11:00
rustc_ast_pretty Add async bound modifier to enable async Fn bounds 2024-01-31 16:59:19 +00:00
rustc_attr Stop using `String` for error codes. 2024-01-29 07:41:41 +11:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk 2024-02-09 13:33:38 +00:00
rustc_builtin_macros Add `SubdiagnosticMessageOp` as a trait alias. 2024-02-08 13:02:44 +11:00
rustc_codegen_cranelift Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00
rustc_codegen_gcc Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors 2024-02-06 22:45:42 +01:00
rustc_codegen_llvm Rollup merge of #119162 - heiher:direct-access-external-data, r=petrochenkov 2024-02-07 18:24:41 +01:00
rustc_codegen_ssa Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00
rustc_const_eval Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00
rustc_data_structures Rollup merge of #119600 - aDotInTheVoid:comment-fix, r=compiler-errors 2024-02-05 06:37:14 +01:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Remove an `unchecked_claim_error_was_emitted` call. 2024-02-07 18:57:38 +11:00
rustc_error_codes Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors 2024-02-06 22:45:42 +01:00
rustc_error_messages Split `Level::DelayedBug` in two. 2024-02-05 10:03:01 +11:00
rustc_errors Fix `span_bug!` backtraces 2024-02-08 14:44:52 +00:00
rustc_expand Add async bound modifier to enable async Fn bounds 2024-01-31 16:59:19 +00:00
rustc_feature Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors 2024-02-06 22:45:42 +01:00
rustc_fluent_macro annotate-snippets: update to 0.10 2024-01-07 16:53:32 +03:00
rustc_fs_util Clean up `rustc_*/Cargo.toml`. 2023-10-30 08:46:02 +11:00
rustc_graphviz remove unused pub fn 2023-11-23 14:11:02 +03:00
rustc_hir Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr 2024-02-08 12:14:19 +00:00
rustc_hir_analysis Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk 2024-02-09 13:33:38 +00:00
rustc_hir_pretty hir: Remove `fn opt_hir_id` and `fn opt_span` 2024-02-07 09:38:24 +03:00
rustc_hir_typeck Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb 2024-02-08 20:34:57 +01:00
rustc_incremental hir: Simplify `hir_owner_nodes` query 2024-01-30 15:00:52 +03:00
rustc_index Auto merge of #120024 - Mark-Simulacrum:fast-union-merge, r=cjgillot 2024-01-27 22:26:37 +00:00
rustc_index_macros Restrict access to the private field of newtype indexes 2024-01-19 15:38:47 +00:00
rustc_infer Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb 2024-02-08 20:34:57 +01:00
rustc_interface Rollup merge of #119162 - heiher:direct-access-external-data, r=petrochenkov 2024-02-07 18:24:41 +01:00
rustc_lexer Use `unescape_unicode` for raw C string literals. 2024-01-25 12:28:11 +11:00
rustc_lint Auto merge of #120544 - BoxyUwU:enter_forall, r=lcnr 2024-02-08 16:42:56 +00:00
rustc_lint_defs update the tracking issue for structural match violations 2024-02-05 20:36:11 +01:00
rustc_llvm Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors 2024-02-06 22:45:42 +01:00
rustc_log rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
rustc_macros Add `SubdiagnosticMessageOp` as a trait alias. 2024-02-08 13:02:44 +11:00
rustc_metadata Rollup merge of #120206 - petrochenkov:somehir, r=compiler-errors 2024-02-08 09:06:32 +01:00
rustc_middle Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk 2024-02-09 13:33:38 +00:00
rustc_mir_build Rollup merge of #120801 - oli-obk:drop_recursion_ice, r=Nilstrieb 2024-02-08 20:35:01 +01:00
rustc_mir_dataflow Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00
rustc_mir_transform Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk 2024-02-09 13:33:38 +00:00
rustc_monomorphize Rollup merge of #120602 - klensy:mono-comment, r=nnethercote 2024-02-06 19:40:07 +01:00
rustc_next_trait_solver Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
rustc_parse Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr 2024-02-08 12:14:19 +00:00
rustc_parse_format Rename the unescaping functions. 2024-01-25 12:28:11 +11:00
rustc_passes Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr 2024-02-08 12:14:19 +00:00
rustc_pattern_analysis Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb 2024-02-08 20:34:57 +01:00
rustc_privacy Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
rustc_query_impl Remove unused features 2024-01-25 14:01:33 +00:00
rustc_query_system Remove dead args from functions 2024-02-02 22:47:26 +00:00
rustc_resolve Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb 2024-02-08 20:34:57 +01:00
rustc_serialize Remove unused features 2024-01-25 14:01:33 +00:00
rustc_session Rollup merge of #120735 - nnethercote:rm-some-unchecked_claims, r=oli-obk 2024-02-07 18:24:46 +01:00
rustc_smir Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00
rustc_span Rollup merge of #120735 - nnethercote:rm-some-unchecked_claims, r=oli-obk 2024-02-07 18:24:46 +01:00
rustc_symbol_mangling Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
rustc_target Rollup merge of #119162 - heiher:direct-access-external-data, r=petrochenkov 2024-02-07 18:24:41 +01:00
rustc_trait_selection Rollup merge of #120590 - compiler-errors:dead, r=Nilstrieb 2024-02-08 20:34:57 +01:00
rustc_traits Remove unused features 2024-01-25 14:01:33 +00:00
rustc_transmute Remove unused features 2024-01-25 14:01:33 +00:00
rustc_ty_utils Fudge coroutine argument for CoroutineKindShim in fn_sig_for_fn_abi 2024-02-06 02:53:06 +00:00
rustc_type_ir reviews + rebase 2024-02-08 13:19:25 +00:00
stable_mir Add a new debug_assertions instrinsic (compiler) 2024-02-08 11:49:08 -05:00