Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 3 pull requests #132171

Merged
merged 7 commits into from
Oct 26, 2024
Merged
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
23 changes: 12 additions & 11 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,9 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
let stable_since = features
.enabled_lang_features()
.iter()
.flat_map(|&(feature, _, since)| if feature == name { since } else { None })
.next();
.find(|feat| feat.gate_name == name)
.map(|feat| feat.stable_since)
.flatten();
if let Some(since) = stable_since {
err.stable_features.push(errors::StableFeature { name, since });
} else {
Expand All @@ -642,16 +643,15 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
}

fn check_incompatible_features(sess: &Session, features: &Features) {
let enabled_features = features
.enabled_lang_features()
.iter()
.copied()
.map(|(name, span, _)| (name, span))
.chain(features.enabled_lib_features().iter().copied());
let enabled_lang_features =
features.enabled_lang_features().iter().map(|feat| (feat.gate_name, feat.attr_sp));
let enabled_lib_features =
features.enabled_lib_features().iter().map(|feat| (feat.gate_name, feat.attr_sp));
let enabled_features = enabled_lang_features.chain(enabled_lib_features);

for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES
.iter()
.filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
.filter(|(f1, f2)| features.enabled(*f1) && features.enabled(*f2))
{
if let Some((f1_name, f1_span)) = enabled_features.clone().find(|(name, _)| name == f1) {
if let Some((f2_name, f2_span)) = enabled_features.clone().find(|(name, _)| name == f2)
Expand All @@ -673,10 +673,11 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
}

// Ban GCE with the new solver, because it does not implement GCE correctly.
if let Some(&(_, gce_span, _)) = features
if let Some(gce_span) = features
.enabled_lang_features()
.iter()
.find(|&&(feat, _, _)| feat == sym::generic_const_exprs)
.find(|feat| feat.gate_name == sym::generic_const_exprs)
.map(|feat| feat.attr_sp)
{
sess.dcx().emit_err(errors::IncompatibleFeatures {
spans: vec![gce_span],
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl DebugContext {
type_names::push_generic_params(
tcx,
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
enclosing_fn_def_id,
&mut name,
);

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_gcc/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
// whether we are sharing generics or not. The important thing here is
// that the visibility we apply to the declaration is the same one that
// has been applied to the definition (wherever that definition may be).
let is_generic =
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
let is_generic = instance.args.non_erasable_generics().next().is_some();

if is_generic {
// This is a monomorphization. Its expected visibility depends
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
unsafe {
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);

let is_generic =
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
let is_generic = instance.args.non_erasable_generics().next().is_some();

let is_hidden = if is_generic {
// This is a monomorphization of a generic function.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
type_names::push_generic_params(
tcx,
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
enclosing_fn_def_id,
&mut name,
);

Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn exported_symbols_provider_local(

match *mono_item {
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
if args.non_erasable_generics(tcx, def).next().is_some() {
if args.non_erasable_generics().next().is_some() {
let symbol = ExportedSymbol::Generic(def, args);
symbols.push((symbol, SymbolExportInfo {
level: SymbolExportLevel::Rust,
Expand All @@ -321,27 +321,21 @@ fn exported_symbols_provider_local(
}));
}
}
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(def_id, Some(ty)), args }) => {
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
// A little sanity-check
assert_eq!(
args.non_erasable_generics(tcx, def_id).next(),
Some(GenericArgKind::Type(ty))
);
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
}));
}
MonoItem::Fn(Instance {
def: InstanceKind::AsyncDropGlueCtorShim(def_id, Some(ty)),
def: InstanceKind::AsyncDropGlueCtorShim(_, Some(ty)),
args,
}) => {
// A little sanity-check
assert_eq!(
args.non_erasable_generics(tcx, def_id).next(),
Some(GenericArgKind::Type(ty))
);
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
symbols.push((ExportedSymbol::AsyncDropGlueCtorShim(ty), SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
Expand Down
29 changes: 8 additions & 21 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ fn push_debuginfo_type_name<'tcx>(
ty_and_layout,
&|output, visited| {
push_item_name(tcx, def.did(), true, output);
push_generic_params_internal(tcx, args, def.did(), output, visited);
push_generic_params_internal(tcx, args, output, visited);
},
output,
visited,
);
} else {
push_item_name(tcx, def.did(), qualified, output);
push_generic_params_internal(tcx, args, def.did(), output, visited);
push_generic_params_internal(tcx, args, output, visited);
}
}
ty::Tuple(component_types) => {
Expand Down Expand Up @@ -251,13 +251,8 @@ fn push_debuginfo_type_name<'tcx>(
let principal =
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
push_item_name(tcx, principal.def_id, qualified, output);
let principal_has_generic_params = push_generic_params_internal(
tcx,
principal.args,
principal.def_id,
output,
visited,
);
let principal_has_generic_params =
push_generic_params_internal(tcx, principal.args, output, visited);

let projection_bounds: SmallVec<[_; 4]> = trait_data
.projection_bounds()
Expand Down Expand Up @@ -538,13 +533,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
visited.clear();
push_generic_params_internal(
tcx,
trait_ref.args,
trait_ref.def_id,
&mut vtable_name,
&mut visited,
);
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
} else {
vtable_name.push('_');
}
Expand Down Expand Up @@ -647,12 +636,11 @@ fn push_unqualified_item_name(
fn push_generic_params_internal<'tcx>(
tcx: TyCtxt<'tcx>,
args: GenericArgsRef<'tcx>,
def_id: DefId,
output: &mut String,
visited: &mut FxHashSet<Ty<'tcx>>,
) -> bool {
assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
let mut args = args.non_erasable_generics(tcx, def_id).peekable();
let mut args = args.non_erasable_generics().peekable();
if args.peek().is_none() {
return false;
}
Expand Down Expand Up @@ -736,12 +724,11 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
pub fn push_generic_params<'tcx>(
tcx: TyCtxt<'tcx>,
args: GenericArgsRef<'tcx>,
def_id: DefId,
output: &mut String,
) {
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
let mut visited = FxHashSet::default();
push_generic_params_internal(tcx, args, def_id, output, &mut visited);
push_generic_params_internal(tcx, args, output, &mut visited);
}

fn push_closure_or_coroutine_name<'tcx>(
Expand Down Expand Up @@ -786,7 +773,7 @@ fn push_closure_or_coroutine_name<'tcx>(
// FIXME(async_closures): This is probably not going to be correct w.r.t.
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
let args = args.truncate_to(tcx, generics);
push_generic_params_internal(tcx, args, enclosing_fn_def_id, output, visited);
push_generic_params_internal(tcx, args, output, visited);
}

fn push_close_angle_bracket(cpp_like_debuginfo: bool, output: &mut String) {
Expand Down
21 changes: 15 additions & 6 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rustc_ast::{
use rustc_attr as attr;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_feature::{
ACCEPTED_LANG_FEATURES, AttributeSafety, Features, REMOVED_LANG_FEATURES,
UNSTABLE_LANG_FEATURES,
ACCEPTED_LANG_FEATURES, AttributeSafety, EnabledLangFeature, EnabledLibFeature, Features,
REMOVED_LANG_FEATURES, UNSTABLE_LANG_FEATURES,
};
use rustc_lint_defs::BuiltinLintDiag;
use rustc_parse::validate_attr;
Expand Down Expand Up @@ -88,8 +88,11 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -

// If the enabled feature is stable, record it.
if let Some(f) = ACCEPTED_LANG_FEATURES.iter().find(|f| name == f.name) {
let since = Some(Symbol::intern(f.since));
features.set_enabled_lang_feature(name, mi.span(), since);
features.set_enabled_lang_feature(EnabledLangFeature {
gate_name: name,
attr_sp: mi.span(),
stable_since: Some(Symbol::intern(f.since)),
});
continue;
}

Expand All @@ -115,13 +118,19 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
{
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
}
features.set_enabled_lang_feature(name, mi.span(), None);

features.set_enabled_lang_feature(EnabledLangFeature {
gate_name: name,
attr_sp: mi.span(),
stable_since: None,
});
continue;
}

// Otherwise, the feature is unknown. Enable it as a lib feature.
// It will be checked later whether the feature really exists.
features.set_enabled_lib_feature(name, mi.span());
features
.set_enabled_lib_feature(EnabledLibFeature { gate_name: name, attr_sp: mi.span() });

// Similar to above, detect internal lib features to suppress
// the ICE message that asks for a report.
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,6 @@ pub use builtin_attrs::{
is_valid_for_get_attr,
};
pub use removed::REMOVED_LANG_FEATURES;
pub use unstable::{Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES};
pub use unstable::{
EnabledLangFeature, EnabledLibFeature, Features, INCOMPATIBLE_FEATURES, UNSTABLE_LANG_FEATURES,
};
47 changes: 33 additions & 14 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,54 @@ macro_rules! status_to_enum {
#[derive(Clone, Default, Debug)]
pub struct Features {
/// `#![feature]` attrs for language features, for error reporting.
enabled_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
enabled_lang_features: Vec<EnabledLangFeature>,
/// `#![feature]` attrs for non-language (library) features.
enabled_lib_features: Vec<(Symbol, Span)>,
enabled_lib_features: Vec<EnabledLibFeature>,
/// `enabled_lang_features` + `enabled_lib_features`.
enabled_features: FxHashSet<Symbol>,
}

/// Information about an enabled language feature.
#[derive(Debug, Copy, Clone)]
pub struct EnabledLangFeature {
/// Name of the feature gate guarding the language feature.
pub gate_name: Symbol,
/// Span of the `#[feature(...)]` attribute.
pub attr_sp: Span,
/// If the lang feature is stable, the version number when it was stabilized.
pub stable_since: Option<Symbol>,
}

/// Information abhout an enabled library feature.
#[derive(Debug, Copy, Clone)]
pub struct EnabledLibFeature {
pub gate_name: Symbol,
pub attr_sp: Span,
}

impl Features {
/// `since` should be set for stable features that are nevertheless enabled with a `#[feature]`
/// attribute, indicating since when they are stable.
pub fn set_enabled_lang_feature(&mut self, name: Symbol, span: Span, since: Option<Symbol>) {
self.enabled_lang_features.push((name, span, since));
self.enabled_features.insert(name);
pub fn set_enabled_lang_feature(&mut self, lang_feat: EnabledLangFeature) {
self.enabled_lang_features.push(lang_feat);
self.enabled_features.insert(lang_feat.gate_name);
}

pub fn set_enabled_lib_feature(&mut self, name: Symbol, span: Span) {
self.enabled_lib_features.push((name, span));
self.enabled_features.insert(name);
pub fn set_enabled_lib_feature(&mut self, lib_feat: EnabledLibFeature) {
self.enabled_lib_features.push(lib_feat);
self.enabled_features.insert(lib_feat.gate_name);
}

/// Returns a list of triples with:
/// - feature gate name
/// - the span of the `#[feature]` attribute
/// - (for already stable features) the version since which it is stable
pub fn enabled_lang_features(&self) -> &Vec<(Symbol, Span, Option<Symbol>)> {
/// Returns a list of [`EnabledLangFeature`] with info about:
///
/// - Feature gate name.
/// - The span of the `#[feature]` attribute.
/// - For stable language features, version info for when it was stabilized.
pub fn enabled_lang_features(&self) -> &Vec<EnabledLangFeature> {
&self.enabled_lang_features
}

pub fn enabled_lib_features(&self) -> &Vec<(Symbol, Span)> {
pub fn enabled_lib_features(&self) -> &Vec<EnabledLibFeature> {
&self.enabled_lib_features
}

Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_hir_analysis/src/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Bounds are restrictions applied to some types after they've been lowered from the HIR to the
//! [`rustc_middle::ty`] form.

use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::LangItem;
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_span::Span;
Expand All @@ -25,7 +24,6 @@ use rustc_span::Span;
#[derive(Default, PartialEq, Eq, Clone, Debug)]
pub(crate) struct Bounds<'tcx> {
clauses: Vec<(ty::Clause<'tcx>, Span)>,
effects_min_tys: FxIndexMap<Ty<'tcx>, Span>,
}

impl<'tcx> Bounds<'tcx> {
Expand Down Expand Up @@ -96,15 +94,7 @@ impl<'tcx> Bounds<'tcx> {
}
}

pub(crate) fn clauses(
&self,
// FIXME(effects): remove tcx
_tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
pub(crate) fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
self.clauses.iter().cloned()
}

pub(crate) fn effects_min_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
self.effects_min_tys.keys().copied()
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn associated_type_bounds<'tcx>(
)
});

let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(bounds_from_parent));
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent));
debug!(
"associated_type_bounds({}) = {:?}",
tcx.def_path_str(assoc_item_def_id.to_def_id()),
Expand Down Expand Up @@ -339,7 +339,7 @@ fn opaque_type_bounds<'tcx>(
}
debug!(?bounds);

tcx.arena.alloc_from_iter(bounds.clauses(tcx))
tcx.arena.alloc_from_iter(bounds.clauses())
})
}

Expand Down
Loading
Loading