Skip to content

Commit

Permalink
Unrolled build for rust-lang#127729
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#127729 - compiler-errors:ed-2024-gen, r=oli-obk

Stop using the `gen` identifier in the compiler

In preparation for edition 2024, this PR previews the fallout of removing usages of `gen` since it's being reserved as a keyword.

There are two notable changes here:
1. Had to rename `fn gen(..)` in gen/kill analysis to `gen_`. Not certain there's a better name than that.
2. There are (false?[^1]) positives in `rustc_macros` when using synstructure, which uses `gen impl` to mark an implementation. We could suppress this in a one-off way, or perhaps just ignore `gen` in macros altogether, since if an identifier ends up in expanded code then it'll get properly denied anyways.

Not relevant to the compiler, but it's gonna be really annoying to change `rand`'s `gen` fn in the library and miri...

[^1]: I haven't looked at the synstructure proc macro code itself so I'm not certain if it'll start to fail when converted to ed2024 (or, e.g., when syn starts parsing `gen` as a kw).
  • Loading branch information
rust-timer committed Jul 15, 2024
2 parents eb72697 + 80393ea commit c093701
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 68 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
panic!("could not find BorrowIndex for location {location:?}");
});

trans.gen(index);
trans.gen_(index);
}

// Make sure there are no remaining borrows for variables
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3218,10 +3218,10 @@ impl<'hir> Item<'hir> {
ItemKind::Static(ty, mutbl, body), (ty, *mutbl, *body);

expect_const, (&'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
ItemKind::Const(ty, gen, body), (ty, gen, *body);
ItemKind::Const(ty, generics, body), (ty, generics, *body);

expect_fn, (&FnSig<'hir>, &'hir Generics<'hir>, BodyId),
ItemKind::Fn(sig, gen, body), (sig, gen, *body);
ItemKind::Fn(sig, generics, body), (sig, generics, *body);

expect_macro, (&ast::MacroDef, MacroKind), ItemKind::Macro(def, mk), (def, *mk);

Expand All @@ -3233,25 +3233,25 @@ impl<'hir> Item<'hir> {
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm(asm), asm;

expect_ty_alias, (&'hir Ty<'hir>, &'hir Generics<'hir>),
ItemKind::TyAlias(ty, gen), (ty, gen);
ItemKind::TyAlias(ty, generics), (ty, generics);

expect_opaque_ty, &OpaqueTy<'hir>, ItemKind::OpaqueTy(ty), ty;

expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, gen), (def, gen);
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, generics), (def, generics);

expect_struct, (&VariantData<'hir>, &'hir Generics<'hir>),
ItemKind::Struct(data, gen), (data, gen);
ItemKind::Struct(data, generics), (data, generics);

expect_union, (&VariantData<'hir>, &'hir Generics<'hir>),
ItemKind::Union(data, gen), (data, gen);
ItemKind::Union(data, generics), (data, generics);

expect_trait,
(IsAuto, Safety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
ItemKind::Trait(is_auto, safety, gen, bounds, items),
(*is_auto, *safety, gen, bounds, items);
ItemKind::Trait(is_auto, safety, generics, bounds, items),
(*is_auto, *safety, generics, bounds, items);

expect_trait_alias, (&'hir Generics<'hir>, GenericBounds<'hir>),
ItemKind::TraitAlias(gen, bounds), (gen, bounds);
ItemKind::TraitAlias(generics, bounds), (generics, bounds);

expect_impl, &'hir Impl<'hir>, ItemKind::Impl(imp), imp;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.and_then(|node| node.generics())
.into_iter()
.flat_map(|generics| generics.params)
.find(|gen| &gen.def_id.to_def_id() == res_def_id)
.find(|param| &param.def_id.to_def_id() == res_def_id)
} else {
None
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl<'a> DiagnosticDerive<'a> {
});

// A lifetime of `'a` causes conflicts, but `_sess` is fine.
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
#[allow(keyword_idents_2024)]
let mut imp = structure.gen_impl(quote! {
gen impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for @Self
where G: rustc_errors::EmissionGuarantee
Expand Down Expand Up @@ -148,6 +150,8 @@ impl<'a> LintDiagnosticDerive<'a> {
}
});

// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
#[allow(keyword_idents_2024)]
let mut imp = structure.gen_impl(quote! {
gen impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for @Self {
#[track_caller]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl SubdiagnosticDerive {

let diag = &self.diag;
let f = &self.f;

// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
#[allow(keyword_idents_2024)]
let ret = structure.gen_impl(quote! {
gen impl rustc_errors::Subdiagnostic for @Self {
fn add_to_diag_with<__G, __F>(
Expand All @@ -100,6 +103,7 @@ impl SubdiagnosticDerive {
}
}
});

ret
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,14 @@ macro_rules! extra_body_methods {
macro_rules! super_body {
($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => {
let span = $body.span;
if let Some(gen) = &$($mutability)? $body.coroutine {
if let Some(yield_ty) = $(& $mutability)? gen.yield_ty {
if let Some(coroutine) = &$($mutability)? $body.coroutine {
if let Some(yield_ty) = $(& $mutability)? coroutine.yield_ty {
$self.visit_ty(
yield_ty,
TyContext::YieldTy(SourceInfo::outermost(span))
);
}
if let Some(resume_ty) = $(& $mutability)? gen.resume_ty {
if let Some(resume_ty) = $(& $mutability)? coroutine.resume_ty {
$self.visit_ty(
resume_ty,
TyContext::ResumeTy(SourceInfo::outermost(span))
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ where
/// building up a `GenKillSet` and then throwing it away.
pub trait GenKill<T> {
/// Inserts `elem` into the state vector.
fn gen(&mut self, elem: T);
fn gen_(&mut self, elem: T);

/// Removes `elem` from the state vector.
fn kill(&mut self, elem: T);

/// Calls `gen` for each element in `elems`.
fn gen_all(&mut self, elems: impl IntoIterator<Item = T>) {
for elem in elems {
self.gen(elem);
self.gen_(elem);
}
}

Expand All @@ -424,44 +424,44 @@ pub trait GenKill<T> {

/// Stores a transfer function for a gen/kill problem.
///
/// Calling `gen`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
/// applied multiple times efficiently. When there are multiple calls to `gen` and/or `kill` for
/// Calling `gen_`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
/// applied multiple times efficiently. When there are multiple calls to `gen_` and/or `kill` for
/// the same element, the most recent one takes precedence.
#[derive(Clone)]
pub struct GenKillSet<T> {
gen: HybridBitSet<T>,
gen_: HybridBitSet<T>,
kill: HybridBitSet<T>,
}

impl<T: Idx> GenKillSet<T> {
/// Creates a new transfer function that will leave the dataflow state unchanged.
pub fn identity(universe: usize) -> Self {
GenKillSet {
gen: HybridBitSet::new_empty(universe),
gen_: HybridBitSet::new_empty(universe),
kill: HybridBitSet::new_empty(universe),
}
}

pub fn apply(&self, state: &mut impl BitSetExt<T>) {
state.union(&self.gen);
state.union(&self.gen_);
state.subtract(&self.kill);
}
}

impl<T: Idx> GenKill<T> for GenKillSet<T> {
fn gen(&mut self, elem: T) {
self.gen.insert(elem);
fn gen_(&mut self, elem: T) {
self.gen_.insert(elem);
self.kill.remove(elem);
}

fn kill(&mut self, elem: T) {
self.kill.insert(elem);
self.gen.remove(elem);
self.gen_.remove(elem);
}
}

impl<T: Idx> GenKill<T> for BitSet<T> {
fn gen(&mut self, elem: T) {
fn gen_(&mut self, elem: T) {
self.insert(elem);
}

Expand All @@ -471,7 +471,7 @@ impl<T: Idx> GenKill<T> for BitSet<T> {
}

impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
fn gen(&mut self, elem: T) {
fn gen_(&mut self, elem: T) {
self.insert(elem);
}

Expand All @@ -481,11 +481,11 @@ impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
}

impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
fn gen(&mut self, elem: T) {
fn gen_(&mut self, elem: T) {
match self {
// If the state is not reachable, adding an element does nothing.
MaybeReachable::Unreachable => {}
MaybeReachable::Reachable(set) => set.gen(elem),
MaybeReachable::Reachable(set) => set.gen_(elem),
}
}

Expand All @@ -499,7 +499,7 @@ impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
}

impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
fn gen(&mut self, elem: T) {
fn gen_(&mut self, elem: T) {
self.0.insert(elem);
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
Rvalue::AddressOf(_, borrowed_place)
| Rvalue::Ref(_, BorrowKind::Mut { .. } | BorrowKind::Shared, borrowed_place) => {
if !borrowed_place.is_indirect() {
self.trans.gen(borrowed_place.local);
self.trans.gen_(borrowed_place.local);
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ where
//
// [#61069]: https://github.com/rust-lang/rust/pull/61069
if !dropped_place.is_indirect() {
self.trans.gen(dropped_place.local);
self.trans.gen_(dropped_place.local);
}
}

Expand Down Expand Up @@ -159,8 +159,8 @@ pub fn borrowed_locals(body: &Body<'_>) -> BitSet<Local> {

impl GenKill<Local> for Borrowed {
#[inline]
fn gen(&mut self, elem: Local) {
self.0.gen(elem)
fn gen_(&mut self, elem: Local) {
self.0.gen_(elem)
}
#[inline]
fn kill(&mut self, _: Local) {
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
) {
match state {
DropFlagState::Absent => trans.kill(path),
DropFlagState::Present => trans.gen(path),
DropFlagState::Present => trans.gen_(path),
}
}
}
Expand All @@ -295,7 +295,7 @@ impl<'a, 'tcx> MaybeUninitializedPlaces<'a, '_, 'tcx> {
state: DropFlagState,
) {
match state {
DropFlagState::Absent => trans.gen(path),
DropFlagState::Absent => trans.gen_(path),
DropFlagState::Present => trans.kill(path),
}
}
Expand All @@ -309,7 +309,7 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
) {
match state {
DropFlagState::Absent => trans.kill(path),
DropFlagState::Present => trans.gen(path),
DropFlagState::Present => trans.gen_(path),
}
}
}
Expand All @@ -331,7 +331,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
assert!(s == DropFlagState::Present);
state.gen(path);
state.gen_(path);
});
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
&& let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
{
on_all_children_bits(self.move_data(), mpi, |child| {
trans.gen(child);
trans.gen_(child);
})
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
self.move_data(),
self.move_data().rev_lookup.find(place.as_ref()),
|mpi| {
trans.gen(mpi);
trans.gen_(mpi);
},
);
});
Expand Down Expand Up @@ -572,7 +572,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
self.move_data(),
enum_place,
variant,
|mpi| trans.gen(mpi),
|mpi| trans.gen_(mpi),
);
});
}
Expand Down Expand Up @@ -643,7 +643,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
self.move_data(),
self.move_data().rev_lookup.find(place.as_ref()),
|mpi| {
trans.gen(mpi);
trans.gen_(mpi);
},
);
});
Expand Down Expand Up @@ -738,7 +738,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, '_, 'tcx> {

let call_loc = self.body.terminator_loc(block);
for init_index in &init_loc_map[call_loc] {
trans.gen(*init_index);
trans.gen_(*init_index);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
self.0.kill(place.local);
}
}
Some(DefUse::Use) => self.0.gen(place.local),
Some(DefUse::Use) => self.0.gen_(place.local),
None => {}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ impl DefUse {
fn apply(trans: &mut impl GenKill<Local>, place: Place<'_>, context: PlaceContext) {
match DefUse::for_place(place, context) {
Some(DefUse::Def) => trans.kill(place.local),
Some(DefUse::Use) => trans.gen(place.local),
Some(DefUse::Use) => trans.gen_(place.local),
None => {}
}
}
Expand Down
Loading

0 comments on commit c093701

Please sign in to comment.