Skip to content

Commit 730a076

Browse files
committed
Don't hardcode stack growth in stack growing function name
1 parent 9db4e0e commit 730a076

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use hir::GenericArg;
5050
use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
5151
ELIDED_LIFETIMES_IN_PATHS};
5252
use middle::cstore::CrateStore;
53-
use middle::recursion_limit::guarantee_one_mb_stack_left;
53+
use middle::recursion_limit::ensure_sufficient_stack;
5454
use rustc_data_structures::fx::FxHashSet;
5555
use rustc_data_structures::indexed_vec::IndexVec;
5656
use rustc_data_structures::thin_vec::ThinVec;
@@ -4267,7 +4267,7 @@ impl<'a> LoweringContext<'a> {
42674267
// just lowered from the expression
42684268
let kind = match e.node {
42694269
ExprKind::Paren(ref ex) => {
4270-
let mut ex = guarantee_one_mb_stack_left(|| self.lower_expr(ex));
4270+
let mut ex = ensure_sufficient_stack(|| self.lower_expr(ex));
42714271
// include parens in span, but only if it is a super-span.
42724272
if e.span.contains(ex.span) {
42734273
ex.span = e.span;
@@ -4446,7 +4446,7 @@ impl<'a> LoweringContext<'a> {
44464446
// add the attributes to the outer returned expr node
44474447
return self.expr_block(block, e.attrs.clone());
44484448
},
4449-
_ => guarantee_one_mb_stack_left(|| self.lower_expr_kind(e)),
4449+
_ => ensure_sufficient_stack(|| self.lower_expr_kind(e)),
44504450
};
44514451

44524452
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);

src/librustc/middle/recursion_limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
2828
/// from this.
2929
///
3030
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
31-
pub fn guarantee_one_mb_stack_left<R, F: FnOnce() -> R>(
31+
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R>(
3232
f: F
3333
) -> R {
3434
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)

src/librustc/traits/project.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ty::subst::{Subst, Substs};
3333
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
3434
use ty::fold::{TypeFoldable, TypeFolder};
3535
use util::common::FN_OUTPUT_NAME;
36-
use middle::recursion_limit::guarantee_one_mb_stack_left;
36+
use middle::recursion_limit::ensure_sufficient_stack;
3737

3838
/// Depending on the stage of compilation, we want projection to be
3939
/// more or less conservative.
@@ -299,7 +299,7 @@ pub fn normalize_with_depth<'a, 'b, 'gcx, 'tcx, T>(
299299
{
300300
debug!("normalize_with_depth(depth={}, value={:?})", depth, value);
301301
let mut normalizer = AssociatedTypeNormalizer::new(selcx, param_env, cause, depth);
302-
let result = guarantee_one_mb_stack_left(|| normalizer.fold(value));
302+
let result = ensure_sufficient_stack(|| normalizer.fold(value));
303303
debug!("normalize_with_depth: depth={} result={:?} with {} obligations",
304304
depth, result, normalizer.obligations.len());
305305
debug!("normalize_with_depth: depth={} obligations={:?}",
@@ -384,7 +384,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
384384
let generic_ty = self.tcx().type_of(def_id);
385385
let concrete_ty = generic_ty.subst(self.tcx(), substs);
386386
self.depth += 1;
387-
let folded_ty = guarantee_one_mb_stack_left(|| self.fold_ty(concrete_ty));
387+
let folded_ty = ensure_sufficient_stack(|| self.fold_ty(concrete_ty));
388388
self.depth -= 1;
389389
folded_ty
390390
}

src/librustc/traits/query/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
2121
use ty::fold::{TypeFoldable, TypeFolder};
2222
use ty::subst::{Subst, Substs};
2323
use ty::{self, Ty, TyCtxt};
24-
use middle::recursion_limit::guarantee_one_mb_stack_left;
24+
use middle::recursion_limit::ensure_sufficient_stack;
2525

2626
use super::NoSolution;
2727

@@ -132,7 +132,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
132132
ty
133133
);
134134
}
135-
let folded_ty = guarantee_one_mb_stack_left(|| self.fold_ty(concrete_ty));
135+
let folded_ty = ensure_sufficient_stack(|| self.fold_ty(concrete_ty));
136136
self.anon_depth -= 1;
137137
folded_ty
138138
}

src/librustc/traits/select.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use hir::def_id::DefId;
4242
use infer;
4343
use infer::{InferCtxt, InferOk, TypeFreshener};
4444
use middle::lang_items;
45-
use middle::recursion_limit::guarantee_one_mb_stack_left;
45+
use middle::recursion_limit::ensure_sufficient_stack;
4646
use mir::interpret::GlobalId;
4747
use ty::fast_reject;
4848
use ty::relate::TypeRelation;
@@ -2856,7 +2856,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
28562856
};
28572857

28582858
let cause = obligation.derived_cause(BuiltinDerivedObligation);
2859-
guarantee_one_mb_stack_left(|| {
2859+
ensure_sufficient_stack(|| {
28602860
self.collect_predicates_for_types(
28612861
obligation.param_env,
28622862
cause,
@@ -2906,7 +2906,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29062906
nested: ty::Binder<Vec<Ty<'tcx>>>,
29072907
) -> VtableAutoImplData<PredicateObligation<'tcx>> {
29082908
debug!("vtable_auto_impl: nested={:?}", nested);
2909-
guarantee_one_mb_stack_left(|| {
2909+
ensure_sufficient_stack(|| {
29102910

29112911
let cause = obligation.derived_cause(BuiltinDerivedObligation);
29122912
let mut obligations = self.collect_predicates_for_types(
@@ -2959,7 +2959,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29592959
let (substs, placeholder_map) = this.rematch_impl(impl_def_id, obligation, snapshot);
29602960
debug!("confirm_impl_candidate: substs={:?}", substs);
29612961
let cause = obligation.derived_cause(ImplDerivedObligation);
2962-
guarantee_one_mb_stack_left(|| this.vtable_impl(
2962+
ensure_sufficient_stack(|| this.vtable_impl(
29632963
impl_def_id,
29642964
substs,
29652965
cause,
@@ -3092,7 +3092,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30923092
let Normalized {
30933093
value: trait_ref,
30943094
obligations,
3095-
} = guarantee_one_mb_stack_left(|| project::normalize_with_depth(
3095+
} = ensure_sufficient_stack(|| project::normalize_with_depth(
30963096
self,
30973097
obligation.param_env,
30983098
obligation.cause.clone(),
@@ -3175,7 +3175,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31753175
let Normalized {
31763176
value: trait_ref,
31773177
mut obligations,
3178-
} = guarantee_one_mb_stack_left(|| normalize_with_depth(
3178+
} = ensure_sufficient_stack(|| normalize_with_depth(
31793179
self,
31803180
obligation.param_env,
31813181
obligation.cause.clone(),
@@ -3228,7 +3228,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
32283228
let Normalized {
32293229
value: trait_ref,
32303230
mut obligations,
3231-
} = guarantee_one_mb_stack_left(|| normalize_with_depth(
3231+
} = ensure_sufficient_stack(|| normalize_with_depth(
32323232
self,
32333233
obligation.param_env,
32343234
obligation.cause.clone(),
@@ -3486,7 +3486,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34863486
nested.extend(obligations);
34873487

34883488
// Construct the nested Field<T>: Unsize<Field<U>> predicate.
3489-
nested.push(guarantee_one_mb_stack_left(|| {
3489+
nested.push(ensure_sufficient_stack(|| {
34903490
tcx.predicate_for_trait_def(
34913491
obligation.param_env,
34923492
obligation.cause.clone(),
@@ -3520,7 +3520,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35203520
nested.extend(obligations);
35213521

35223522
// Construct the nested T: Unsize<U> predicate.
3523-
nested.push(guarantee_one_mb_stack_left(|| {
3523+
nested.push(ensure_sufficient_stack(|| {
35243524
tcx.predicate_for_trait_def(
35253525
obligation.param_env,
35263526
obligation.cause.clone(),
@@ -3602,7 +3602,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
36023602
let Normalized {
36033603
value: impl_trait_ref,
36043604
obligations: mut nested_obligations,
3605-
} = guarantee_one_mb_stack_left(|| project::normalize_with_depth(
3605+
} = ensure_sufficient_stack(|| project::normalize_with_depth(
36063606
self,
36073607
obligation.param_env,
36083608
obligation.cause.clone(),

src/librustc/ty/inhabitedness/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ty::{AdtDef, VariantDef, FieldDef, Ty, TyS};
1414
use ty::{DefId, Substs};
1515
use ty::{AdtKind, Visibility};
1616
use ty::TyKind::*;
17-
use middle::recursion_limit::guarantee_one_mb_stack_left;
17+
use middle::recursion_limit::ensure_sufficient_stack;
1818

1919
pub use self::def_id_forest::DefIdForest;
2020

@@ -250,7 +250,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
250250
tcx.sess.fatal(&error);
251251
}
252252
}
253-
let ret = guarantee_one_mb_stack_left(|| {
253+
let ret = ensure_sufficient_stack(|| {
254254
def.uninhabited_from(visited, tcx, substs)
255255
});
256256
let substs_set = visited.get_mut(&def.did).unwrap();

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
540540
p.record_query(Q::CATEGORY);
541541
});
542542

543-
let res = ::middle::recursion_limit::guarantee_one_mb_stack_left(|| job.start(self, |tcx| {
543+
let res = ::middle::recursion_limit::ensure_sufficient_stack(|| job.start(self, |tcx| {
544544
if dep_node.kind.is_eval_always() {
545545
tcx.dep_graph.with_eval_always_task(dep_node,
546546
tcx,

src/librustc_mir/build/expr/as_temp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
1414
use hair::*;
1515
use rustc::middle::region;
1616
use rustc::mir::*;
17-
use rustc::middle::recursion_limit::guarantee_one_mb_stack_left;
17+
use rustc::middle::recursion_limit::ensure_sufficient_stack;
1818

1919
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2020
/// Compile `expr` into a fresh temporary. This is used when building
@@ -34,7 +34,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3434
// this is the only place in mir building that we need to truly need to worry about
3535
// infinite recursion. Everything else does recurse, too, but it always gets broken up
3636
// at some point by inserting an intermediate temporary
37-
guarantee_one_mb_stack_left(|| self.expr_as_temp(block, temp_lifetime, expr, mutability))
37+
ensure_sufficient_stack(|| self.expr_as_temp(block, temp_lifetime, expr, mutability))
3838
}
3939

4040
fn expr_as_temp(

src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
409409
recursion_depths));
410410
check_type_length_limit(tcx, instance);
411411

412-
rustc::middle::recursion_limit::guarantee_one_mb_stack_left(|| {
412+
rustc::middle::recursion_limit::ensure_sufficient_stack(|| {
413413
collect_neighbours(tcx, instance, &mut neighbors);
414414
});
415415
}
@@ -1180,7 +1180,7 @@ fn collect_miri<'a, 'tcx>(
11801180
Some(AllocType::Memory(alloc)) => {
11811181
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
11821182
for &((), inner) in alloc.relocations.values() {
1183-
rustc::middle::recursion_limit::guarantee_one_mb_stack_left(|| {
1183+
rustc::middle::recursion_limit::ensure_sufficient_stack(|| {
11841184
collect_miri(tcx, inner, output);
11851185
});
11861186
}

src/librustc_traits/dropck_outlives.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,20 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>(
193193

194194
ty::Array(ety, _) | ty::Slice(ety) => {
195195
// single-element containers, behave like their element
196-
rustc::middle::recursion_limit::guarantee_one_mb_stack_left(|| {
196+
rustc::middle::recursion_limit::ensure_sufficient_stack(|| {
197197
dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ety)
198198
})
199199
}
200200

201201
ty::Tuple(tys) => tys.iter()
202-
.map(|ty| rustc::middle::recursion_limit::guarantee_one_mb_stack_left(|| {
202+
.map(|ty| rustc::middle::recursion_limit::ensure_sufficient_stack(|| {
203203
dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ty)
204204
}))
205205
.collect(),
206206

207207
ty::Closure(def_id, substs) => substs
208208
.upvar_tys(def_id, tcx)
209-
.map(|ty| rustc::middle::recursion_limit::guarantee_one_mb_stack_left(|| {
209+
.map(|ty| rustc::middle::recursion_limit::ensure_sufficient_stack(|| {
210210
dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ty)
211211
}))
212212
.collect(),

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
9494
use rustc::infer::opaque_types::OpaqueTypeDecl;
9595
use rustc::infer::type_variable::{TypeVariableOrigin};
9696
use rustc::middle::region;
97-
use rustc::middle::recursion_limit::guarantee_one_mb_stack_left;
97+
use rustc::middle::recursion_limit::ensure_sufficient_stack;
9898
use rustc::mir::interpret::{ConstValue, GlobalId};
9999
use rustc::ty::subst::{CanonicalUserSubsts, UnpackedKind, Subst, Substs,
100100
UserSelfTy, UserSubsts};
@@ -3752,7 +3752,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37523752
self.diverges.set(Diverges::Maybe);
37533753
self.has_errors.set(false);
37543754

3755-
let ty = guarantee_one_mb_stack_left(|| self.check_expr_kind(expr, expected, needs));
3755+
let ty = ensure_sufficient_stack(|| self.check_expr_kind(expr, expected, needs));
37563756

37573757
// Warn for non-block expressions with diverging children.
37583758
match expr.node {

0 commit comments

Comments
 (0)