1
1
use std:: borrow:: Cow ;
2
2
use std:: cmp:: min;
3
- use std:: collections:: HashMap ;
4
3
5
4
use itertools:: Itertools ;
6
5
use rustc_ast:: token:: { Delimiter , LitKind } ;
@@ -23,7 +22,7 @@ use crate::macros::{rewrite_macro, MacroPosition};
23
22
use crate :: matches:: rewrite_match;
24
23
use crate :: overflow:: { self , IntoOverflowableItem , OverflowableItem } ;
25
24
use crate :: pairs:: { rewrite_all_pairs, rewrite_pair, PairParts } ;
26
- use crate :: rewrite:: { QueryId , Rewrite , RewriteContext } ;
25
+ use crate :: rewrite:: { Rewrite , RewriteContext } ;
27
26
use crate :: shape:: { Indent , Shape } ;
28
27
use crate :: source_map:: { LineRangeUtils , SpanUtils } ;
29
28
use crate :: spanned:: Spanned ;
@@ -54,54 +53,6 @@ pub(crate) fn format_expr(
54
53
expr_type : ExprType ,
55
54
context : & RewriteContext < ' _ > ,
56
55
shape : Shape ,
57
- ) -> Option < String > {
58
- // when max_width is tight, we should check all possible formattings, in order to find
59
- // if we can fit expression in the limit. Doing it recursively takes exponential time
60
- // relative to input size, and people hit it with rustfmt takes minutes in #4476 #4867 #5128
61
- // By memoization of format_expr function, we format each pair of expression and shape
62
- // only once, so worst case execution time becomes O(n*max_width^3).
63
- if context. inside_macro ( ) || context. is_macro_def {
64
- // span ids are not unique in macros, so we don't memoize result of them.
65
- return format_expr_inner ( expr, expr_type, context, shape) ;
66
- }
67
- let clean;
68
- let query_id = QueryId {
69
- shape,
70
- span : expr. span ,
71
- } ;
72
- if let Some ( map) = context. memoize . take ( ) {
73
- if let Some ( r) = map. get ( & query_id) {
74
- let r = r. clone ( ) ;
75
- context. memoize . set ( Some ( map) ) ; // restore map in the memoize cell for other users
76
- return r;
77
- }
78
- context. memoize . set ( Some ( map) ) ;
79
- clean = false ;
80
- } else {
81
- context. memoize . set ( Some ( HashMap :: default ( ) ) ) ;
82
- clean = true ; // We got None, so we are the top level called function. When
83
- // this function finishes, no one is interested in what is in the map, because
84
- // all of them are sub expressions of this top level expression, and this is
85
- // done. So we should clean up memoize map to save some memory.
86
- }
87
-
88
- let r = format_expr_inner ( expr, expr_type, context, shape) ;
89
- if clean {
90
- context. memoize . set ( None ) ;
91
- } else {
92
- if let Some ( mut map) = context. memoize . take ( ) {
93
- map. insert ( query_id, r. clone ( ) ) ; // insert the result in the memoize map
94
- context. memoize . set ( Some ( map) ) ; // so it won't be computed again
95
- }
96
- }
97
- r
98
- }
99
-
100
- fn format_expr_inner (
101
- expr : & ast:: Expr ,
102
- expr_type : ExprType ,
103
- context : & RewriteContext < ' _ > ,
104
- shape : Shape ,
105
56
) -> Option < String > {
106
57
skip_out_of_file_lines_range ! ( context, expr. span) ;
107
58
0 commit comments