Skip to content

Commit d9c11c6

Browse files
committed
Auto merge of rust-lang#3042 - rust-lang:rustup-2023-08-29, r=RalfJung
Automatic sync from rustc
2 parents 63bf240 + fb3565a commit d9c11c6

File tree

307 files changed

+2409
-1424
lines changed

Some content is hidden

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

307 files changed

+2409
-1424
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ enum ImplTraitContext {
236236
ReturnPositionOpaqueTy {
237237
/// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
238238
origin: hir::OpaqueTyOrigin,
239-
in_trait: bool,
239+
fn_kind: FnDeclKind,
240240
},
241241
/// Impl trait in type aliases.
242242
TypeAliasesOpaqueTy { in_assoc_ty: bool },
@@ -312,7 +312,7 @@ impl std::fmt::Display for ImplTraitPosition {
312312
}
313313
}
314314

315-
#[derive(Debug, PartialEq, Eq)]
315+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
316316
enum FnDeclKind {
317317
Fn,
318318
Inherent,
@@ -1401,13 +1401,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14011401
TyKind::ImplTrait(def_node_id, bounds) => {
14021402
let span = t.span;
14031403
match itctx {
1404-
ImplTraitContext::ReturnPositionOpaqueTy { origin, in_trait } => self
1404+
ImplTraitContext::ReturnPositionOpaqueTy { origin, fn_kind } => self
14051405
.lower_opaque_impl_trait(
14061406
span,
14071407
*origin,
14081408
*def_node_id,
14091409
bounds,
1410-
*in_trait,
1410+
Some(*fn_kind),
14111411
itctx,
14121412
),
14131413
&ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty } => self
@@ -1416,7 +1416,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14161416
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty },
14171417
*def_node_id,
14181418
bounds,
1419-
false,
1419+
None,
14201420
itctx,
14211421
),
14221422
ImplTraitContext::Universal => {
@@ -1523,7 +1523,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15231523
origin: hir::OpaqueTyOrigin,
15241524
opaque_ty_node_id: NodeId,
15251525
bounds: &GenericBounds,
1526-
in_trait: bool,
1526+
fn_kind: Option<FnDeclKind>,
15271527
itctx: &ImplTraitContext,
15281528
) -> hir::TyKind<'hir> {
15291529
// Make sure we know that some funky desugaring has been going on here.
@@ -1540,10 +1540,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15401540
Vec::new()
15411541
}
15421542
hir::OpaqueTyOrigin::FnReturn(..) => {
1543-
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
1544-
// example, we only need to duplicate lifetimes that appear in the
1545-
// bounds, since those are the only ones that are captured by the opaque.
1546-
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
1543+
if let FnDeclKind::Impl | FnDeclKind::Trait =
1544+
fn_kind.expect("expected RPITs to be lowered with a FnKind")
1545+
{
1546+
// return-position impl trait in trait was decided to capture all
1547+
// in-scope lifetimes, which we collect for all opaques during resolution.
1548+
self.resolver
1549+
.take_extra_lifetime_params(opaque_ty_node_id)
1550+
.into_iter()
1551+
.map(|(ident, id, _)| Lifetime { id, ident })
1552+
.collect()
1553+
} else {
1554+
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
1555+
// example, we only need to duplicate lifetimes that appear in the
1556+
// bounds, since those are the only ones that are captured by the opaque.
1557+
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
1558+
}
15471559
}
15481560
hir::OpaqueTyOrigin::AsyncFn(..) => {
15491561
unreachable!("should be using `lower_async_fn_ret_ty`")
@@ -1554,7 +1566,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15541566
self.lower_opaque_inner(
15551567
opaque_ty_node_id,
15561568
origin,
1557-
in_trait,
1569+
matches!(fn_kind, Some(FnDeclKind::Trait)),
15581570
captured_lifetimes_to_duplicate,
15591571
span,
15601572
opaque_ty_span,
@@ -1802,20 +1814,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18021814
}
18031815

18041816
let fn_def_id = self.local_def_id(fn_node_id);
1805-
self.lower_async_fn_ret_ty(
1806-
&decl.output,
1807-
fn_def_id,
1808-
ret_id,
1809-
matches!(kind, FnDeclKind::Trait),
1810-
)
1817+
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind)
18111818
} else {
18121819
match &decl.output {
18131820
FnRetTy::Ty(ty) => {
18141821
let context = if kind.return_impl_trait_allowed(self.tcx) {
18151822
let fn_def_id = self.local_def_id(fn_node_id);
18161823
ImplTraitContext::ReturnPositionOpaqueTy {
18171824
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1818-
in_trait: matches!(kind, FnDeclKind::Trait),
1825+
fn_kind: kind,
18191826
}
18201827
} else {
18211828
let position = match kind {
@@ -1883,7 +1890,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18831890
output: &FnRetTy,
18841891
fn_def_id: LocalDefId,
18851892
opaque_ty_node_id: NodeId,
1886-
in_trait: bool,
1893+
fn_kind: FnDeclKind,
18871894
) -> hir::FnRetTy<'hir> {
18881895
let span = self.lower_span(output.span());
18891896
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
@@ -1898,23 +1905,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18981905
let opaque_ty_ref = self.lower_opaque_inner(
18991906
opaque_ty_node_id,
19001907
hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
1901-
in_trait,
1908+
matches!(fn_kind, FnDeclKind::Trait),
19021909
captured_lifetimes,
19031910
span,
19041911
opaque_ty_span,
19051912
|this| {
19061913
let future_bound = this.lower_async_fn_output_type_to_future_bound(
19071914
output,
19081915
span,
1909-
if in_trait && !this.tcx.features().return_position_impl_trait_in_trait {
1916+
if let FnDeclKind::Trait = fn_kind
1917+
&& !this.tcx.features().return_position_impl_trait_in_trait
1918+
{
19101919
ImplTraitContext::FeatureGated(
19111920
ImplTraitPosition::TraitReturn,
19121921
sym::return_position_impl_trait_in_trait,
19131922
)
19141923
} else {
19151924
ImplTraitContext::ReturnPositionOpaqueTy {
19161925
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1917-
in_trait,
1926+
fn_kind,
19181927
}
19191928
},
19201929
);

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn expand_include_bytes(
217217
};
218218
match cx.source_map().load_binary_file(&file) {
219219
Ok(bytes) => {
220-
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes.into()));
220+
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes));
221221
base::MacEager::expr(expr)
222222
}
223223
Err(e) => {

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn clif_sig_from_fn_abi<'tcx>(
3939
pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: CallConv) -> CallConv {
4040
match c {
4141
Conv::Rust | Conv::C => default_call_conv,
42-
Conv::RustCold => CallConv::Cold,
42+
Conv::Cold | Conv::PreserveMost | Conv::PreserveAll => CallConv::Cold,
4343
Conv::X86_64SysV => CallConv::SystemV,
4444
Conv::X86_64Win64 => CallConv::WindowsFastcall,
4545

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
125125
PassMode::Ignore => continue,
126126
PassMode::Direct(_) => arg.layout.immediate_gcc_type(cx),
127127
PassMode::Pair(..) => {
128-
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 0, true));
129-
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 1, true));
128+
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 0));
129+
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 1));
130130
continue;
131131
}
132132
PassMode::Indirect { extra_attrs: Some(_), .. } => {

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
821821

822822
let mut load = |i, scalar: &abi::Scalar, align| {
823823
let llptr = self.struct_gep(pair_type, place.llval, i as u64);
824-
let llty = place.layout.scalar_pair_element_gcc_type(self, i, false);
824+
let llty = place.layout.scalar_pair_element_gcc_type(self, i);
825825
let load = self.load(llty, llptr, align);
826826
scalar_load_metadata(self, load, scalar);
827827
if scalar.is_bool() { self.trunc(load, self.type_i1()) } else { load }

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
5555
_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
5656
_llfn: RValue<'gcc>,
5757
_mir: &mir::Body<'tcx>,
58-
) -> Option<FunctionDebugContext<'tcx, Self::DIScope, Self::DILocation>> {
58+
) -> Option<FunctionDebugContext<Self::DIScope, Self::DILocation>> {
5959
// TODO(antoyo)
6060
None
6161
}

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gccjit::{Struct, Type};
44
use crate::rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods};
55
use rustc_middle::bug;
66
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
7-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
7+
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
88
use rustc_middle::ty::print::with_no_trimmed_paths;
99
use rustc_target::abi::{self, Abi, Align, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants};
1010
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
@@ -74,8 +74,8 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
7474
Abi::ScalarPair(..) => {
7575
return cx.type_struct(
7676
&[
77-
layout.scalar_pair_element_gcc_type(cx, 0, false),
78-
layout.scalar_pair_element_gcc_type(cx, 1, false),
77+
layout.scalar_pair_element_gcc_type(cx, 0),
78+
layout.scalar_pair_element_gcc_type(cx, 1),
7979
],
8080
false,
8181
);
@@ -150,7 +150,7 @@ pub trait LayoutGccExt<'tcx> {
150150
fn gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>;
151151
fn immediate_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>;
152152
fn scalar_gcc_type_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, scalar: &abi::Scalar, offset: Size) -> Type<'gcc>;
153-
fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize, immediate: bool) -> Type<'gcc>;
153+
fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize) -> Type<'gcc>;
154154
fn gcc_field_index(&self, index: usize) -> u64;
155155
fn pointee_info_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, offset: Size) -> Option<PointeeInfo>;
156156
}
@@ -182,23 +182,16 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
182182
/// of that field's type - this is useful for taking the address of
183183
/// that field and ensuring the struct has the right alignment.
184184
fn gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
185+
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
186+
// In other words, this should generally not look at the type at all, but only at the
187+
// layout.
185188
if let Abi::Scalar(ref scalar) = self.abi {
186189
// Use a different cache for scalars because pointers to DSTs
187190
// can be either fat or thin (data pointers of fat pointers).
188191
if let Some(&ty) = cx.scalar_types.borrow().get(&self.ty) {
189192
return ty;
190193
}
191-
let ty =
192-
match *self.ty.kind() {
193-
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
194-
cx.type_ptr_to(cx.layout_of(ty).gcc_type(cx))
195-
}
196-
ty::Adt(def, _) if def.is_box() => {
197-
cx.type_ptr_to(cx.layout_of(self.ty.boxed_ty()).gcc_type(cx))
198-
}
199-
ty::FnPtr(sig) => cx.fn_ptr_backend_type(&cx.fn_abi_of_fn_ptr(sig, ty::List::empty())),
200-
_ => self.scalar_gcc_type_at(cx, scalar, Size::ZERO),
201-
};
194+
let ty = self.scalar_gcc_type_at(cx, scalar, Size::ZERO);
202195
cx.scalar_types.borrow_mut().insert(self.ty, ty);
203196
return ty;
204197
}
@@ -272,23 +265,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
272265
}
273266
}
274267

275-
fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize, immediate: bool) -> Type<'gcc> {
276-
// TODO(antoyo): remove llvm hack:
277-
// HACK(eddyb) special-case fat pointers until LLVM removes
278-
// pointee types, to avoid bitcasting every `OperandRef::deref`.
279-
match self.ty.kind() {
280-
ty::Ref(..) | ty::RawPtr(_) => {
281-
return self.field(cx, index).gcc_type(cx);
282-
}
283-
// only wide pointer boxes are handled as pointers
284-
// thin pointer boxes with scalar allocators are handled by the general logic below
285-
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_zst() => {
286-
let ptr_ty = Ty::new_mut_ptr(cx.tcx,self.ty.boxed_ty());
287-
return cx.layout_of(ptr_ty).scalar_pair_element_gcc_type(cx, index, immediate);
288-
}
289-
_ => {}
290-
}
291-
268+
fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize) -> Type<'gcc> {
269+
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
270+
// In other words, this should generally not look at the type at all, but only at the
271+
// layout.
292272
let (a, b) = match self.abi {
293273
Abi::ScalarPair(ref a, ref b) => (a, b),
294274
_ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self),
@@ -367,8 +347,8 @@ impl<'gcc, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
367347
layout.gcc_field_index(index)
368348
}
369349

370-
fn scalar_pair_element_backend_type(&self, layout: TyAndLayout<'tcx>, index: usize, immediate: bool) -> Type<'gcc> {
371-
layout.scalar_pair_element_gcc_type(self, index, immediate)
350+
fn scalar_pair_element_backend_type(&self, layout: TyAndLayout<'tcx>, index: usize, _immediate: bool) -> Type<'gcc> {
351+
layout.scalar_pair_element_gcc_type(self, index)
372352
}
373353

374354
fn cast_backend_type(&self, ty: &CastTarget) -> Type<'gcc> {

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ impl From<Conv> for llvm::CallConv {
571571
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall | Conv::RiscvInterrupt { .. } => {
572572
llvm::CCallConv
573573
}
574-
Conv::RustCold => llvm::ColdCallConv,
574+
Conv::Cold => llvm::ColdCallConv,
575+
Conv::PreserveMost => llvm::PreserveMost,
576+
Conv::PreserveAll => llvm::PreserveAll,
575577
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
576578
Conv::AvrInterrupt => llvm::AvrInterrupt,
577579
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
2020
cx: &CodegenCx<'ll, 'tcx>,
2121
instance: Instance<'tcx>,
2222
mir: &Body<'tcx>,
23-
debug_context: &mut FunctionDebugContext<'tcx, &'ll DIScope, &'ll DILocation>,
23+
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
2424
) {
2525
// Find all scopes with variables defined in them.
2626
let variables = if cx.sess().opts.debuginfo == DebugInfo::Full {
@@ -51,7 +51,7 @@ fn make_mir_scope<'ll, 'tcx>(
5151
instance: Instance<'tcx>,
5252
mir: &Body<'tcx>,
5353
variables: &Option<BitSet<SourceScope>>,
54-
debug_context: &mut FunctionDebugContext<'tcx, &'ll DIScope, &'ll DILocation>,
54+
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
5555
instantiated: &mut BitSet<SourceScope>,
5656
scope: SourceScope,
5757
) {
@@ -84,6 +84,7 @@ fn make_mir_scope<'ll, 'tcx>(
8484
}
8585

8686
let loc = cx.lookup_debug_loc(scope_data.span.lo());
87+
let file_metadata = file_metadata(cx, &loc.file);
8788

8889
let dbg_scope = match scope_data.inlined {
8990
Some((callee, _)) => {
@@ -94,26 +95,18 @@ fn make_mir_scope<'ll, 'tcx>(
9495
ty::ParamEnv::reveal_all(),
9596
ty::EarlyBinder::bind(callee),
9697
);
97-
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {
98-
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
99-
cx.dbg_scope_fn(callee, callee_fn_abi, None)
100-
})
101-
}
102-
None => {
103-
let file_metadata = file_metadata(cx, &loc.file);
104-
debug_context
105-
.lexical_blocks
106-
.entry((parent_scope.dbg_scope, loc.line, loc.col, file_metadata))
107-
.or_insert_with(|| unsafe {
108-
llvm::LLVMRustDIBuilderCreateLexicalBlock(
109-
DIB(cx),
110-
parent_scope.dbg_scope,
111-
file_metadata,
112-
loc.line,
113-
loc.col,
114-
)
115-
})
98+
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
99+
cx.dbg_scope_fn(callee, callee_fn_abi, None)
116100
}
101+
None => unsafe {
102+
llvm::LLVMRustDIBuilderCreateLexicalBlock(
103+
DIB(cx),
104+
parent_scope.dbg_scope,
105+
file_metadata,
106+
loc.line,
107+
loc.col,
108+
)
109+
},
117110
};
118111

119112
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {

0 commit comments

Comments
 (0)