Skip to content

Commit

Permalink
Auto merge of #18183 - lnicola:sync-from-rust, r=lnicola
Browse files Browse the repository at this point in the history
internal: Sync from downstream
  • Loading branch information
bors committed Sep 25, 2024
2 parents 82b2d07 + f4bcae3 commit 7ab2c17
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 56 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.63.0", default-features = false }
ra-ap-rustc_parse_format = { version = "0.63.0", default-features = false }
ra-ap-rustc_index = { version = "0.63.0", default-features = false }
ra-ap-rustc_abi = { version = "0.63.0", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.63.0", default-features = false }
ra-ap-rustc_lexer = { version = "0.68.0", default-features = false }
ra-ap-rustc_parse_format = { version = "0.68.0", default-features = false }
ra-ap-rustc_index = { version = "0.68.0", default-features = false }
ra-ap-rustc_abi = { version = "0.68.0", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.68.0", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
Expand Down
3 changes: 3 additions & 0 deletions crates/hir-expand/src/inert_attr_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
// Used by the `rustc::potential_query_instability` lint to warn methods which
// might not be stable during incremental compilation.
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
// to assist in changes to diagnostic APIs.
rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
Expand Down
70 changes: 39 additions & 31 deletions crates/hir-ty/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
//! Compute the binary representation of a type
use std::{borrow::Cow, fmt};
use std::fmt;

use base_db::salsa::Cycle;
use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy};
use hir_def::{
layout::{
Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutS, Primitive, ReprOptions,
Scalar, Size, StructKind, TargetDataLayout, WrappingRange,
Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutS,
Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange,
},
LocalFieldId, StructId,
};
use la_arena::{Idx, RawIdx};
use rustc_abi::AddressSpace;
use rustc_index::{IndexSlice, IndexVec};

use stdx::never;
use triomphe::Arc;

use crate::{
Expand Down Expand Up @@ -73,6 +72,7 @@ pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum LayoutError {
EmptyUnion,
HasErrorConst,
HasErrorType,
HasPlaceholder,
Expand All @@ -81,6 +81,7 @@ pub enum LayoutError {
RecursiveTypeWithoutIndirection,
SizeOverflow,
TargetLayoutNotAvailable,
UnexpectedUnsized,
Unknown,
UserReprTooSmall,
}
Expand All @@ -89,6 +90,7 @@ impl std::error::Error for LayoutError {}
impl fmt::Display for LayoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LayoutError::EmptyUnion => write!(f, "type is an union with no fields"),
LayoutError::HasErrorConst => write!(f, "type contains an unevaluatable const"),
LayoutError::HasErrorType => write!(f, "type contains an error"),
LayoutError::HasPlaceholder => write!(f, "type contains placeholders"),
Expand All @@ -99,6 +101,9 @@ impl fmt::Display for LayoutError {
}
LayoutError::SizeOverflow => write!(f, "size overflow"),
LayoutError::TargetLayoutNotAvailable => write!(f, "target layout not available"),
LayoutError::UnexpectedUnsized => {
write!(f, "an unsized type was found where a sized type was expected")
}
LayoutError::Unknown => write!(f, "unknown"),
LayoutError::UserReprTooSmall => {
write!(f, "the `#[repr]` hint is too small to hold the discriminants of the enum")
Expand All @@ -107,19 +112,23 @@ impl fmt::Display for LayoutError {
}
}

struct LayoutCx<'a> {
target: &'a TargetDataLayout,
impl<F> From<LayoutCalculatorError<F>> for LayoutError {
fn from(err: LayoutCalculatorError<F>) -> Self {
match err {
LayoutCalculatorError::EmptyUnion => LayoutError::EmptyUnion,
LayoutCalculatorError::UnexpectedUnsized(_) => LayoutError::UnexpectedUnsized,
LayoutCalculatorError::SizeOverflow => LayoutError::SizeOverflow,
}
}
}

impl<'a> LayoutCalculator for LayoutCx<'a> {
type TargetDataLayoutRef = &'a TargetDataLayout;

fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
never!("{}", txt.into());
}
struct LayoutCx<'a> {
calc: LayoutCalculator<&'a TargetDataLayout>,
}

fn current_data_layout(&self) -> &'a TargetDataLayout {
self.target
impl<'a> LayoutCx<'a> {
fn new(target: &'a TargetDataLayout) -> Self {
Self { calc: LayoutCalculator::new(target) }
}
}

Expand Down Expand Up @@ -205,8 +214,8 @@ pub fn layout_of_ty_query(
let Ok(target) = db.target_data_layout(krate) else {
return Err(LayoutError::TargetLayoutNotAvailable);
};
let cx = LayoutCx { target: &target };
let dl = cx.current_data_layout();
let dl = &*target;
let cx = LayoutCx::new(dl);
let ty = normalize(db, trait_env.clone(), ty);
let result = match ty.kind(Interner) {
TyKind::Adt(AdtId(def), subst) => {
Expand Down Expand Up @@ -281,7 +290,7 @@ pub fn layout_of_ty_query(
.collect::<Result<Vec<_>, _>>()?;
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
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) => {
let count = try_const_usize(db, count).ok_or(LayoutError::HasErrorConst)? as u64;
Expand Down Expand Up @@ -367,12 +376,12 @@ pub fn layout_of_ty_query(
};

// 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::Never => cx.layout_of_never_type(),
TyKind::FnDef(_, _) => layout_of_unit(&cx)?,
TyKind::Never => cx.calc.layout_of_never_type(),
TyKind::Dyn(_) | TyKind::Foreign(_) => {
let mut unit = layout_of_unit(&cx, dl)?;
let mut unit = layout_of_unit(&cx)?;
match &mut unit.abi {
Abi::Aggregate { sized } => *sized = false,
_ => return Err(LayoutError::Unknown),
Expand Down Expand Up @@ -414,8 +423,7 @@ pub fn layout_of_ty_query(
.collect::<Result<Vec<_>, _>>()?;
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
let fields = fields.iter().collect::<IndexVec<_, _>>();
cx.univariant(dl, &fields, &ReprOptions::default(), StructKind::AlwaysSized)
.ok_or(LayoutError::Unknown)?
cx.calc.univariant(&fields, &ReprOptions::default(), StructKind::AlwaysSized)?
}
TyKind::Coroutine(_, _) | TyKind::CoroutineWitness(_, _) => {
return Err(LayoutError::NotImplemented)
Expand Down Expand Up @@ -447,14 +455,14 @@ pub fn layout_of_ty_recover(
Err(LayoutError::RecursiveTypeWithoutIndirection)
}

fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, LayoutError> {
cx.univariant::<RustcFieldIdx, RustcEnumVariantIdx, &&Layout>(
dl,
IndexSlice::empty(),
&ReprOptions::default(),
StructKind::AlwaysSized,
)
.ok_or(LayoutError::Unknown)
fn layout_of_unit(cx: &LayoutCx<'_>) -> Result<Layout, LayoutError> {
cx.calc
.univariant::<RustcFieldIdx, RustcEnumVariantIdx, &&Layout>(
IndexSlice::empty(),
&ReprOptions::default(),
StructKind::AlwaysSized,
)
.map_err(Into::into)
}

fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {
Expand Down
13 changes: 6 additions & 7 deletions crates/hir-ty/src/layout/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{cmp, ops::Bound};
use base_db::salsa::Cycle;
use hir_def::{
data::adt::VariantData,
layout::{Integer, LayoutCalculator, ReprOptions, TargetDataLayout},
layout::{Integer, ReprOptions, TargetDataLayout},
AdtId, VariantId,
};
use intern::sym;
Expand Down Expand Up @@ -36,8 +36,8 @@ pub fn layout_of_adt_query(
let Ok(target) = db.target_data_layout(krate) else {
return Err(LayoutError::TargetLayoutNotAvailable);
};
let cx = LayoutCx { target: &target };
let dl = cx.current_data_layout();
let dl = &*target;
let cx = LayoutCx::new(dl);
let handle_variant = |def: VariantId, var: &VariantData| {
var.fields()
.iter()
Expand Down Expand Up @@ -73,9 +73,9 @@ pub fn layout_of_adt_query(
.collect::<SmallVec<[_; 1]>>();
let variants = variants.iter().map(|it| it.iter().collect()).collect::<IndexVec<_, _>>();
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 {
cx.layout_of_struct_or_enum(
cx.calc.layout_of_struct_or_enum(
&repr,
&variants,
matches!(def, AdtId::EnumId(..)),
Expand Down Expand Up @@ -103,8 +103,7 @@ pub fn layout_of_adt_query(
.next()
.and_then(|it| it.iter().last().map(|it| !it.is_unsized()))
.unwrap_or(true),
)
.ok_or(LayoutError::SizeOverflow)?
)?
};
Ok(Arc::new(result))
}
Expand Down
3 changes: 3 additions & 0 deletions crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub enum FnAbi {
AvrNonBlockingInterrupt,
C,
CCmseNonsecureCall,
CCmseNonsecureEntry,
CDecl,
CDeclUnwind,
CUnwind,
Expand Down Expand Up @@ -436,6 +437,7 @@ impl FnAbi {
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::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 => FnAbi::C,
s if *s == sym::cdecl_dash_unwind => FnAbi::CDeclUnwind,
Expand Down Expand Up @@ -479,6 +481,7 @@ impl FnAbi {
FnAbi::AvrNonBlockingInterrupt => "avr-non-blocking-interrupt",
FnAbi::C => "C",
FnAbi::CCmseNonsecureCall => "C-cmse-nonsecure-call",
FnAbi::CCmseNonsecureEntry => "C-cmse-nonsecure-entry",
FnAbi::CDecl => "C-decl",
FnAbi::CDeclUnwind => "cdecl-unwind",
FnAbi::CUnwind => "C-unwind",
Expand Down
1 change: 1 addition & 0 deletions crates/ide-completion/src/completions/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
"riscv-interrupt-m",
"riscv-interrupt-s",
"C-cmse-nonsecure-call",
"C-cmse-nonsecure-entry",
"wasm",
"system",
"system-unwind",
Expand Down
1 change: 1 addition & 0 deletions crates/intern/src/symbol/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ define_symbols! {
avr_dash_interrupt = "avr-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_entry = "C-cmse-nonsecure-entry",
C_dash_unwind = "C-unwind",
cdecl_dash_unwind = "cdecl-unwind",
fastcall_dash_unwind = "fastcall-unwind",
Expand Down
5 changes: 5 additions & 0 deletions crates/parser/src/lexed_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ impl<'a> Converter<'a> {
}
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::Comma => T![,],
Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6cf068db566de080dfa7ed24a216ea3aed2b98ce
1b5aa96d6016bafe50e071b45d4d2e3c90fd766f

0 comments on commit 7ab2c17

Please sign in to comment.