Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2282,9 +2282,9 @@ checksum = "803ec87c9cfb29b9d2633f20cba1f488db3fd53f2158b1024cbefb47ba05d413"

[[package]]
name = "libc"
version = "0.2.189"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"

[[package]]
name = "libffi"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl RegionName {
RegionNameHighlight::CannotMatchHirTy(span, type_name),
mir_description,
) => {
diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
diag.span_label(*span, format!("return type{mir_description} is `{type_name}`"));
}
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
diag.span_label(*span, format!("yield type is {type_name}"));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl<'a> TraitDef<'a> {
if self.is_const && cx.ecfg.features.staged_api() {
let rustc_const_unstable = cx.path_name(self.span, sym::rustc_const_unstable);

// #[rustc_const_unstable(feature = "derive_const", issue = "118304")]
// #[rustc_const_unstable(feature = "derive_const", issue = "143874")]
attrs.push(
cx.attr_nested(
rustc_ast::AttrItem {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ declare_features! (
(internal, profiler_runtime, "1.18.0", None),
/// Allows using `rustc_*` attributes (RFC 572).
(internal, rustc_attrs, "1.0.0", None),
/// Allows using internal rustdoc features like `doc(keyword)`.
(internal, rustdoc_internals, "1.58.0", None),
/// Allows using the `#[stable]` and `#[unstable]` attributes.
(internal, staged_api, "1.0.0", None),
/// Perma-unstable, only used in the test suite for binders (`for<'a>`).
Expand Down Expand Up @@ -322,8 +324,6 @@ declare_features! (
(internal, repr_simd, "1.4.0", Some(27731)),
/// Allows using compiler's own crates.
(unstable, rustc_private, "1.0.0", Some(27812)),
/// Allows using internal rustdoc features like `doc(keyword)`.
(internal, rustdoc_internals, "1.58.0", Some(90418)),
/// Allows using the `rustdoc::missing_doc_code_examples` lint
(unstable, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730)),
/// Introduces a hierarchy of `Sized` traits (RFC 3729).
Expand Down Expand Up @@ -666,7 +666,7 @@ declare_features! (
/// Allows providing names to parameters of `impl Fn` etc
(unstable, named_fn_trait_parameters, "1.99.0", Some(158499)),
/// Allows specifying the as-needed link modifier
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(99424)),
/// Allow negative trait implementations.
(unstable, negative_impls, "1.44.0", Some(68318)),
/// Allows the `!` pattern.
Expand Down Expand Up @@ -725,7 +725,7 @@ declare_features! (
/// Allows the use of the `sanitize` attribute.
(unstable, sanitize, "1.91.0", Some(39699)),
/// Allows the use of SIMD types in functions declared in `extern` blocks.
(unstable, simd_ffi, "1.0.0", Some(27731)),
(unstable, simd_ffi, "1.0.0", Some(63068)),
/// Target features on sparc.
(unstable, sparc_target_feature, "1.84.0", Some(132783)),
/// Allows specialization of implementations (RFC 1210).
Expand Down
449 changes: 229 additions & 220 deletions compiler/rustc_metadata/src/rmeta/encoder.rs

Large diffs are not rendered by default.

39 changes: 37 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use rustc_target::spec::{PanicStrategy, TargetTuple};
use table::TableBuilder;

use crate::eii::EiiMapEncodedKeyValue;
use crate::rmeta::parameterized::EncodeFrom;
use crate::rmeta::remapped_def_id::RemappedRawDefId;

mod decoder;
Expand Down Expand Up @@ -570,10 +571,45 @@ macro_rules! define_tables {
}
}
}

impl<'a, 'tcx, 'b> TableWriter<'a, 'tcx, 'b> {
$(
/// Records a value into the corresponding `TableBuilders` field, encoding it in
/// the process when necessary
fn $name1<T>(&mut self, i: LocalDefId, v: T)
where
$T1: EncodeFrom<'tcx, T>
{
let encoded = <$T1 as EncodeFrom<'tcx, T>>::encode_from(self.encoder, v);
let idx = self.encoder.local_defs_remapping.map_local_def_id(i);
self.encoder.tables.$name1.set(idx, encoded);
}
)+
$(
/// Records a value into the corresponding `TableBuilders` field, encoding it in
/// the process when necessary
fn $name2<T>(&mut self, i: LocalDefId, v: T)
where
$T2: EncodeFrom<'tcx, T>
{
let encoded = <$T2 as EncodeFrom<'tcx, T>>::encode_from(self.encoder, v);
let idx = self.encoder.local_defs_remapping.map_local_def_id(i);
self.encoder.tables.$name2.set(idx, Some(encoded));
}
)+
}
}
}

/// Helper struct for writing values into [`TableBuilders`].
#[must_use]
struct TableWriter<'a, 'tcx, 'b> {
encoder: &'b mut EncodeContext<'a, 'tcx>,
}

define_tables! {
// If the compiler complains about `EncodeFrom` or `ParameterizedOverTcx` bounds when calling a
// function generated in this macro, add them to parameterized.rs
- defaulted:
intrinsic: Table<Option<LazyValue<ty::IntrinsicDef>>>,
is_macro_rules: Table<bool>,
Expand All @@ -592,7 +628,6 @@ define_tables! {
explicit_implied_clauses_of: Table<LazyArray<(ty::Clause<'static>, Span)>>,
explicit_implied_const_bounds: Table<LazyArray<(ty::PolyTraitRef<'static>, Span)>>,
inherent_impls: Table<LazyArray<LocalDefId>>,
opt_rpitit_info: Table<Option<LazyValue<ty::ImplTraitInTraitData>>>,
// Reexported names are not associated with individual `DefId`s,
// e.g. a glob import can introduce a lot of names, all with the same `DefId`.
// That's why the encoded list needs to contain `ModChild` structures describing all the names
Expand All @@ -607,6 +642,7 @@ define_tables! {
impl_is_fully_generic_for_reflection: Table<bool>,

- optional:
opt_rpitit_info: Table<LazyValue<ty::ImplTraitInTraitData>>,
attributes: Table<LazyArray<Attribute>>,
// For non-reexported names in a module every name is associated with a separate `DefId`,
// so we can take their names, visibilities etc from other encoded tables.
Expand Down Expand Up @@ -672,7 +708,6 @@ define_tables! {
anon_const_kind: Table<LazyValue<ty::AnonConstKind>>,
const_of_item: Table<LazyValue<Option<ty::EarlyBinder<'static, ty::Const<'static>>>>>,
associated_types_for_impl_traits_in_trait_or_impl: Table<LazyValue<DefIdMap<Vec<DefId>>>>,
live_args_for_alias_from_outlives_bounds: Table<LazyValue<DenseBitSet<u32>>>,
args_known_to_outlive_alias_params: Table<LazyValue<Vec<(usize, DenseBitSet<u32>)>>>,
mut_restriction: Table<LazyValue<ty::RestrictionKind>>,
}
Expand Down
140 changes: 139 additions & 1 deletion compiler/rustc_metadata/src/rmeta/parameterized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use std::hash::Hash;

use rustc_data_structures::unord::UnordMap;
use rustc_index::{Idx, IndexVec};
use rustc_middle::ty::{Binder, EarlyBinder, GenericArg, Region};
use rustc_middle::ty::{Binder, EarlyBinder, GenericArg, Region, Ty};
use rustc_serialize::Encodable;
use rustc_span::Symbol;

use crate::rmeta::encoder::EncodeContext;
use crate::rmeta::{LazyArray, LazyValue, LocalDefId};

pub(crate) trait ParameterizedOverTcx: 'static {
Expand Down Expand Up @@ -176,3 +178,139 @@ parameterized_over_tcx! {
rustc_middle::ty::Ty,
// tidy-alphabetical-end
}

/// Converts values from `TyCtxt` stored form into metadata table stored form
pub(super) trait EncodeFrom<'tcx, T> {
/// When a `T` is trivial to encode, it has a fixed size, no pointers inside, this can be
/// just a no-op. For more complex types this usually creates a `LazyValue<T>` or `LazyArray<T>`
/// encoding `value` with `encoder` in the process
fn encode_from<'a>(encoder: &mut EncodeContext<'a, 'tcx>, value: T) -> Self;
}

macro_rules! trivial_encode_from {
(
$($ty:ty,)+
) => {
$(
impl<'tcx> EncodeFrom<'tcx, $ty> for $ty {
fn encode_from<'a>(
_encoder: &mut EncodeContext<'a, 'tcx>,
value: $ty,
) -> $ty {
value
}
}
)+
};
}

macro_rules! lazy_encode_from {
(
$($ty:ty,)+
) => {
$(
impl<'tcx, B> EncodeFrom<'tcx, B> for LazyValue<$ty>
where
B: std::borrow::Borrow<<$ty as ParameterizedOverTcx>::Value<'tcx>>
{
fn encode_from<'a>(
encoder: &mut EncodeContext<'a, 'tcx>,
value: B,
) -> LazyValue<$ty> {
encoder.lazy(value)
}
}
)+
};
}

trivial_encode_from! {
bool,
u64,
// tidy-alphabetical-start
crate::rmeta::AttrFlags,
crate::rmeta::remapped_def_id::RemappedRawDefId,
rustc_hir::Constness,
rustc_hir::CoroutineKind,
rustc_hir::Defaultness,
rustc_hir::Safety,
rustc_hir::def::DefKind,
rustc_middle::ty::Asyncness,
// tidy-alphabetical-end
}

lazy_encode_from! {
// tidy-alphabetical-start
(rustc_middle::mir::ConstValue, Ty<'static>),
crate::rmeta::VariantData,
rustc_abi::ReprOptions,
rustc_ast::DelimArgs,
rustc_attr_ir::ConstStability,
rustc_attr_ir::DefaultBodyStability,
rustc_attr_ir::Deprecation,
rustc_attr_ir::Stability,
rustc_hir::OpaqueTyOrigin<rustc_span::def_id::DefId>,
rustc_hir::def_id::DefId,
rustc_hir::def_id::DefIdMap<rustc_middle::ty::EarlyBinder<'static, Ty<'static>>>,
rustc_hir::def_id::DefIdMap<std::vec::Vec<rustc_hir::def_id::DefId>>,
rustc_hir::definitions::DefKey,
rustc_index::IndexVec<rustc_abi::FieldIdx, rustc_span::Symbol>,
rustc_index::IndexVec<rustc_middle::mir::Promoted, rustc_middle::mir::Body<'static>>,
rustc_index::bit_set::DenseBitSet<u32>,
rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs,
rustc_middle::middle::resolve::DocLinkResMap,
rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault,
rustc_middle::mir::Body<'static>,
rustc_middle::mir::ConstQualifs,
rustc_middle::mir::CoroutineLayout<'static>,
rustc_middle::mir::interpret::ConstAllocation<'static>,
rustc_middle::ty::AnonConstKind,
rustc_middle::ty::AssocContainer,
rustc_middle::ty::AsyncDestructor,
rustc_middle::ty::ConstConditions<'static>,
rustc_middle::ty::Destructor,
rustc_middle::ty::EarlyBinder<'static, Ty<'static>>,
rustc_middle::ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>,
rustc_middle::ty::EarlyBinder<'static, rustc_middle::ty::PolyFnSig<'static>>,
rustc_middle::ty::GenericClauses<'static>,
rustc_middle::ty::Generics,
rustc_middle::ty::ImplTraitHeader<'static>,
rustc_middle::ty::ImplTraitInTraitData,
rustc_middle::ty::IntrinsicDef,
rustc_middle::ty::RestrictionKind,
rustc_middle::ty::Visibility<rustc_span::def_id::LocalDefId>,
rustc_middle::ty::adjustment::CoerceUnsizedInfo,
rustc_middle::ty::trait_def::TraitDef,
rustc_span::ExpnId,
rustc_span::Span,
std::option::Option<rustc_middle::ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>>,
std::string::String,
std::vec::Vec<(usize, rustc_index::bit_set::DenseBitSet<u32>)>,
// tidy-alphabetical-end
}

impl<'tcx, T, B> EncodeFrom<'tcx, Option<B>> for Option<LazyValue<T>>
where
T: ParameterizedOverTcx,
T::Value<'tcx>: for<'b> Encodable<EncodeContext<'b, 'tcx>>,
B: std::borrow::Borrow<T::Value<'tcx>>,
{
fn encode_from<'a>(
encoder: &mut EncodeContext<'a, 'tcx>,
value: Option<B>,
) -> Option<LazyValue<T>> {
value.map(|v| encoder.lazy(v))
}
}

impl<'tcx, T, I, B> EncodeFrom<'tcx, I> for LazyArray<T>
where
T: ParameterizedOverTcx,
I: IntoIterator<Item = B>,
B: std::borrow::Borrow<T::Value<'tcx>>,
T::Value<'tcx>: for<'a> Encodable<EncodeContext<'a, 'tcx>>,
{
fn encode_from<'a>(encoder: &mut EncodeContext<'a, 'tcx>, values: I) -> Self {
encoder.lazy_array(values)
}
}
7 changes: 6 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2964,9 +2964,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
let mut mod_inner_attrs_start = None;
match item.kind {
ItemKind::Mod(..) => {
// We only handle outer doc comments for modules here.
// We only handle outer attributes which can contain intra-doc links (doc comments
// and `deprecated`) for modules here.
let attrs = if let Some(pos) = item.attrs.iter().position(|a| {
a.doc_resolution_scope().is_some_and(|style| style == AttrStyle::Inner)
|| matches!(
a.kind,
AttrKind::Normal(ref n)
if n.item.name() == Some(sym::deprecated) && a.style == AttrStyle::Inner)
}) {
mod_inner_attrs_start = Some(pos);
&item.attrs[..pos]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ symbols! {
deref_target,
derive,
derive_const,
derive_const_issue: "118304",
derive_const_issue: "143874",
derive_default_enum,
derive_from,
derive_smart_pointer,
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, T> Iter<'a, T> {
///
/// assert_eq!(iter.as_slices(), (&[9, 10][..], &[0, 1][..]));
/// ```
#[unstable(feature = "vec_deque_iter_as_slices", issue = "123947")]
#[unstable(feature = "vec_deque_iter_as_slices", issue = "133253")]
pub fn as_slices(&self) -> (&'a [T], &'a [T]) {
(self.i1.as_slice(), self.i2.as_slice())
}
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/vec_deque/iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a, T> IterMut<'a, T> {
/// slices.1[0] = 24;
/// assert_eq!(deque.as_slices(), (&[8, 42, 10][..], &[24, 1, 2][..]));
/// ```
#[unstable(feature = "vec_deque_iter_as_slices", issue = "123947")]
#[unstable(feature = "vec_deque_iter_as_slices", issue = "133253")]
pub fn into_slices(self) -> (&'a mut [T], &'a mut [T]) {
(self.i1.into_slice(), self.i2.into_slice())
}
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'a, T> IterMut<'a, T> {
///
/// assert_eq!(iter.as_slices(), (&[9, 10][..], &[0, 1][..]));
/// ```
#[unstable(feature = "vec_deque_iter_as_slices", issue = "123947")]
#[unstable(feature = "vec_deque_iter_as_slices", issue = "133253")]
pub fn as_slices(&self) -> (&[T], &[T]) {
(self.i1.as_slice(), self.i2.as_slice())
}
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a, T> IterMut<'a, T> {
/// iter.as_mut_slices().1[0] = 24;
/// assert_eq!(deque.as_slices(), (&[8, 42, 10][..], &[24, 1, 2][..]));
/// ```
#[unstable(feature = "vec_deque_iter_as_slices", issue = "123947")]
#[unstable(feature = "vec_deque_iter_as_slices", issue = "133253")]
pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T]) {
(self.i1.as_mut_slice(), self.i2.as_mut_slice())
}
Expand Down
Loading
Loading