Merge from rust-lang/rust

This commit is contained in:
Laurențiu Nicola 2024-09-25 09:00:53 +03:00
commit 37f7190b3e
7 changed files with 55 additions and 38 deletions

View file

@ -464,6 +464,9 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
// Used by the `rustc::potential_query_instability` lint to warn methods which // Used by the `rustc::potential_query_instability` lint to warn methods which
// might not be stable during incremental compilation. // might not be stable during incremental compilation.
rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE), rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
// Used by the `rustc::untracked_query_information` lint to warn methods which
// might break incremental compilation.
rustc_attr!(rustc_lint_untracked_query_information, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
// Used by the `rustc::untranslatable_diagnostic` and `rustc::diagnostic_outside_of_impl` lints // Used by the `rustc::untranslatable_diagnostic` and `rustc::diagnostic_outside_of_impl` lints
// to assist in changes to diagnostic APIs. // to assist in changes to diagnostic APIs.
rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE), rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),

View file

@ -1,13 +1,13 @@
//! Compute the binary representation of a type //! Compute the binary representation of a type
use std::{borrow::Cow, fmt}; use std::fmt;
use base_db::salsa::Cycle; use base_db::salsa::Cycle;
use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy}; use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy};
use hir_def::{ use hir_def::{
layout::{ layout::{
Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutS, Primitive, ReprOptions, Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutS,
Scalar, Size, StructKind, TargetDataLayout, WrappingRange, Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange,
}, },
LocalFieldId, StructId, LocalFieldId, StructId,
}; };
@ -15,7 +15,6 @@ use la_arena::{Idx, RawIdx};
use rustc_abi::AddressSpace; use rustc_abi::AddressSpace;
use rustc_index::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use stdx::never;
use triomphe::Arc; use triomphe::Arc;
use crate::{ use crate::{
@ -107,19 +106,24 @@ impl fmt::Display for LayoutError {
} }
} }
struct LayoutCx<'a> { impl<F> From<LayoutCalculatorError<F>> for LayoutError {
target: &'a TargetDataLayout, fn from(err: LayoutCalculatorError<F>) -> Self {
match err {
LayoutCalculatorError::UnexpectedUnsized(_) | LayoutCalculatorError::EmptyUnion => {
LayoutError::Unknown
}
LayoutCalculatorError::SizeOverflow => LayoutError::SizeOverflow,
}
}
} }
impl<'a> LayoutCalculator for LayoutCx<'a> { struct LayoutCx<'a> {
type TargetDataLayoutRef = &'a TargetDataLayout; calc: LayoutCalculator<&'a TargetDataLayout>,
}
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) { impl<'a> LayoutCx<'a> {
never!("{}", txt.into()); fn new(target: &'a TargetDataLayout) -> Self {
} Self { calc: LayoutCalculator::new(target) }
fn current_data_layout(&self) -> &'a TargetDataLayout {
self.target
} }
} }
@ -205,8 +209,8 @@ pub fn layout_of_ty_query(
let Ok(target) = db.target_data_layout(krate) else { let Ok(target) = db.target_data_layout(krate) else {
return Err(LayoutError::TargetLayoutNotAvailable); return Err(LayoutError::TargetLayoutNotAvailable);
}; };
let cx = LayoutCx { target: &target }; let dl = &*target;
let dl = cx.current_data_layout(); let cx = LayoutCx::new(dl);
let ty = normalize(db, trait_env.clone(), ty); let ty = normalize(db, trait_env.clone(), ty);
let result = match ty.kind(Interner) { let result = match ty.kind(Interner) {
TyKind::Adt(AdtId(def), subst) => { TyKind::Adt(AdtId(def), subst) => {
@ -281,7 +285,7 @@ pub fn layout_of_ty_query(
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>(); let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
let fields = fields.iter().collect::<IndexVec<_, _>>(); let fields = fields.iter().collect::<IndexVec<_, _>>();
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)? cx.calc.univariant(&fields, &ReprOptions::default(), kind)?
} }
TyKind::Array(element, count) => { TyKind::Array(element, count) => {
let count = try_const_usize(db, count).ok_or(LayoutError::HasErrorConst)? as u64; let count = try_const_usize(db, count).ok_or(LayoutError::HasErrorConst)? as u64;
@ -367,12 +371,12 @@ pub fn layout_of_ty_query(
}; };
// Effectively a (ptr, meta) tuple. // Effectively a (ptr, meta) tuple.
cx.scalar_pair(data_ptr, metadata) cx.calc.scalar_pair(data_ptr, metadata)
} }
TyKind::FnDef(_, _) => layout_of_unit(&cx, dl)?, TyKind::FnDef(_, _) => layout_of_unit(&cx)?,
TyKind::Never => cx.layout_of_never_type(), TyKind::Never => cx.calc.layout_of_never_type(),
TyKind::Dyn(_) | TyKind::Foreign(_) => { TyKind::Dyn(_) | TyKind::Foreign(_) => {
let mut unit = layout_of_unit(&cx, dl)?; let mut unit = layout_of_unit(&cx)?;
match &mut unit.abi { match &mut unit.abi {
Abi::Aggregate { sized } => *sized = false, Abi::Aggregate { sized } => *sized = false,
_ => return Err(LayoutError::Unknown), _ => return Err(LayoutError::Unknown),
@ -414,8 +418,7 @@ pub fn layout_of_ty_query(
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>(); let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
let fields = fields.iter().collect::<IndexVec<_, _>>(); let fields = fields.iter().collect::<IndexVec<_, _>>();
cx.univariant(dl, &fields, &ReprOptions::default(), StructKind::AlwaysSized) cx.calc.univariant(&fields, &ReprOptions::default(), StructKind::AlwaysSized)?
.ok_or(LayoutError::Unknown)?
} }
TyKind::Coroutine(_, _) | TyKind::CoroutineWitness(_, _) => { TyKind::Coroutine(_, _) | TyKind::CoroutineWitness(_, _) => {
return Err(LayoutError::NotImplemented) return Err(LayoutError::NotImplemented)
@ -447,14 +450,14 @@ pub fn layout_of_ty_recover(
Err(LayoutError::RecursiveTypeWithoutIndirection) Err(LayoutError::RecursiveTypeWithoutIndirection)
} }
fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, LayoutError> { fn layout_of_unit(cx: &LayoutCx<'_>) -> Result<Layout, LayoutError> {
cx.univariant::<RustcFieldIdx, RustcEnumVariantIdx, &&Layout>( cx.calc
dl, .univariant::<RustcFieldIdx, RustcEnumVariantIdx, &&Layout>(
IndexSlice::empty(), IndexSlice::empty(),
&ReprOptions::default(), &ReprOptions::default(),
StructKind::AlwaysSized, StructKind::AlwaysSized,
) )
.ok_or(LayoutError::Unknown) .map_err(Into::into)
} }
fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty { fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {

View file

@ -5,7 +5,7 @@ use std::{cmp, ops::Bound};
use base_db::salsa::Cycle; use base_db::salsa::Cycle;
use hir_def::{ use hir_def::{
data::adt::VariantData, data::adt::VariantData,
layout::{Integer, LayoutCalculator, ReprOptions, TargetDataLayout}, layout::{Integer, ReprOptions, TargetDataLayout},
AdtId, VariantId, AdtId, VariantId,
}; };
use intern::sym; use intern::sym;
@ -36,8 +36,8 @@ pub fn layout_of_adt_query(
let Ok(target) = db.target_data_layout(krate) else { let Ok(target) = db.target_data_layout(krate) else {
return Err(LayoutError::TargetLayoutNotAvailable); return Err(LayoutError::TargetLayoutNotAvailable);
}; };
let cx = LayoutCx { target: &target }; let dl = &*target;
let dl = cx.current_data_layout(); let cx = LayoutCx::new(dl);
let handle_variant = |def: VariantId, var: &VariantData| { let handle_variant = |def: VariantId, var: &VariantData| {
var.fields() var.fields()
.iter() .iter()
@ -73,9 +73,9 @@ pub fn layout_of_adt_query(
.collect::<SmallVec<[_; 1]>>(); .collect::<SmallVec<[_; 1]>>();
let variants = variants.iter().map(|it| it.iter().collect()).collect::<IndexVec<_, _>>(); let variants = variants.iter().map(|it| it.iter().collect()).collect::<IndexVec<_, _>>();
let result = if matches!(def, AdtId::UnionId(..)) { let result = if matches!(def, AdtId::UnionId(..)) {
cx.layout_of_union(&repr, &variants).ok_or(LayoutError::Unknown)? cx.calc.layout_of_union(&repr, &variants)?
} else { } else {
cx.layout_of_struct_or_enum( cx.calc.layout_of_struct_or_enum(
&repr, &repr,
&variants, &variants,
matches!(def, AdtId::EnumId(..)), matches!(def, AdtId::EnumId(..)),
@ -103,8 +103,7 @@ pub fn layout_of_adt_query(
.next() .next()
.and_then(|it| it.iter().last().map(|it| !it.is_unsized())) .and_then(|it| it.iter().last().map(|it| !it.is_unsized()))
.unwrap_or(true), .unwrap_or(true),
) )?
.ok_or(LayoutError::SizeOverflow)?
}; };
Ok(Arc::new(result)) Ok(Arc::new(result))
} }

View file

@ -379,6 +379,7 @@ pub enum FnAbi {
AvrNonBlockingInterrupt, AvrNonBlockingInterrupt,
C, C,
CCmseNonsecureCall, CCmseNonsecureCall,
CCmseNonsecureEntry,
CDecl, CDecl,
CDeclUnwind, CDeclUnwind,
CUnwind, CUnwind,
@ -436,6 +437,7 @@ impl FnAbi {
s if *s == sym::avr_dash_interrupt => FnAbi::AvrInterrupt, s if *s == sym::avr_dash_interrupt => FnAbi::AvrInterrupt,
s if *s == sym::avr_dash_non_dash_blocking_dash_interrupt => FnAbi::AvrNonBlockingInterrupt, s if *s == sym::avr_dash_non_dash_blocking_dash_interrupt => FnAbi::AvrNonBlockingInterrupt,
s if *s == sym::C_dash_cmse_dash_nonsecure_dash_call => FnAbi::CCmseNonsecureCall, s if *s == sym::C_dash_cmse_dash_nonsecure_dash_call => FnAbi::CCmseNonsecureCall,
s if *s == sym::C_dash_cmse_dash_nonsecure_dash_entry => FnAbi::CCmseNonsecureEntry,
s if *s == sym::C_dash_unwind => FnAbi::CUnwind, s if *s == sym::C_dash_unwind => FnAbi::CUnwind,
s if *s == sym::C => FnAbi::C, s if *s == sym::C => FnAbi::C,
s if *s == sym::cdecl_dash_unwind => FnAbi::CDeclUnwind, s if *s == sym::cdecl_dash_unwind => FnAbi::CDeclUnwind,
@ -479,6 +481,7 @@ impl FnAbi {
FnAbi::AvrNonBlockingInterrupt => "avr-non-blocking-interrupt", FnAbi::AvrNonBlockingInterrupt => "avr-non-blocking-interrupt",
FnAbi::C => "C", FnAbi::C => "C",
FnAbi::CCmseNonsecureCall => "C-cmse-nonsecure-call", FnAbi::CCmseNonsecureCall => "C-cmse-nonsecure-call",
FnAbi::CCmseNonsecureEntry => "C-cmse-nonsecure-entry",
FnAbi::CDecl => "C-decl", FnAbi::CDecl => "C-decl",
FnAbi::CDeclUnwind => "cdecl-unwind", FnAbi::CDeclUnwind => "cdecl-unwind",
FnAbi::CUnwind => "C-unwind", FnAbi::CUnwind => "C-unwind",

View file

@ -32,6 +32,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
"riscv-interrupt-m", "riscv-interrupt-m",
"riscv-interrupt-s", "riscv-interrupt-s",
"C-cmse-nonsecure-call", "C-cmse-nonsecure-call",
"C-cmse-nonsecure-entry",
"wasm", "wasm",
"system", "system",
"system-unwind", "system-unwind",

View file

@ -94,6 +94,7 @@ define_symbols! {
avr_dash_interrupt = "avr-interrupt", avr_dash_interrupt = "avr-interrupt",
avr_dash_non_dash_blocking_dash_interrupt = "avr-non-blocking-interrupt", avr_dash_non_dash_blocking_dash_interrupt = "avr-non-blocking-interrupt",
C_dash_cmse_dash_nonsecure_dash_call = "C-cmse-nonsecure-call", C_dash_cmse_dash_nonsecure_dash_call = "C-cmse-nonsecure-call",
C_dash_cmse_dash_nonsecure_dash_entry = "C-cmse-nonsecure-entry",
C_dash_unwind = "C-unwind", C_dash_unwind = "C-unwind",
cdecl_dash_unwind = "cdecl-unwind", cdecl_dash_unwind = "cdecl-unwind",
fastcall_dash_unwind = "fastcall-unwind", fastcall_dash_unwind = "fastcall-unwind",

View file

@ -198,6 +198,13 @@ impl<'a> Converter<'a> {
} }
LIFETIME_IDENT LIFETIME_IDENT
} }
rustc_lexer::TokenKind::UnknownPrefixLifetime => {
err = "Unknown lifetime prefix";
LIFETIME_IDENT
}
rustc_lexer::TokenKind::RawLifetime => {
LIFETIME_IDENT
}
rustc_lexer::TokenKind::Semi => T![;], rustc_lexer::TokenKind::Semi => T![;],
rustc_lexer::TokenKind::Comma => T![,], rustc_lexer::TokenKind::Comma => T![,],