Skip to content

Commit

Permalink
Auto merge of #107328 - matthiaskrgr:rollup-lfqwo0o, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #106904 (Preserve split DWARF files when building archives.)
 - #106971 (Handle diagnostics customization on the fluent side (for one specific diagnostic))
 - #106978 (Migrate mir_build's borrow conflicts)
 - #107150 (`ty::tls` cleanups)
 - #107168 (Use a type-alias-impl-trait in `ObligationForest`)
 - #107189 (Encode info for Adt in a single place.)
 - #107322 (Custom mir: Add support for some remaining, easy to support constructs)
 - #107323 (Disable ConstGoto opt in cleanup blocks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 26, 2023
2 parents 3e97763 + 4ed8cfc commit c62665e
Show file tree
Hide file tree
Showing 36 changed files with 641 additions and 611 deletions.
12 changes: 0 additions & 12 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,6 @@ fn check_opaque_type_parameter_valid(
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
let arg_is_param = match arg.unpack() {
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
GenericArgKind::Lifetime(lt) if lt.is_static() => {
tcx.sess
.struct_span_err(span, "non-defining opaque type use in defining scope")
.span_label(
tcx.def_span(opaque_generics.param_at(i, tcx).def_id),
"cannot use static lifetime; use a bound lifetime \
instead or remove the lifetime parameter from the \
opaque type",
)
.emit();
return false;
}
GenericArgKind::Lifetime(lt) => {
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
}
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,6 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> (bool, bool) {
return (false, false);
}

// If we're only producing artifacts that are archives, no need to preserve
// the objects as they're losslessly contained inside the archives.
if sess.crate_types().iter().all(|&x| x.is_archive()) {
return (false, false);
}

match (sess.split_debuginfo(), sess.opts.unstable_opts.split_dwarf_kind) {
// If there is no split debuginfo then do not preserve objects.
(SplitDebuginfo::Off, _) => (false, false),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_data_structures/src/obligation_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ pub enum ProcessResult<O, E> {
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
struct ObligationTreeId(usize);

type ObligationTreeIdGenerator =
std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> ObligationTreeId>;
type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;

pub struct ObligationForest<O: ForestObligation> {
/// The list of obligations. In between calls to [Self::process_obligations],
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@ borrowck_cannot_move_when_borrowed =
borrowck_opaque_type_non_generic_param =
expected generic {$kind} parameter, found `{$ty}`
.label = this generic parameter must be used with a generic {$kind} parameter
.label = {STREQ($ty, "'static") ->
[true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
*[other] this generic parameter must be used with a generic {$kind} parameter
}
2 changes: 0 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/infer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ infer_region_explanation = {$pref_kind ->
}{$desc_kind ->
*[should_not_happen] [{$desc_kind}]
[restatic] the static lifetime
[reempty] the empty lifetime
[reemptyuni] the empty lifetime in universe {$desc_arg}
[revar] lifetime {$desc_arg}
[as_defined] the lifetime `{$desc_arg}` as defined here
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_error_messages/locales/en-US/mir_build.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,18 @@ mir_build_borrow_of_moved_value = borrow of moved value
.suggestion = borrow this binding in the pattern to avoid moving the value
mir_build_multiple_mut_borrows = cannot borrow value as mutable more than once at a time
.label = first mutable borrow, by `{$name}`, occurs here
.mutable_borrow = another mutable borrow, by `{$name_mut}`, occurs here
.immutable_borrow = also borrowed as immutable, by `{$name_immut}`, here
.moved = also moved into `{$name_moved}` here
mir_build_already_borrowed = cannot borrow value as mutable because it is also borrowed as immutable
mir_build_already_mut_borrowed = cannot borrow value as immutable because it is also borrowed as mutable
mir_build_moved_while_borrowed = cannot move out of value because it is borrowed
mir_build_mutable_borrow = value is mutably borrowed by `{$name}` here
mir_build_borrow = value is borrowed by `{$name}` here
mir_build_moved = value is moved into `{$name}` here
mir_build_union_pattern = cannot use unions in constant patterns
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ pub fn fluent_bundle(
trace!(?locale);
let mut bundle = new_bundle(vec![locale]);

// Add convenience functions available to ftl authors.
register_functions(&mut bundle);

// Fluent diagnostics can insert directionality isolation markers around interpolated variables
// indicating that there may be a shift from right-to-left to left-to-right text (or
// vice-versa). These are disabled because they are sometimes visible in the error output, but
Expand Down Expand Up @@ -244,6 +247,15 @@ pub fn fluent_bundle(
Ok(Some(bundle))
}

fn register_functions(bundle: &mut FluentBundle) {
bundle
.add_function("STREQ", |positional, _named| match positional {
[FluentValue::String(a), FluentValue::String(b)] => format!("{}", (a == b)).into(),
_ => FluentValue::Error,
})
.expect("Failed to add a function to the bundle.");
}

/// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily
/// evaluated fluent bundle.
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
Expand All @@ -256,6 +268,9 @@ pub fn fallback_fluent_bundle(
) -> LazyFallbackBundle {
Lrc::new(Lazy::new(move || {
let mut fallback_bundle = new_bundle(vec![langid!("en-US")]);

register_functions(&mut fallback_bundle);

// See comment in `fluent_bundle`.
fallback_bundle.set_use_isolating(with_directionality_markers);

Expand Down
158 changes: 45 additions & 113 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use rustc_span::symbol::{sym, Symbol};
use rustc_span::{
self, DebuggerVisualizerFile, ExternalSource, FileName, SourceFile, Span, SyntaxContext,
};
use rustc_target::abi::VariantIdx;
use std::borrow::Borrow;
use std::collections::hash_map::Entry;
use std::hash::Hash;
Expand Down Expand Up @@ -1189,8 +1188,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
}
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
let params_in_repr = self.tcx.params_in_repr(def_id);
record!(self.tables.params_in_repr[def_id] <- params_in_repr);
self.encode_info_for_adt(def_id);
}
if should_encode_trait_impl_trait_tys(tcx, def_id)
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
Expand All @@ -1213,46 +1211,53 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}

fn encode_enum_variant_info(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx) {
#[instrument(level = "trace", skip(self))]
fn encode_info_for_adt(&mut self, def_id: DefId) {
let tcx = self.tcx;
let variant = &def.variant(index);
let def_id = variant.def_id;
debug!("EncodeContext::encode_enum_variant_info({:?})", def_id);

let data = VariantData {
discr: variant.discr,
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};
let adt_def = tcx.adt_def(def_id);
record!(self.tables.repr_options[def_id] <- adt_def.repr());

record!(self.tables.variant_data[def_id] <- data);
self.tables.constness.set(def_id.index, hir::Constness::Const);
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
assert!(f.did.is_local());
f.did.index
}));
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id));
let params_in_repr = self.tcx.params_in_repr(def_id);
record!(self.tables.params_in_repr[def_id] <- params_in_repr);

if adt_def.is_enum() {
record_array!(self.tables.children[def_id] <- iter::from_generator(||
for variant in tcx.adt_def(def_id).variants() {
yield variant.def_id.index;
// Encode constructors which take a separate slot in value namespace.
if let Some(ctor_def_id) = variant.ctor_def_id() {
yield ctor_def_id.index;
}
}
));
} else {
// For non-enum, there is only one variant, and its def_id is the adt's.
debug_assert_eq!(adt_def.variants().len(), 1);
debug_assert_eq!(adt_def.non_enum_variant().def_id, def_id);
// Therefore, the loop over variants will encode its fields as the adt's children.
}
}

fn encode_enum_variant_ctor(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx) {
let variant = &def.variant(index);
let Some((ctor_kind, def_id)) = variant.ctor else { return };
debug!("EncodeContext::encode_enum_variant_ctor({:?})", def_id);
for variant in adt_def.variants().iter() {
let data = VariantData {
discr: variant.discr,
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};
record!(self.tables.variant_data[variant.def_id] <- data);

// FIXME(eddyb) encode only the `CtorKind` for constructors.
let data = VariantData {
discr: variant.discr,
ctor: Some((ctor_kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};
self.tables.constness.set(variant.def_id.index, hir::Constness::Const);
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| {
assert!(f.did.is_local());
f.did.index
}));

record!(self.tables.variant_data[def_id] <- data);
self.tables.constness.set(def_id.index, hir::Constness::Const);
if ctor_kind == CtorKind::Fn {
record!(self.tables.fn_sig[def_id] <- self.tcx.fn_sig(def_id));
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
self.tables.constness.set(ctor_def_id.index, hir::Constness::Const);
let fn_sig = tcx.fn_sig(ctor_def_id);
record!(self.tables.fn_sig[ctor_def_id] <- fn_sig);
// FIXME only encode signature for ctor_def_id
record!(self.tables.fn_sig[variant.def_id] <- fn_sig);
}
}
}

Expand Down Expand Up @@ -1305,25 +1310,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}

fn encode_struct_ctor(&mut self, adt_def: ty::AdtDef<'tcx>) {
let variant = adt_def.non_enum_variant();
let Some((ctor_kind, def_id)) = variant.ctor else { return };
debug!("EncodeContext::encode_struct_ctor({:?})", def_id);

let data = VariantData {
discr: variant.discr,
ctor: Some((ctor_kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};

record!(self.tables.repr_options[def_id] <- adt_def.repr());
record!(self.tables.variant_data[def_id] <- data);
self.tables.constness.set(def_id.index, hir::Constness::Const);
if ctor_kind == CtorKind::Fn {
record!(self.tables.fn_sig[def_id] <- self.tcx.fn_sig(def_id));
}
}

fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
let bounds = self.tcx.explicit_item_bounds(def_id);
Expand Down Expand Up @@ -1532,33 +1518,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tables.is_type_alias_impl_trait.set_nullable(def_id.index, true);
}
}
hir::ItemKind::Enum(..) => {
let adt_def = self.tcx.adt_def(def_id);
record!(self.tables.repr_options[def_id] <- adt_def.repr());
}
hir::ItemKind::Struct(..) => {
let adt_def = self.tcx.adt_def(def_id);
record!(self.tables.repr_options[def_id] <- adt_def.repr());
self.tables.constness.set(def_id.index, hir::Constness::Const);

let variant = adt_def.non_enum_variant();
record!(self.tables.variant_data[def_id] <- VariantData {
discr: variant.discr,
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
});
}
hir::ItemKind::Union(..) => {
let adt_def = self.tcx.adt_def(def_id);
record!(self.tables.repr_options[def_id] <- adt_def.repr());

let variant = adt_def.non_enum_variant();
record!(self.tables.variant_data[def_id] <- VariantData {
discr: variant.discr,
ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
});
}
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
self.tables.impl_defaultness.set(def_id.index, *defaultness);
self.tables.constness.set(def_id.index, *constness);
Expand Down Expand Up @@ -1597,31 +1556,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::GlobalAsm(..)
| hir::ItemKind::TyAlias(..) => {}
};
// FIXME(eddyb) there should be a nicer way to do this.
match item.kind {
hir::ItemKind::Enum(..) => {
record_array!(self.tables.children[def_id] <- iter::from_generator(||
for variant in tcx.adt_def(def_id).variants() {
yield variant.def_id.index;
// Encode constructors which take a separate slot in value namespace.
if let Some(ctor_def_id) = variant.ctor_def_id() {
yield ctor_def_id.index;
}
}
))
}
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
record_array!(self.tables.children[def_id] <-
self.tcx.adt_def(def_id).non_enum_variant().fields.iter().map(|f| {
assert!(f.did.is_local());
f.did.index
})
)
}
hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
record_array!(self.tables.children[def_id] <-
Expand Down Expand Up @@ -1649,17 +1592,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// so it's easier to do that here then to wait until we would encounter
// normally in the visitor walk.
match item.kind {
hir::ItemKind::Enum(..) => {
let def = self.tcx.adt_def(item.owner_id.to_def_id());
for (i, _) in def.variants().iter_enumerated() {
self.encode_enum_variant_info(def, i);
self.encode_enum_variant_ctor(def, i);
}
}
hir::ItemKind::Struct(..) => {
let def = self.tcx.adt_def(item.owner_id.to_def_id());
self.encode_struct_ctor(def);
}
hir::ItemKind::Impl { .. } => {
for &trait_item_def_id in
self.tcx.associated_item_def_ids(item.owner_id.to_def_id()).iter()
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#![feature(min_specialization)]
#![feature(trusted_len)]
#![feature(type_alias_impl_trait)]
#![feature(strict_provenance)]
#![feature(associated_type_bounds)]
#![feature(rustc_attrs)]
#![feature(control_flow_enum)]
Expand Down
Loading

0 comments on commit c62665e

Please sign in to comment.