rust/compiler
Ralf Jung a0215d8e46 Re-do recursive const stability checks
Fundamentally, we have *three* disjoint categories of functions:
1. const-stable functions
2. private/unstable functions that are meant to be callable from const-stable functions
3. functions that can make use of unstable const features

This PR implements the following system:
- `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions.
- `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category.
- `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls.

Also, several holes in recursive const stability checking are being closed.
There's still one potential hole that is hard to avoid, which is when MIR
building automatically inserts calls to a particular function in stable
functions -- which happens in the panic machinery. Those need to *not* be
`rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be
sure they follow recursive const stability. But that's a fairly rare and special
case so IMO it's fine.

The net effect of this is that a `#[unstable]` or unmarked function can be
constified simply by marking it as `const fn`, and it will then be
const-callable from stable `const fn` and subject to recursive const stability
requirements. If it is publicly reachable (which implies it cannot be unmarked),
it will be const-unstable under the same feature gate. Only if the function ever
becomes `#[stable]` does it need a `#[rustc_const_unstable]` or
`#[rustc_const_stable]` marker to decide if this should also imply
const-stability.

Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to
use unstable const lang features (including intrinsics), or (b) `#[stable]`
functions that are not yet intended to be const-stable. Adding
`#[rustc_const_stable]` is only needed for functions that are actually meant to
be directly callable from stable const code. `#[rustc_const_stable_indirect]` is
used to mark intrinsics as const-callable and for `#[rustc_const_unstable]`
functions that are actually called from other, exposed-on-stable `const fn`. No
other attributes are required.
2024-10-25 20:31:40 +02:00
..
rustc
rustc_abi
rustc_arena
rustc_ast Remove visit_expr_post 2024-10-24 10:59:40 -03:00
rustc_ast_ir
rustc_ast_lowering Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_ast_passes nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_ast_pretty Print safety correctly in extern static items 2024-10-24 00:41:27 +00:00
rustc_attr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #131756 - compiler-errors:deeply-normalize-type-err, r=lcnr 2024-10-24 14:19:55 +11:00
rustc_builtin_macros nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_codegen_cranelift Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_codegen_gcc coverage: SSA doesn't need to know about instrprof_increment 2024-10-25 14:24:05 +11:00
rustc_codegen_llvm coverage: SSA doesn't need to know about instrprof_increment 2024-10-25 14:24:05 +11:00
rustc_codegen_ssa coverage: SSA doesn't need to know about instrprof_increment 2024-10-25 14:24:05 +11:00
rustc_const_eval Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_data_structures Replace an FTP link in comments with an equivalent HTTPS link 2024-10-24 17:02:11 +11:00
rustc_driver
rustc_driver_impl
rustc_error_codes
rustc_error_messages
rustc_errors "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens 2024-10-23 02:45:24 -07:00
rustc_expand Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_feature Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_hir_analysis Auto merge of #132116 - matthiaskrgr:rollup-3a0ia4r, r=matthiaskrgr 2024-10-24 20:28:20 +00:00
rustc_hir_pretty Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_hir_typeck Be better at enforcing that const_conditions is only called on const items 2024-10-24 09:46:36 +00:00
rustc_incremental nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_index
rustc_index_macros
rustc_infer Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_interface
rustc_lexer
rustc_lint Auto merge of #132116 - matthiaskrgr:rollup-3a0ia4r, r=matthiaskrgr 2024-10-24 20:28:20 +00:00
rustc_lint_defs
rustc_llvm coverage: Emit MC/DC intrinsics using the normal helper method 2024-10-25 14:01:36 +11:00
rustc_log
rustc_macros
rustc_metadata Be better at enforcing that const_conditions is only called on const items 2024-10-24 09:46:36 +00:00
rustc_middle Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_mir_build Rollup merge of #129248 - compiler-errors:raw-ref-deref, r=nnethercote 2024-10-24 10:35:39 +02:00
rustc_mir_dataflow "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens 2024-10-23 02:45:24 -07:00
rustc_mir_transform fix a couple clippy:complexitys 2024-10-23 22:15:59 +02:00
rustc_monomorphize Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
rustc_next_trait_solver Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
rustc_parse "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens 2024-10-23 02:45:24 -07:00
rustc_parse_format
rustc_passes Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_pattern_analysis nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_privacy Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_query_impl
rustc_query_system stop hashing compile-time constant 2024-10-23 19:46:52 +02:00
rustc_resolve nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_sanitizers
rustc_serialize
rustc_session
rustc_smir Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_span Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
rustc_symbol_mangling nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
rustc_target Rollup merge of #131169 - madsmtm:target-info-nto-vendor, r=wesleywiser 2024-10-24 14:19:53 +11:00
rustc_trait_selection Auto merge of #131985 - compiler-errors:const-pred, r=fee1-dead 2024-10-24 17:33:42 +00:00
rustc_traits Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_transmute
rustc_ty_utils Be better at enforcing that const_conditions is only called on const items 2024-10-24 09:46:36 +00:00
rustc_type_ir Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
rustc_type_ir_macros
stable_mir Rollup merge of #132085 - celinval:update-smir-doc, r=compiler-errors 2024-10-24 23:23:55 -07:00