Skip to content

Commit c35a363

Browse files
committed
Auto merge of rust-lang#116168 - matthiaskrgr:rollup-ys1zmk1, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#116099 (Add regression test for issue rust-lang#79865) - rust-lang#116102 (Correct codegen of `ConstValue::Indirect` scalar and scalar pair) - rust-lang#116131 (Rename `cold_path` to `outline`) - rust-lang#116144 (subst -> instantiate) - rust-lang#116151 (Fix typo in rustdoc unstable features doc) - rust-lang#116153 (Update books) - rust-lang#116162 (Gate and validate `#[rustc_safe_intrinsic]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8bf0dec + b62471d commit c35a363

File tree

52 files changed

+212
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+212
-118
lines changed

compiler/rustc_arena/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ use std::ptr::{self, NonNull};
3737
use std::slice;
3838
use std::{cmp, intrinsics};
3939

40+
/// This calls the passed function while ensuring it won't be inlined into the caller.
4041
#[inline(never)]
4142
#[cold]
42-
fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
43+
fn outline<F: FnOnce() -> R, R>(f: F) -> R {
4344
f()
4445
}
4546

@@ -600,7 +601,7 @@ impl DroplessArena {
600601
unsafe { self.write_from_iter(iter, len, mem) }
601602
}
602603
(_, _) => {
603-
cold_path(move || -> &mut [T] {
604+
outline(move || -> &mut [T] {
604605
let mut vec: SmallVec<[_; 8]> = iter.collect();
605606
if vec.is_empty() {
606607
return &mut [];

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16641664
lifetime.ident,
16651665
));
16661666

1667-
// Now make an arg that we can use for the substs of the opaque tykind.
1667+
// Now make an arg that we can use for the generic params of the opaque tykind.
16681668
let id = self.next_node_id();
16691669
let lifetime_arg = self.new_named_lifetime_with_res(id, lifetime.ident, res);
16701670
let duplicated_lifetime_def_id = self.local_def_id(duplicated_lifetime_node_id);

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) struct RegionName {
2727
/// This helps to print the right kinds of diagnostics.
2828
#[derive(Debug, Clone)]
2929
pub(crate) enum RegionNameSource {
30-
/// A bound (not free) region that was substituted at the def site (not an HRTB).
30+
/// A bound (not free) region that was instantiated at the def site (not an HRTB).
3131
NamedEarlyBoundRegion(Span),
3232
/// A free region that the user has a name (`'a`) for.
3333
NamedFreeRegion(Span),
@@ -619,7 +619,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
619619
// programs, so we need to use delay_span_bug here. See #82126.
620620
self.infcx.tcx.sess.delay_span_bug(
621621
hir_arg.span(),
622-
format!("unmatched subst and hir arg: found {kind:?} vs {hir_arg:?}"),
622+
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
623623
);
624624
}
625625
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22502250

22512251
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
22522252
// Query canonicalization can create local superuniverses (for example in
2253-
// `InferCtx::query_response_substitution_guess`), but they don't have an associated
2253+
// `InferCtx::query_response_instantiation_guess`), but they don't have an associated
22542254
// `UniverseInfo` explaining why they were created.
22552255
// This can cause ICEs if these causes are accessed in diagnostics, for example in issue
22562256
// #114907 where this happens via liveness and dropck outlives results.

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10071007
}
10081008

10091009
pub(super) fn register_predefined_opaques_in_new_solver(&mut self) {
1010-
// OK to use the identity substitutions for each opaque type key, since
1010+
// OK to use the identity arguments for each opaque type key, since
10111011
// we remap opaques from HIR typeck back to their definition params.
10121012
let opaques: Vec<_> = self
10131013
.infcx

compiler/rustc_borrowck/src/universal_regions.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
639639
};
640640

641641
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
642-
let subst_mapping =
643-
iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
642+
let arg_mapping = iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
644643

645-
UniversalRegionIndices { indices: global_mapping.chain(subst_mapping).collect(), fr_static }
644+
UniversalRegionIndices { indices: global_mapping.chain(arg_mapping).collect(), fr_static }
646645
}
647646

648647
fn compute_inputs_and_output(

compiler/rustc_codegen_cranelift/scripts/filter_profile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
100100
stack = &stack[..index + ENCODE_METADATA.len()];
101101
}
102102

103-
const SUBST_AND_NORMALIZE_ERASING_REGIONS: &str = "rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::subst_and_normalize_erasing_regions";
104-
if let Some(index) = stack.find(SUBST_AND_NORMALIZE_ERASING_REGIONS) {
105-
stack = &stack[..index + SUBST_AND_NORMALIZE_ERASING_REGIONS.len()];
103+
const INSTANTIATE_AND_NORMALIZE_ERASING_REGIONS: &str = "rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::instantiate_and_normalize_erasing_regions";
104+
if let Some(index) = stack.find(INSTANTIATE_AND_NORMALIZE_ERASING_REGIONS) {
105+
stack = &stack[..index + INSTANTIATE_AND_NORMALIZE_ERASING_REGIONS.len()];
106106
}
107107

108108
const NORMALIZE_ERASING_LATE_BOUND_REGIONS: &str = "rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_late_bound_regions";

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
359359
where
360360
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
361361
{
362-
self.instance.subst_mir_and_normalize_erasing_regions(
362+
self.instance.instantiate_mir_and_normalize_erasing_regions(
363363
self.tcx,
364364
ty::ParamEnv::reveal_all(),
365365
ty::EarlyBinder::bind(value),

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn make_mir_scope<'ll, 'tcx>(
9090
Some((callee, _)) => {
9191
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
9292
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
93-
let callee = cx.tcx.subst_and_normalize_erasing_regions(
93+
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
9494
instance.args,
9595
ty::ParamEnv::reveal_all(),
9696
ty::EarlyBinder::bind(callee),

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
529529
if let Some(impl_def_id) = cx.tcx.impl_of_method(instance.def_id()) {
530530
// If the method does *not* belong to a trait, proceed
531531
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
532-
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
532+
let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
533533
instance.args,
534534
ty::ParamEnv::reveal_all(),
535535
cx.tcx.type_of(impl_def_id),

compiler/rustc_codegen_ssa/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
118118
T: Copy + TypeFoldable<TyCtxt<'tcx>>,
119119
{
120120
debug!("monomorphize: self.instance={:?}", self.instance);
121-
self.instance.subst_mir_and_normalize_erasing_regions(
121+
self.instance.instantiate_mir_and_normalize_erasing_regions(
122122
self.cx.tcx(),
123123
ty::ParamEnv::reveal_all(),
124124
ty::EarlyBinder::bind(value),

compiler/rustc_codegen_ssa/src/mir/operand.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
135135
assert_eq!(alloc_align, layout.align.abi);
136136

137137
let read_scalar = |start, size, s: abi::Scalar, ty| {
138-
let val = alloc
139-
.0
140-
.read_scalar(
141-
bx,
142-
alloc_range(start, size),
143-
/*read_provenance*/ matches!(s.primitive(), abi::Pointer(_)),
144-
)
145-
.unwrap();
146-
bx.scalar_to_backend(val, s, ty)
138+
match alloc.0.read_scalar(
139+
bx,
140+
alloc_range(start, size),
141+
/*read_provenance*/ matches!(s.primitive(), abi::Pointer(_)),
142+
) {
143+
Ok(val) => bx.scalar_to_backend(val, s, ty),
144+
Err(_) => bx.const_poison(ty),
145+
}
147146
};
148147

149148
// It may seem like all types with `Scalar` or `ScalarPair` ABI are fair game at this point.
@@ -156,18 +155,18 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
156155
Abi::Scalar(s @ abi::Scalar::Initialized { .. }) => {
157156
let size = s.size(bx);
158157
assert_eq!(size, layout.size, "abi::Scalar size does not match layout size");
159-
let val = read_scalar(Size::ZERO, size, s, bx.type_ptr());
158+
let val = read_scalar(offset, size, s, bx.backend_type(layout));
160159
OperandRef { val: OperandValue::Immediate(val), layout }
161160
}
162161
Abi::ScalarPair(
163162
a @ abi::Scalar::Initialized { .. },
164163
b @ abi::Scalar::Initialized { .. },
165164
) => {
166165
let (a_size, b_size) = (a.size(bx), b.size(bx));
167-
let b_offset = a_size.align_to(b.align(bx).abi);
166+
let b_offset = (offset + a_size).align_to(b.align(bx).abi);
168167
assert!(b_offset.bytes() > 0);
169168
let a_val = read_scalar(
170-
Size::ZERO,
169+
offset,
171170
a_size,
172171
a,
173172
bx.scalar_pair_element_backend_type(layout, 0, true),

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
569569
) -> Result<T, ErrorHandled> {
570570
frame
571571
.instance
572-
.try_subst_mir_and_normalize_erasing_regions(
572+
.try_instantiate_mir_and_normalize_erasing_regions(
573573
*self.tcx,
574574
self.param_env,
575575
ty::EarlyBinder::bind(value),

compiler/rustc_const_eval/src/interpret/util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::ty::{
44
};
55
use std::ops::ControlFlow;
66

7-
/// Checks whether a type contains generic parameters which require substitution.
7+
/// Checks whether a type contains generic parameters which must be instantiated.
88
///
99
/// In case it does, returns a `TooGeneric` const eval error. Note that due to polymorphization
1010
/// types may be "concrete enough" even though they still contain generic parameters in
@@ -43,7 +43,8 @@ where
4343
.try_into()
4444
.expect("more generic parameters than can fit into a `u32`");
4545
// Only recurse when generic parameters in fns, closures and generators
46-
// are used and require substitution.
46+
// are used and have to be instantiated.
47+
//
4748
// Just in case there are closures or generators within this subst,
4849
// recurse.
4950
if unused_params.is_used(index) && subst.has_param() {

compiler/rustc_const_eval/src/transform/validate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
558558
}
559559
}
560560

561-
/// A faster version of the validation pass that only checks those things which may break when apply
562-
/// generic substitutions.
561+
/// A faster version of the validation pass that only checks those things which may break when
562+
/// instantiating any generic parameters.
563563
pub fn validate_types<'tcx>(
564564
tcx: TyCtxt<'tcx>,
565565
mir_phase: MirPhase,

compiler/rustc_data_structures/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ use std::fmt;
5151

5252
pub use rustc_index::static_assert_size;
5353

54+
/// This calls the passed function while ensuring it won't be inlined into the caller.
5455
#[inline(never)]
5556
#[cold]
56-
pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
57+
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
5758
f()
5859
}
5960

compiler/rustc_data_structures/src/profiling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
//!
8282
//! [mm]: https://github.com/rust-lang/measureme/
8383
84-
use crate::cold_path;
8584
use crate::fx::FxHashMap;
85+
use crate::outline;
8686

8787
use std::borrow::Borrow;
8888
use std::collections::hash_map::Entry;
@@ -697,7 +697,7 @@ impl<'a> TimingGuard<'a> {
697697
#[inline]
698698
pub fn finish_with_query_invocation_id(self, query_invocation_id: QueryInvocationId) {
699699
if let Some(guard) = self.0 {
700-
cold_path(|| {
700+
outline(|| {
701701
let event_id = StringId::new_virtual(query_invocation_id.0);
702702
let event_id = EventId::from_virtual(event_id);
703703
guard.finish_with_override_event_id(event_id);

compiler/rustc_data_structures/src/sync/worker_local.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ptr;
66
use std::sync::Arc;
77

88
#[cfg(parallel_compiler)]
9-
use {crate::cold_path, crate::sync::CacheAligned};
9+
use {crate::outline, crate::sync::CacheAligned};
1010

1111
/// A pointer to the `RegistryData` which uniquely identifies a registry.
1212
/// This identifier can be reused if the registry gets freed.
@@ -25,11 +25,7 @@ impl RegistryId {
2525
fn verify(self) -> usize {
2626
let (id, index) = THREAD_DATA.with(|data| (data.registry_id.get(), data.index.get()));
2727

28-
if id == self {
29-
index
30-
} else {
31-
cold_path(|| panic!("Unable to verify registry association"))
32-
}
28+
if id == self { index } else { outline(|| panic!("Unable to verify registry association")) }
3329
}
3430
}
3531

compiler/rustc_error_codes/src/error_codes/E0038.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,13 @@ fn foo<T>(x: T) {
162162
```
163163

164164
The machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any
165-
other type substitution is different. Hence the compiler generates the
165+
other instantiation is different. Hence the compiler generates the
166166
implementation on-demand. If you call `foo()` with a `bool` parameter, the
167167
compiler will only generate code for `foo::<bool>()`. When we have additional
168168
type parameters, the number of monomorphized implementations the compiler
169169
generates does not grow drastically, since the compiler will only generate an
170-
implementation if the function is called with unparameterized substitutions
171-
(i.e., substitutions where none of the substituted types are themselves
172-
parameterized).
170+
implementation if the function is called with fully concrete arguments
171+
(i.e., arguments which do not contain any generic parameters).
173172

174173
However, with trait objects we have to make a table containing _every_ object
175174
that implements the trait. Now, if it has type parameters, we need to add

compiler/rustc_error_codes/src/error_codes/E0094.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ An invalid number of generic parameters was passed to an intrinsic function.
33
Erroneous code example:
44

55
```compile_fail,E0094
6-
#![feature(intrinsics)]
6+
#![feature(intrinsics, rustc_attrs)]
77
#![allow(internal_features)]
88
99
extern "rust-intrinsic" {
@@ -18,7 +18,7 @@ and verify with the function declaration in the Rust source code.
1818
Example:
1919

2020
```
21-
#![feature(intrinsics)]
21+
#![feature(intrinsics, rustc_attrs)]
2222
#![allow(internal_features)]
2323
2424
extern "rust-intrinsic" {

compiler/rustc_error_codes/src/error_codes/E0211.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You used a function or type which doesn't fit the requirements for where it was
44
used. Erroneous code examples:
55

66
```compile_fail
7-
#![feature(intrinsics)]
7+
#![feature(intrinsics, rustc_attrs)]
88
#![allow(internal_features)]
99
1010
extern "rust-intrinsic" {
@@ -41,7 +41,7 @@ impl Foo {
4141
For the first code example, please check the function definition. Example:
4242

4343
```
44-
#![feature(intrinsics)]
44+
#![feature(intrinsics, rustc_attrs)]
4545
#![allow(internal_features)]
4646
4747
extern "rust-intrinsic" {

compiler/rustc_feature/src/builtin_attrs.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
537537
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
538538
"allow_internal_unsafe side-steps the unsafe_code lint",
539539
),
540-
ungated!(rustc_safe_intrinsic, Normal, template!(Word), DuplicatesOk),
541540
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
542541
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
543542
through unstable paths"),
@@ -806,6 +805,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
806805
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
807806
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
808807
),
808+
rustc_attr!(
809+
rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
810+
"the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
811+
),
809812

810813
// ==========================================================================
811814
// Internal attributes, Testing:

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
427427
let bound_vars = tcx.late_bound_vars(binding.hir_id);
428428
ty::Binder::bind_with_vars(subst_output, bound_vars)
429429
} else {
430-
// Include substitutions for generic parameters of associated types
430+
// Append the generic arguments of the associated type to the `trait_ref`.
431431
candidate.map_bound(|trait_ref| {
432432
let ident = Ident::new(assoc_item.name, binding.item_name.span);
433433
let item_segment = hir::PathSegment {

compiler/rustc_hir_analysis/src/astconv/generics.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,22 @@ fn generic_arg_mismatch_err(
139139
err.emit()
140140
}
141141

142-
/// Creates the relevant generic argument substitutions
142+
/// Creates the relevant generic arguments
143143
/// corresponding to a set of generic parameters. This is a
144144
/// rather complex function. Let us try to explain the role
145145
/// of each of its parameters:
146146
///
147-
/// To start, we are given the `def_id` of the thing we are
148-
/// creating the substitutions for, and a partial set of
149-
/// substitutions `parent_args`. In general, the substitutions
150-
/// for an item begin with substitutions for all the "parents" of
147+
/// To start, we are given the `def_id` of the thing whose generic
148+
/// parameters we are instantiating, and a partial set of
149+
/// arguments `parent_args`. In general, the generic arguments
150+
/// for an item begin with arguments for all the "parents" of
151151
/// that item -- e.g., for a method it might include the
152152
/// parameters from the impl.
153153
///
154154
/// Therefore, the method begins by walking down these parents,
155155
/// starting with the outermost parent and proceed inwards until
156156
/// it reaches `def_id`. For each parent `P`, it will check `parent_args`
157-
/// first to see if the parent's substitutions are listed in there. If so,
157+
/// first to see if the parent's arguments are listed in there. If so,
158158
/// we can append those and move on. Otherwise, it invokes the
159159
/// three callback functions:
160160
///
@@ -188,15 +188,16 @@ pub fn create_args_for_parent_generic_args<'tcx, 'a>(
188188
stack.push((def_id, parent_defs));
189189
}
190190

191-
// We manually build up the substitution, rather than using convenience
191+
// We manually build up the generic arguments, rather than using convenience
192192
// methods in `subst.rs`, so that we can iterate over the arguments and
193193
// parameters in lock-step linearly, instead of trying to match each pair.
194194
let mut args: SmallVec<[ty::GenericArg<'tcx>; 8]> = SmallVec::with_capacity(count);
195195
// Iterate over each segment of the path.
196196
while let Some((def_id, defs)) = stack.pop() {
197197
let mut params = defs.params.iter().peekable();
198198

199-
// If we have already computed substitutions for parents, we can use those directly.
199+
// If we have already computed the generic arguments for parents,
200+
// we can use those directly.
200201
while let Some(&param) = params.peek() {
201202
if let Some(&kind) = parent_args.get(param.index as usize) {
202203
args.push(kind);

0 commit comments

Comments
 (0)