Skip to content

Commit 6318e9d

Browse files
committed
Auto merge of #3202 - rust-lang:rustup-2023-12-03, r=saethlin
Automatic Rustup
2 parents 33515d7 + 3a6753b commit 6318e9d

File tree

561 files changed

+6457
-2472
lines changed

Some content is hidden

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

561 files changed

+6457
-2472
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,18 @@ pub enum InlineAsmOperand {
22512251
},
22522252
}
22532253

2254+
impl InlineAsmOperand {
2255+
pub fn reg(&self) -> Option<&InlineAsmRegOrRegClass> {
2256+
match self {
2257+
Self::In { reg, .. }
2258+
| Self::Out { reg, .. }
2259+
| Self::InOut { reg, .. }
2260+
| Self::SplitInOut { reg, .. } => Some(reg),
2261+
Self::Const { .. } | Self::Sym { .. } => None,
2262+
}
2263+
}
2264+
}
2265+
22542266
/// Inline assembly.
22552267
///
22562268
/// E.g., `asm!("NOP");`.

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -342,61 +342,75 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
342342

343343
// Flag to output the error only once per operand
344344
let mut skip = false;
345-
reg.overlapping_regs(|r| {
346-
let mut check = |used_regs: &mut FxHashMap<asm::InlineAsmReg, usize>,
347-
input| {
348-
match used_regs.entry(r) {
349-
Entry::Occupied(o) => {
350-
if skip {
351-
return;
352-
}
353-
skip = true;
354345

355-
let idx2 = *o.get();
356-
let (ref op2, op_sp2) = operands[idx2];
357-
let Some(asm::InlineAsmRegOrRegClass::Reg(reg2)) = op2.reg()
358-
else {
359-
unreachable!();
360-
};
346+
let mut check = |used_regs: &mut FxHashMap<asm::InlineAsmReg, usize>,
347+
input,
348+
r: asm::InlineAsmReg| {
349+
match used_regs.entry(r) {
350+
Entry::Occupied(o) => {
351+
if skip {
352+
return;
353+
}
354+
skip = true;
361355

362-
let in_out = match (op, op2) {
363-
(
364-
hir::InlineAsmOperand::In { .. },
365-
hir::InlineAsmOperand::Out { late, .. },
366-
)
367-
| (
368-
hir::InlineAsmOperand::Out { late, .. },
369-
hir::InlineAsmOperand::In { .. },
370-
) => {
371-
assert!(!*late);
372-
let out_op_sp = if input { op_sp2 } else { op_sp };
373-
Some(out_op_sp)
374-
}
375-
_ => None,
376-
};
356+
let idx2 = *o.get();
357+
let (ref op2, op_sp2) = operands[idx2];
377358

378-
sess.emit_err(RegisterConflict {
379-
op_span1: op_sp,
380-
op_span2: op_sp2,
381-
reg1_name: reg.name(),
382-
reg2_name: reg2.name(),
383-
in_out,
384-
});
385-
}
386-
Entry::Vacant(v) => {
387-
if r == reg {
388-
v.insert(idx);
359+
let in_out = match (op, op2) {
360+
(
361+
hir::InlineAsmOperand::In { .. },
362+
hir::InlineAsmOperand::Out { late, .. },
363+
)
364+
| (
365+
hir::InlineAsmOperand::Out { late, .. },
366+
hir::InlineAsmOperand::In { .. },
367+
) => {
368+
assert!(!*late);
369+
let out_op_sp = if input { op_sp2 } else { op_sp };
370+
Some(out_op_sp)
371+
}
372+
_ => None,
373+
};
374+
let reg_str = |idx| -> &str {
375+
// HIR asm doesn't preserve the original alias string of the explicit register,
376+
// so we have to retrieve it from AST
377+
let (op, _): &(InlineAsmOperand, Span) = &asm.operands[idx];
378+
if let Some(ast::InlineAsmRegOrRegClass::Reg(reg_sym)) =
379+
op.reg()
380+
{
381+
reg_sym.as_str()
382+
} else {
383+
unreachable!();
389384
}
385+
};
386+
387+
sess.emit_err(RegisterConflict {
388+
op_span1: op_sp,
389+
op_span2: op_sp2,
390+
reg1_name: reg_str(idx),
391+
reg2_name: reg_str(idx2),
392+
in_out,
393+
});
394+
}
395+
Entry::Vacant(v) => {
396+
if r == reg {
397+
v.insert(idx);
390398
}
391399
}
392-
};
400+
}
401+
};
402+
let mut overlapping_with = vec![];
403+
reg.overlapping_regs(|r| {
404+
overlapping_with.push(r);
405+
});
406+
for r in overlapping_with {
393407
if input {
394-
check(&mut used_input_regs, true);
408+
check(&mut used_input_regs, true, r);
395409
}
396410
if output {
397-
check(&mut used_output_regs, false);
411+
check(&mut used_output_regs, false, r);
398412
}
399-
});
413+
}
400414
}
401415
}
402416
}
@@ -411,12 +425,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
411425
continue;
412426
}
413427

414-
let mut output_used = false;
428+
let mut overlapping_with = vec![];
415429
clobber.overlapping_regs(|reg| {
416-
if used_output_regs.contains_key(&reg) {
417-
output_used = true;
418-
}
430+
overlapping_with.push(reg);
419431
});
432+
let output_used =
433+
overlapping_with.iter().any(|reg| used_output_regs.contains_key(&reg));
420434

421435
if !output_used {
422436
operands.push((

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,9 +1799,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17991799
.iter()
18001800
.find(|cand| self.matches_by_doc_alias(cand.def_id))
18011801
.map(|cand| cand.name)
1802-
})
1803-
.unwrap();
1804-
Ok(applicable_close_candidates.into_iter().find(|method| method.name == best_name))
1802+
});
1803+
Ok(best_name.and_then(|best_name| {
1804+
applicable_close_candidates.into_iter().find(|method| method.name == best_name)
1805+
}))
18051806
}
18061807
})
18071808
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,16 @@ impl<'tcx> Const<'tcx> {
304304
let (param_env, unevaluated) = unevaluated.prepare_for_eval(tcx, param_env);
305305
// try to resolve e.g. associated constants to their definition on an impl, and then
306306
// evaluate the const.
307-
let c = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?;
308-
Ok(c.expect("`ty::Const::eval` called on a non-valtree-compatible type"))
307+
let Some(c) = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?
308+
else {
309+
// This can happen when we run on ill-typed code.
310+
let e = tcx.sess.span_delayed_bug(
311+
span.unwrap_or(DUMMY_SP),
312+
"`ty::Const::eval` called on a non-valtree-compatible type",
313+
);
314+
return Err(e.into());
315+
};
316+
Ok(c)
309317
}
310318
ConstKind::Value(val) => Ok(val),
311319
ConstKind::Error(g) => Err(g.into()),

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::errors::{
1818
UnexpectedConstParamDeclaration, UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets,
1919
UseEqInstead, WrapType,
2020
};
21-
2221
use crate::fluent_generated as fluent;
2322
use crate::parser;
2423
use crate::parser::attr::InnerAttrPolicy;
@@ -772,8 +771,10 @@ impl<'a> Parser<'a> {
772771
&& let ast::AttrKind::Normal(attr_kind) = &attr.kind
773772
&& let [segment] = &attr_kind.item.path.segments[..]
774773
&& segment.ident.name == sym::cfg
774+
&& let Some(args_span) = attr_kind.item.args.span()
775775
&& let Ok(next_attr) = snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
776776
&& let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind
777+
&& let Some(next_attr_args_span) = next_attr_kind.item.args.span()
777778
&& let [next_segment] = &next_attr_kind.item.path.segments[..]
778779
&& segment.ident.name == sym::cfg
779780
&& let Ok(next_expr) = snapshot.parse_expr()
@@ -787,23 +788,14 @@ impl<'a> Parser<'a> {
787788
let margin = self.sess.source_map().span_to_margin(next_expr.span).unwrap_or(0);
788789
let sugg = vec![
789790
(attr.span.with_hi(segment.span().hi()), "if cfg!".to_string()),
790-
(
791-
attr_kind.item.args.span().unwrap().shrink_to_hi().with_hi(attr.span.hi()),
792-
" {".to_string(),
793-
),
791+
(args_span.shrink_to_hi().with_hi(attr.span.hi()), " {".to_string()),
794792
(expr.span.shrink_to_lo(), " ".to_string()),
795793
(
796794
next_attr.span.with_hi(next_segment.span().hi()),
797795
"} else if cfg!".to_string(),
798796
),
799797
(
800-
next_attr_kind
801-
.item
802-
.args
803-
.span()
804-
.unwrap()
805-
.shrink_to_hi()
806-
.with_hi(next_attr.span.hi()),
798+
next_attr_args_span.shrink_to_hi().with_hi(next_attr.span.hi()),
807799
" {".to_string(),
808800
),
809801
(next_expr.span.shrink_to_lo(), " ".to_string()),

compiler/rustc_smir/src/rustc_smir/context.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This trait is currently the main interface between the Rust compiler,
44
//! and the `stable_mir` crate.
55
6+
use rustc_middle::ty;
67
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
78
use rustc_middle::ty::{GenericPredicates, Instance, ParamEnv, ScalarInt, ValTree};
89
use rustc_span::def_id::LOCAL_CRATE;
@@ -12,9 +13,9 @@ use stable_mir::mir::mono::{InstanceDef, StaticDef};
1213
use stable_mir::mir::Body;
1314
use stable_mir::ty::{
1415
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs, LineInfo,
15-
RigidTy, Span, TyKind,
16+
PolyFnSig, RigidTy, Span, TyKind,
1617
};
17-
use stable_mir::{self, Crate, CrateItem, Error, Filename, ItemKind, Symbol};
18+
use stable_mir::{self, Crate, CrateItem, DefId, Error, Filename, ItemKind, Symbol};
1819
use std::cell::RefCell;
1920

2021
use crate::rustc_internal::{internal, RustcInternal};
@@ -39,6 +40,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
3940
tables.tcx.instance_mir(rustc_middle::ty::InstanceDef::Item(def_id)).stable(&mut tables)
4041
}
4142

43+
fn has_body(&self, def: DefId) -> bool {
44+
let tables = self.0.borrow();
45+
let def_id = tables[def];
46+
tables.tcx.is_mir_available(def_id)
47+
}
48+
4249
fn all_trait_decls(&self) -> stable_mir::TraitDecls {
4350
let mut tables = self.0.borrow_mut();
4451
tables
@@ -195,6 +202,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
195202
def.internal(&mut *tables).is_box()
196203
}
197204

205+
fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig {
206+
let mut tables = self.0.borrow_mut();
207+
let def_id = def.0.internal(&mut *tables);
208+
let sig = tables.tcx.fn_sig(def_id).instantiate(tables.tcx, args.internal(&mut *tables));
209+
sig.stable(&mut *tables)
210+
}
211+
198212
fn eval_target_usize(&self, cnst: &Const) -> Result<u64, Error> {
199213
let mut tables = self.0.borrow_mut();
200214
let mir_const = cnst.internal(&mut *tables);
@@ -266,6 +280,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
266280
tables.tcx.symbol_name(instance).name.to_string()
267281
}
268282

283+
fn is_empty_drop_shim(&self, def: InstanceDef) -> bool {
284+
let tables = self.0.borrow_mut();
285+
let instance = tables.instances[def];
286+
matches!(instance.def, ty::InstanceDef::DropGlue(_, None))
287+
}
288+
269289
fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
270290
let mut tables = self.0.borrow_mut();
271291
let def_id = tables[item.0];

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
777777
let kind = match self.def {
778778
ty::InstanceDef::Item(..) => stable_mir::mir::mono::InstanceKind::Item,
779779
ty::InstanceDef::Intrinsic(..) => stable_mir::mir::mono::InstanceKind::Intrinsic,
780-
ty::InstanceDef::Virtual(..) => stable_mir::mir::mono::InstanceKind::Virtual,
780+
ty::InstanceDef::Virtual(_def_id, idx) => {
781+
stable_mir::mir::mono::InstanceKind::Virtual { idx }
782+
}
781783
ty::InstanceDef::VTableShim(..)
782784
| ty::InstanceDef::ReifyShim(..)
783785
| ty::InstanceDef::FnPtrAddrShim(..)

compiler/stable_mir/src/compiler_interface.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::mir::mono::{Instance, InstanceDef, StaticDef};
1010
use crate::mir::Body;
1111
use crate::ty::{
1212
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs,
13-
GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, RigidTy, Span, TraitDecl, TraitDef,
14-
Ty, TyKind,
13+
GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, PolyFnSig, RigidTy, Span, TraitDecl,
14+
TraitDef, Ty, TyKind,
1515
};
1616
use crate::{
1717
mir, Crate, CrateItem, CrateItems, DefId, Error, Filename, ImplTraitDecls, ItemKind, Symbol,
@@ -24,7 +24,11 @@ pub trait Context {
2424
fn entry_fn(&self) -> Option<CrateItem>;
2525
/// Retrieve all items of the local crate that have a MIR associated with them.
2626
fn all_local_items(&self) -> CrateItems;
27+
/// Retrieve the body of a function.
28+
/// This function will panic if the body is not available.
2729
fn mir_body(&self, item: DefId) -> mir::Body;
30+
/// Check whether the body of a function is available.
31+
fn has_body(&self, item: DefId) -> bool;
2832
fn all_trait_decls(&self) -> TraitDecls;
2933
fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl;
3034
fn all_trait_impls(&self) -> ImplTraitDecls;
@@ -64,6 +68,9 @@ pub trait Context {
6468
/// Returns if the ADT is a box.
6569
fn adt_is_box(&self, def: AdtDef) -> bool;
6670

71+
/// Retrieve the function signature for the given generic arguments.
72+
fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig;
73+
6774
/// Evaluate constant as a target usize.
6875
fn eval_target_usize(&self, cnst: &Const) -> Result<u64, Error>;
6976

@@ -85,8 +92,7 @@ pub trait Context {
8592
/// Obtain the representation of a type.
8693
fn ty_kind(&self, ty: Ty) -> TyKind;
8794

88-
/// Get the body of an Instance.
89-
/// FIXME: Monomorphize the body.
95+
/// Get the body of an Instance which is already monomorphized.
9096
fn instance_body(&self, instance: InstanceDef) -> Option<Body>;
9197

9298
/// Get the instance type with generic substitutions applied and lifetimes erased.
@@ -98,6 +104,9 @@ pub trait Context {
98104
/// Get the instance mangled name.
99105
fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol;
100106

107+
/// Check if this is an empty DropGlue shim.
108+
fn is_empty_drop_shim(&self, def: InstanceDef) -> bool;
109+
101110
/// Convert a non-generic crate item into an instance.
102111
/// This function will panic if the item is generic.
103112
fn mono_instance(&self, item: CrateItem) -> Instance;

0 commit comments

Comments
 (0)