Skip to content

Commit 2f84484

Browse files
committed
Remove the everybody loops pass
It isn't used anymore by rustdoc
1 parent 4566094 commit 2f84484

File tree

11 files changed

+12
-309
lines changed

11 files changed

+12
-309
lines changed

compiler/rustc_driver/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
F: FnOnce(&dyn PrinterSupport) -> A,
4343
{
4444
match *ppmode {
45-
Normal | EveryBodyLoops | Expanded => {
45+
Normal | Expanded => {
4646
let annotation = NoAnn { sess, tcx };
4747
f(&annotation)
4848
}

compiler/rustc_interface/src/passes.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::proc_macro_decls;
33
use crate::util;
44

55
use ast::CRATE_NODE_ID;
6-
use rustc_ast::mut_visit::MutVisitor;
76
use rustc_ast::{self as ast, visit};
87
use rustc_borrowck as mir_borrowck;
98
use rustc_codegen_ssa::back::link::emit_metadata;
@@ -29,7 +28,7 @@ use rustc_plugin_impl as plugin;
2928
use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
3029
use rustc_resolve::{Resolver, ResolverArenas};
3130
use rustc_serialize::json;
32-
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType, PpMode, PpSourceMode};
31+
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
3332
use rustc_session::cstore::{MetadataLoader, MetadataLoaderDyn};
3433
use rustc_session::lint;
3534
use rustc_session::output::{filename_for_input, filename_for_metadata};
@@ -384,11 +383,6 @@ pub fn configure_and_expand(
384383
rustc_builtin_macros::test_harness::inject(sess, resolver, &mut krate)
385384
});
386385

387-
if let Some(PpMode::Source(PpSourceMode::EveryBodyLoops)) = sess.opts.pretty {
388-
tracing::debug!("replacing bodies with loop {{}}");
389-
util::ReplaceBodyWithLoop::new(resolver).visit_crate(&mut krate);
390-
}
391-
392386
let has_proc_macro_decls = sess.time("AST_validation", || {
393387
rustc_ast_passes::ast_validation::check_crate(sess, &krate, resolver.lint_buffer())
394388
});
@@ -457,18 +451,12 @@ pub fn configure_and_expand(
457451
});
458452

459453
// Add all buffered lints from the `ParseSess` to the `Session`.
460-
// The ReplaceBodyWithLoop pass may have deleted some AST nodes, potentially
461-
// causing a delay_span_bug later if a buffered lint refers to such a deleted
462-
// AST node (issue #87308). Since everybody_loops is for pretty-printing only,
463-
// anyway, we simply skip all buffered lints here.
464-
if !matches!(sess.opts.pretty, Some(PpMode::Source(PpSourceMode::EveryBodyLoops))) {
465-
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
466-
info!("{} parse sess buffered_lints", buffered_lints.len());
467-
for early_lint in buffered_lints.drain(..) {
468-
resolver.lint_buffer().add_early_lint(early_lint);
469-
}
470-
});
471-
}
454+
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
455+
info!("{} parse sess buffered_lints", buffered_lints.len());
456+
for early_lint in buffered_lints.drain(..) {
457+
resolver.lint_buffer().add_early_lint(early_lint);
458+
}
459+
});
472460

473461
// Gate identifiers containing invalid Unicode codepoints that were recovered during lexing.
474462
sess.parse_sess.bad_unicode_identifiers.with_lock(|identifiers| {

compiler/rustc_interface/src/util.rs

+1-214
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use libloading::Library;
2-
use rustc_ast::mut_visit::{visit_clobber, MutVisitor, *};
3-
use rustc_ast::ptr::P;
4-
use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Term};
2+
use rustc_ast as ast;
53
use rustc_codegen_ssa::traits::CodegenBackend;
64
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
75
#[cfg(parallel_compiler)]
@@ -13,7 +11,6 @@ use rustc_middle::ty::tls;
1311
use rustc_parse::validate_attr;
1412
#[cfg(parallel_compiler)]
1513
use rustc_query_impl::QueryCtxt;
16-
use rustc_resolve::{self, Resolver};
1714
use rustc_session as session;
1815
use rustc_session::config::CheckCfg;
1916
use rustc_session::config::{self, CrateType};
@@ -25,12 +22,10 @@ use rustc_span::edition::Edition;
2522
use rustc_span::lev_distance::find_best_match_for_name;
2623
use rustc_span::source_map::FileLoader;
2724
use rustc_span::symbol::{sym, Symbol};
28-
use smallvec::SmallVec;
2925
use std::env;
3026
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
3127
use std::lazy::SyncOnceCell;
3228
use std::mem;
33-
use std::ops::DerefMut;
3429
#[cfg(not(parallel_compiler))]
3530
use std::panic;
3631
use std::path::{Path, PathBuf};
@@ -664,214 +659,6 @@ pub fn non_durable_rename(src: &Path, dst: &Path) -> std::io::Result<()> {
664659
std::fs::rename(src, dst)
665660
}
666661

667-
/// Replaces function bodies with `loop {}` (an infinite loop). This gets rid of
668-
/// all semantic errors in the body while still satisfying the return type,
669-
/// except in certain cases, see below for more.
670-
///
671-
/// This pass is known as `everybody_loops`. Very punny.
672-
///
673-
/// As of March 2021, `everybody_loops` is only used for the
674-
/// `-Z unpretty=everybody_loops` debugging option.
675-
///
676-
/// FIXME: Currently the `everybody_loops` transformation is not applied to:
677-
/// * `const fn`; support could be added, but hasn't. Originally `const fn`
678-
/// was skipped due to issue #43636 that `loop` was not supported for
679-
/// const evaluation.
680-
/// * `impl Trait`, due to issue #43869 that functions returning impl Trait cannot be diverging.
681-
/// Solving this may require `!` to implement every trait, which relies on the an even more
682-
/// ambitious form of the closed RFC #1637. See also [#34511].
683-
///
684-
/// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
685-
pub struct ReplaceBodyWithLoop<'a, 'b> {
686-
within_static_or_const: bool,
687-
nested_blocks: Option<Vec<ast::Block>>,
688-
resolver: &'a mut Resolver<'b>,
689-
}
690-
691-
impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
692-
pub fn new(resolver: &'a mut Resolver<'b>) -> ReplaceBodyWithLoop<'a, 'b> {
693-
ReplaceBodyWithLoop { within_static_or_const: false, nested_blocks: None, resolver }
694-
}
695-
696-
fn run<R, F: FnOnce(&mut Self) -> R>(&mut self, is_const: bool, action: F) -> R {
697-
let old_const = mem::replace(&mut self.within_static_or_const, is_const);
698-
let old_blocks = self.nested_blocks.take();
699-
let ret = action(self);
700-
self.within_static_or_const = old_const;
701-
self.nested_blocks = old_blocks;
702-
ret
703-
}
704-
705-
fn should_ignore_fn(ret_ty: &ast::FnRetTy) -> bool {
706-
let ast::FnRetTy::Ty(ref ty) = ret_ty else {
707-
return false;
708-
};
709-
fn involves_impl_trait(ty: &ast::Ty) -> bool {
710-
match ty.kind {
711-
ast::TyKind::ImplTrait(..) => true,
712-
ast::TyKind::Slice(ref subty)
713-
| ast::TyKind::Array(ref subty, _)
714-
| ast::TyKind::Ptr(ast::MutTy { ty: ref subty, .. })
715-
| ast::TyKind::Rptr(_, ast::MutTy { ty: ref subty, .. })
716-
| ast::TyKind::Paren(ref subty) => involves_impl_trait(subty),
717-
ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()),
718-
ast::TyKind::Path(_, ref path) => {
719-
path.segments.iter().any(|seg| match seg.args.as_deref() {
720-
None => false,
721-
Some(&ast::GenericArgs::AngleBracketed(ref data)) => {
722-
data.args.iter().any(|arg| match arg {
723-
ast::AngleBracketedArg::Arg(arg) => match arg {
724-
ast::GenericArg::Type(ty) => involves_impl_trait(ty),
725-
ast::GenericArg::Lifetime(_) | ast::GenericArg::Const(_) => {
726-
false
727-
}
728-
},
729-
ast::AngleBracketedArg::Constraint(c) => match c.kind {
730-
ast::AssocConstraintKind::Bound { .. } => true,
731-
ast::AssocConstraintKind::Equality { ref term } => {
732-
match term {
733-
Term::Ty(ty) => involves_impl_trait(ty),
734-
// FIXME(...): This should check if the constant
735-
// involves a trait impl, but for now ignore.
736-
Term::Const(_) => false,
737-
}
738-
}
739-
},
740-
})
741-
}
742-
Some(&ast::GenericArgs::Parenthesized(ref data)) => {
743-
any_involves_impl_trait(data.inputs.iter())
744-
|| ReplaceBodyWithLoop::should_ignore_fn(&data.output)
745-
}
746-
})
747-
}
748-
_ => false,
749-
}
750-
}
751-
752-
fn any_involves_impl_trait<'a, I: Iterator<Item = &'a P<ast::Ty>>>(mut it: I) -> bool {
753-
it.any(|subty| involves_impl_trait(subty))
754-
}
755-
756-
involves_impl_trait(ty)
757-
}
758-
759-
fn is_sig_const(sig: &ast::FnSig) -> bool {
760-
matches!(sig.header.constness, ast::Const::Yes(_))
761-
|| ReplaceBodyWithLoop::should_ignore_fn(&sig.decl.output)
762-
}
763-
}
764-
765-
impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
766-
fn visit_item_kind(&mut self, i: &mut ast::ItemKind) {
767-
let is_const = match i {
768-
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
769-
ast::ItemKind::Fn(box ast::Fn { ref sig, .. }) => Self::is_sig_const(sig),
770-
_ => false,
771-
};
772-
self.run(is_const, |s| noop_visit_item_kind(i, s))
773-
}
774-
775-
fn flat_map_trait_item(&mut self, i: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
776-
let is_const = match i.kind {
777-
ast::AssocItemKind::Const(..) => true,
778-
ast::AssocItemKind::Fn(box ast::Fn { ref sig, .. }) => Self::is_sig_const(sig),
779-
_ => false,
780-
};
781-
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))
782-
}
783-
784-
fn flat_map_impl_item(&mut self, i: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
785-
self.flat_map_trait_item(i)
786-
}
787-
788-
fn visit_anon_const(&mut self, c: &mut ast::AnonConst) {
789-
self.run(true, |s| noop_visit_anon_const(c, s))
790-
}
791-
792-
fn visit_block(&mut self, b: &mut P<ast::Block>) {
793-
fn stmt_to_block(
794-
rules: ast::BlockCheckMode,
795-
s: Option<ast::Stmt>,
796-
resolver: &mut Resolver<'_>,
797-
) -> ast::Block {
798-
ast::Block {
799-
stmts: s.into_iter().collect(),
800-
rules,
801-
id: resolver.next_node_id(),
802-
span: rustc_span::DUMMY_SP,
803-
tokens: None,
804-
could_be_bare_literal: false,
805-
}
806-
}
807-
808-
fn block_to_stmt(b: ast::Block, resolver: &mut Resolver<'_>) -> ast::Stmt {
809-
let expr = P(ast::Expr {
810-
id: resolver.next_node_id(),
811-
kind: ast::ExprKind::Block(P(b), None),
812-
span: rustc_span::DUMMY_SP,
813-
attrs: AttrVec::new(),
814-
tokens: None,
815-
});
816-
817-
ast::Stmt {
818-
id: resolver.next_node_id(),
819-
kind: ast::StmtKind::Expr(expr),
820-
span: rustc_span::DUMMY_SP,
821-
}
822-
}
823-
824-
let empty_block = stmt_to_block(BlockCheckMode::Default, None, self.resolver);
825-
let loop_expr = P(ast::Expr {
826-
kind: ast::ExprKind::Loop(P(empty_block), None),
827-
id: self.resolver.next_node_id(),
828-
span: rustc_span::DUMMY_SP,
829-
attrs: AttrVec::new(),
830-
tokens: None,
831-
});
832-
833-
let loop_stmt = ast::Stmt {
834-
id: self.resolver.next_node_id(),
835-
span: rustc_span::DUMMY_SP,
836-
kind: ast::StmtKind::Expr(loop_expr),
837-
};
838-
839-
if self.within_static_or_const {
840-
noop_visit_block(b, self)
841-
} else {
842-
visit_clobber(b.deref_mut(), |b| {
843-
let mut stmts = vec![];
844-
for s in b.stmts {
845-
let old_blocks = self.nested_blocks.replace(vec![]);
846-
847-
stmts.extend(self.flat_map_stmt(s).into_iter().filter(|s| s.is_item()));
848-
849-
// we put a Some in there earlier with that replace(), so this is valid
850-
let new_blocks = self.nested_blocks.take().unwrap();
851-
self.nested_blocks = old_blocks;
852-
stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, self.resolver)));
853-
}
854-
855-
let mut new_block = ast::Block { stmts, ..b };
856-
857-
if let Some(old_blocks) = self.nested_blocks.as_mut() {
858-
//push our fresh block onto the cache and yield an empty block with `loop {}`
859-
if !new_block.stmts.is_empty() {
860-
old_blocks.push(new_block);
861-
}
862-
863-
stmt_to_block(b.rules, Some(loop_stmt), &mut self.resolver)
864-
} else {
865-
//push `loop {}` onto the end of our fresh block and yield that
866-
new_block.stmts.push(loop_stmt);
867-
868-
new_block
869-
}
870-
})
871-
}
872-
}
873-
}
874-
875662
/// Returns a version string such as "1.46.0 (04488afe3 2020-08-24)"
876663
pub fn version_str() -> Option<&'static str> {
877664
option_env!("CFG_VERSION")

compiler/rustc_session/src/config.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,6 @@ fn parse_pretty(debugging_opts: &DebuggingOptions, efmt: ErrorOutputType) -> Opt
25092509
let first = match debugging_opts.unpretty.as_deref()? {
25102510
"normal" => Source(PpSourceMode::Normal),
25112511
"identified" => Source(PpSourceMode::Identified),
2512-
"everybody_loops" => Source(PpSourceMode::EveryBodyLoops),
25132512
"expanded" => Source(PpSourceMode::Expanded),
25142513
"expanded,identified" => Source(PpSourceMode::ExpandedIdentified),
25152514
"expanded,hygiene" => Source(PpSourceMode::ExpandedHygiene),
@@ -2645,8 +2644,6 @@ impl fmt::Display for CrateType {
26452644
pub enum PpSourceMode {
26462645
/// `-Zunpretty=normal`
26472646
Normal,
2648-
/// `-Zunpretty=everybody_loops`
2649-
EveryBodyLoops,
26502647
/// `-Zunpretty=expanded`
26512648
Expanded,
26522649
/// `-Zunpretty=identified`
@@ -2678,7 +2675,7 @@ pub enum PpHirMode {
26782675
#[derive(Copy, Clone, PartialEq, Debug)]
26792676
pub enum PpMode {
26802677
/// Options that print the source code, i.e.
2681-
/// `-Zunpretty=normal` and `-Zunpretty=everybody_loops`
2678+
/// `-Zunpretty=normal` and `-Zunpretty=expanded`
26822679
Source(PpSourceMode),
26832680
AstTree(PpAstTreeMode),
26842681
/// Options that print the HIR, i.e. `-Zunpretty=hir`
@@ -2700,7 +2697,7 @@ impl PpMode {
27002697
match *self {
27012698
Source(Normal | Identified) | AstTree(PpAstTreeMode::Normal) => false,
27022699

2703-
Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene)
2700+
Source(Expanded | ExpandedIdentified | ExpandedHygiene)
27042701
| AstTree(PpAstTreeMode::Expanded)
27052702
| Hir(_)
27062703
| HirTree

compiler/rustc_session/src/options.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ options! {
14911491
`normal`, `identified`,
14921492
`expanded`, `expanded,identified`,
14931493
`expanded,hygiene` (with internal representations),
1494-
`everybody_loops` (all function bodies replaced with `loop {}`),
14951494
`ast-tree` (raw AST before expansion),
14961495
`ast-tree,expanded` (raw AST after expansion),
14971496
`hir` (the HIR), `hir,identified`,

compiler/rustc_typeck/src/check_unused.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
8282
// The `def_id` here actually was calculated during resolution (at least
8383
// at the time of this writing) and is being shipped to us via a side
8484
// channel of the tcx. There may have been extra expansion phases,
85-
// however, which ended up removing the `def_id` *after* expansion such
86-
// as the `ReplaceBodyWithLoop` pass (which is a bit of a hack, but hey)
85+
// however, which ended up removing the `def_id` *after* expansion.
8786
//
8887
// As a result we need to verify that `def_id` is indeed still valid for
8988
// our AST and actually present in the HIR map. If it's not there then

src/test/ui/lint/issue-87308.rs

-12
This file was deleted.

src/test/ui/lint/issue-87308.stdout

-14
This file was deleted.

src/test/ui/repr/issue-83921-pretty.normal.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)