rust/compiler
Matthias Krüger 04b2073c84
Rollup merge of #92923 - dtolnay:ringbuffer, r=petrochenkov
Abstract the pretty printer's ringbuffer to be infinitely sized

This PR backports 8e5e83c3ff from the `prettyplease` crate into `rustc_ast_pretty`.

Using a dedicated RingBuffer type with non-wrapping indices, instead of manually `%`-ing indices into a capped sized buffer, unlocks a number of simplifications to the pretty printing algorithm implementation in followup commits such as fcb5968b1e and 4427cedcb8.

This change also greatly reduces memory overhead of the pretty printer. The old implementation always grows its buffer to 205920 bytes even for files without deeply nested code, because it only wraps its indices when they hit the maximum tolerable size of the ring buffer (the size after which the pretty printer will crash if there are that many tokens buffered). In contrast, the new implementation uses memory proportional to the peak number of simultaneously buffered tokens only, not the number of tokens that have ever been in the buffer.

Speaking of crashing the pretty printer and "maximum tolerable size", the constant used for that in the old implementation is a lie:

de9b573eed/compiler/rustc_ast_pretty/src/pp.rs (L227-L228)

It was raised from 3 to 55 in https://github.com/rust-lang/rust/pull/33934 because that was empirically the size that avoided crashing on one particular test crate, but according to https://github.com/rust-lang/rust/pull/33934#issuecomment-226700470 other syntax trees still crash at that size. There is no reason to believe that any particular size is good enough for arbitrary code, and using a large number like 55 adds overhead to inputs that never need close to that much of a buffer. The new implementation eliminates this tradeoff.
2022-01-18 04:42:06 +01:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
rustc_ast_lowering Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
rustc_ast_passes Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
rustc_ast_pretty Abstract the pretty printer's ringbuffer to be infinitely sized 2022-01-17 12:08:08 -08:00
rustc_attr
rustc_borrowck Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu 2022-01-17 09:40:29 +00:00
rustc_builtin_macros Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu 2022-01-17 09:40:29 +00:00
rustc_codegen_cranelift Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu 2022-01-17 09:40:29 +00:00
rustc_codegen_gcc Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
rustc_codegen_llvm Rollup merge of #92877 - Amanieu:remove_llvm_nounwind, r=Mark-Simulacrum 2022-01-17 20:07:07 +01:00
rustc_codegen_ssa Rollup merge of #92877 - Amanieu:remove_llvm_nounwind, r=Mark-Simulacrum 2022-01-17 20:07:07 +01:00
rustc_const_eval Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu 2022-01-17 09:40:29 +00:00
rustc_data_structures Auto merge of #92740 - cuviper:update-rayons, r=Mark-Simulacrum 2022-01-16 08:12:23 +00:00
rustc_driver Rollup merge of #92504 - dtolnay:wall, r=jackh726 2022-01-06 23:15:17 +01:00
rustc_error_codes Rollup merge of #92752 - jamestiotio:error-codes-typos, r=nagisa 2022-01-17 20:07:04 +01:00
rustc_errors Auto merge of #92070 - rukai:replace_vec_into_iter_with_array_into_iter, r=Mark-Simulacrum 2022-01-11 14:23:24 +00:00
rustc_expand Auto merge of #92473 - petrochenkov:ltrattr2, r=Aaron1011 2022-01-17 02:06:54 +00:00
rustc_feature Rollup merge of #92701 - ehuss:even-more-attr-validation, r=matthewjasper 2022-01-18 04:41:59 +01:00
rustc_fs_util
rustc_graphviz eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
rustc_hir Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
rustc_hir_pretty Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu 2022-01-17 09:40:29 +00:00
rustc_incremental Rollup merge of #92825 - pierwill:rustc-version-force-rename, r=Mark-Simulacrum 2022-01-17 20:07:06 +01:00
rustc_index remove unused FIXME 2022-01-12 16:09:01 +01:00
rustc_infer Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr 2022-01-18 04:41:58 +01:00
rustc_interface Update rayon and rustc-rayon 2022-01-10 11:34:07 -08:00
rustc_lexer
rustc_lint Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
rustc_lint_defs Fix lints documents 2022-01-13 03:57:44 +00:00
rustc_llvm Remove LLVMRustMarkAllFunctionsNounwind 2022-01-14 00:36:12 +00:00
rustc_log Make rustc_log doc test runnable 2022-01-03 22:31:56 -08:00
rustc_macros Rollup merge of #92011 - Aaron1011:decode-span, r=michaelwoerister 2022-01-03 14:44:16 +01:00
rustc_metadata Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, r=Aaron1011 2022-01-17 20:07:02 +01:00
rustc_middle Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr 2022-01-18 04:41:58 +01:00
rustc_mir_build Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
rustc_mir_dataflow Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
rustc_mir_transform Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
rustc_monomorphize Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr 2022-01-16 11:19:21 +00:00
rustc_parse Rollup merge of #92876 - compiler-errors:fix-turbofish-lifetime-suggestion, r=nagisa 2022-01-17 06:08:15 +01:00
rustc_parse_format
rustc_passes Rollup merge of #92701 - ehuss:even-more-attr-validation, r=matthewjasper 2022-01-18 04:41:59 +01:00
rustc_plugin_impl
rustc_privacy Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
rustc_query_impl attempt to re-add ty::Unevaluated visitor and friends 2022-01-15 01:16:55 +00:00
rustc_query_system Auto merge of #92740 - cuviper:update-rayons, r=Mark-Simulacrum 2022-01-16 08:12:23 +00:00
rustc_resolve Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
rustc_save_analysis Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
rustc_serialize Auto merge of #92604 - nnethercote:optimize-impl_read_unsigned_leb128, r=michaelwoerister 2022-01-15 07:27:30 +00:00
rustc_session sess/cg: re-introduce split dwarf kind 2022-01-06 09:32:42 +00:00
rustc_span Rollup merge of #92825 - pierwill:rustc-version-force-rename, r=Mark-Simulacrum 2022-01-17 20:07:06 +01:00
rustc_symbol_mangling Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr 2022-01-16 11:19:21 +00:00
rustc_target Rollup merge of #92581 - Meziu:armv6k-3ds-target, r=nagisa 2022-01-16 16:58:12 +01:00
rustc_trait_selection Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
rustc_traits Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr 2022-01-18 04:41:58 +01:00
rustc_ty_utils Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr 2022-01-16 11:19:21 +00:00
rustc_type_ir initial revert 2022-01-15 01:16:55 +00:00
rustc_typeck Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr 2022-01-18 04:41:58 +01:00