Skip to content

Commit 7e5a88a

Browse files
committed
Combine individual limit queries into single limits query
1 parent ff15b5e commit 7e5a88a

File tree

20 files changed

+75
-55
lines changed

20 files changed

+75
-55
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
872872
});
873873
},
874874
{
875-
// Mark the attributes as used, and ensure that
876-
// they're not ill-formed. We force these queries
877-
// to run, since they might not otherwise get called.
878-
tcx.ensure().recursion_limit(());
879-
tcx.ensure().move_size_limit(());
880-
tcx.ensure().type_length_limit(());
881-
tcx.ensure().const_eval_limit(());
875+
// We force these querie to run,
876+
// since they might not otherwise get called.
877+
// This marks the corresponding crate-level attributes
878+
// as used, and ensures that their values are valid.
879+
tcx.ensure().limits(());
882880
}
883881
);
884882
});

compiler/rustc_middle/src/middle/limits.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@
1212
use crate::bug;
1313
use crate::ty;
1414
use rustc_ast::Attribute;
15-
use rustc_session::Limit;
1615
use rustc_session::Session;
16+
use rustc_session::{Limit, Limits};
1717
use rustc_span::symbol::{sym, Symbol};
1818

1919
use std::num::IntErrorKind;
2020

2121
pub fn provide(providers: &mut ty::query::Providers) {
22-
providers.recursion_limit = |tcx, ()| get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess);
23-
providers.move_size_limit =
24-
|tcx, ()| get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::move_size_limit, 0).0;
25-
providers.type_length_limit =
26-
|tcx, ()| get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::type_length_limit, 1048576);
27-
providers.const_eval_limit =
28-
|tcx, ()| get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::const_eval_limit, 1_000_000);
22+
providers.limits = |tcx, ()| Limits {
23+
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
24+
move_size_limit: get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::move_size_limit, 0),
25+
type_length_limit: get_limit(
26+
tcx.hir().krate_attrs(),
27+
tcx.sess,
28+
sym::type_length_limit,
29+
1048576,
30+
),
31+
const_eval_limit: get_limit(
32+
tcx.hir().krate_attrs(),
33+
tcx.sess,
34+
sym::const_eval_limit,
35+
1_000_000,
36+
),
37+
}
2938
}
3039

3140
pub fn get_recursion_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,25 +1713,7 @@ rustc_queries! {
17131713
desc { "conservatively checking if {:?} is privately uninhabited", key }
17141714
}
17151715

1716-
/// The maximum recursion limit for potentially infinitely recursive
1717-
/// operations such as auto-dereference and monomorphization.
1718-
query recursion_limit(key: ()) -> Limit {
1719-
desc { "looking up recursion limit" }
1720-
}
1721-
1722-
/// The size at which the `large_assignments` lint starts
1723-
/// being emitted.
1724-
query move_size_limit(key: ()) -> usize {
1725-
desc { "looking up move size limit" }
1726-
}
1727-
1728-
/// The maximum length of types during monomorphization.
1729-
query type_length_limit(key: ()) -> Limit {
1730-
desc { "looking up type length limit" }
1731-
}
1732-
1733-
/// The maximum blocks a const expression can evaluate.
1734-
query const_eval_limit(key: ()) -> Limit {
1735-
desc { "looking up const eval limit" }
1716+
query limits(key: ()) -> Limits {
1717+
desc { "looking up limits" }
17361718
}
17371719
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use rustc_middle::ty::OpaqueTypeKey;
5353
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
5454
use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
5555
use rustc_session::lint::{Level, Lint};
56+
use rustc_session::Limit;
5657
use rustc_session::Session;
5758
use rustc_span::def_id::StableCrateId;
5859
use rustc_span::source_map::MultiSpan;
@@ -1569,6 +1570,22 @@ impl<'tcx> TyCtxt<'tcx> {
15691570
def_kind => (def_kind.article(), def_kind.descr(def_id)),
15701571
}
15711572
}
1573+
1574+
pub fn type_length_limit(self) -> Limit {
1575+
self.limits(()).type_length_limit
1576+
}
1577+
1578+
pub fn recursion_limit(self) -> Limit {
1579+
self.limits(()).recursion_limit
1580+
}
1581+
1582+
pub fn move_size_limit(self) -> Limit {
1583+
self.limits(()).move_size_limit
1584+
}
1585+
1586+
pub fn const_eval_limit(self) -> Limit {
1587+
self.limits(()).const_eval_limit
1588+
}
15721589
}
15731590

15741591
/// A trait implemented for all `X<'a>` types that can be safely and

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn layout_raw<'tcx>(
221221
ty::tls::with_related_context(tcx, move |icx| {
222222
let (param_env, ty) = query.into_parts();
223223

224-
if !tcx.recursion_limit(()).value_within_limit(icx.layout_depth) {
224+
if !tcx.recursion_limit().value_within_limit(icx.layout_depth) {
225225
tcx.sess.fatal(&format!("overflow representing the type `{}`", ty));
226226
}
227227

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
14371437
}
14381438

14391439
fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
1440-
let type_length_limit = self.tcx.type_length_limit(());
1440+
let type_length_limit = self.tcx.type_length_limit();
14411441
if type_length_limit.value_within_limit(self.printed_type_count) {
14421442
self.printed_type_count += 1;
14431443
self.pretty_print_type(ty)

compiler/rustc_middle/src/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_serialize::opaque;
4949
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
5050
use rustc_session::utils::NativeLibKind;
5151
use rustc_session::CrateDisambiguator;
52-
use rustc_session::Limit;
52+
use rustc_session::Limits;
5353
use rustc_target::spec::PanicStrategy;
5454

5555
use rustc_ast as ast;

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'tcx> TyCtxt<'tcx> {
206206
mut ty: Ty<'tcx>,
207207
normalize: impl Fn(Ty<'tcx>) -> Ty<'tcx>,
208208
) -> Ty<'tcx> {
209-
let recursion_limit = self.recursion_limit(());
209+
let recursion_limit = self.recursion_limit();
210210
for iteration in 0.. {
211211
if !recursion_limit.value_within_limit(iteration) {
212212
return self.ty_error_with_message(

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(super) fn mk_eval_cx<'mir, 'tcx>(
9898
tcx,
9999
root_span,
100100
param_env,
101-
CompileTimeInterpreter::new(tcx.const_eval_limit(())),
101+
CompileTimeInterpreter::new(tcx.const_eval_limit()),
102102
MemoryExtra { can_access_statics },
103103
)
104104
}
@@ -300,7 +300,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
300300
tcx,
301301
tcx.def_span(def.did),
302302
key.param_env,
303-
CompileTimeInterpreter::new(tcx.const_eval_limit(())),
303+
CompileTimeInterpreter::new(tcx.const_eval_limit()),
304304
// Statics (and promoteds inside statics) may access other statics, because unlike consts
305305
// they do not have to behave "as if" they were evaluated at runtime.
306306
MemoryExtra { can_access_statics: is_static },

compiler/rustc_mir/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
392392
tcx: tcx.at(root_span),
393393
param_env,
394394
memory: Memory::new(tcx, memory_extra),
395-
recursion_limit: tcx.recursion_limit(()),
395+
recursion_limit: tcx.recursion_limit(),
396396
}
397397
}
398398

0 commit comments

Comments
 (0)