Skip to content

Commit 324681b

Browse files
authored
Rollup merge of #142047 - cuviper:s390x-stack, r=oli-obk
Ensure stack in two places that affect s390x In our Fedora s390x test results, we found two tests that started hitting stack overflows in the 1.87.0 update. It seems to be related in some part to our use of PGO as well, probably inlining more into stack frames that were already recursive. The main points of recursion that I identified were: - `ui/parser/survive-peano-lesson-queue.rs` in `ThirBuildCx::mirror_exprs` - `ui/associated-consts/issue-93775.rs` in `Parser::parse_ty` A couple new `ensure_sufficient_stack` calls will solve these tests.
2 parents 29954af + af2a85b commit 324681b

File tree

2 files changed

+16
-9
lines changed
  • compiler
    • rustc_mir_build/src/thir/cx
    • rustc_parse/src/parser

2 files changed

+16
-9
lines changed

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl<'tcx> ThirBuildCx<'tcx> {
3838
}
3939

4040
pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
41-
exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect()
41+
// `mirror_exprs` may also recurse deeply, so it needs protection from stack overflow.
42+
// Note that we *could* forward to `mirror_expr` for that, but we can consolidate the
43+
// overhead of stack growth by doing it outside the iteration.
44+
ensure_sufficient_stack(|| exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect())
4245
}
4346

4447
#[instrument(level = "trace", skip(self, hir_expr))]

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::{
77
Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty,
88
TyKind, UnsafeBinderTy,
99
};
10+
use rustc_data_structures::stack::ensure_sufficient_stack;
1011
use rustc_errors::{Applicability, Diag, PResult};
1112
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
1213
use thin_vec::{ThinVec, thin_vec};
@@ -104,14 +105,17 @@ fn can_begin_dyn_bound_in_edition_2015(t: &Token) -> bool {
104105
impl<'a> Parser<'a> {
105106
/// Parses a type.
106107
pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
107-
self.parse_ty_common(
108-
AllowPlus::Yes,
109-
AllowCVariadic::No,
110-
RecoverQPath::Yes,
111-
RecoverReturnSign::Yes,
112-
None,
113-
RecoverQuestionMark::Yes,
114-
)
108+
// Make sure deeply nested types don't overflow the stack.
109+
ensure_sufficient_stack(|| {
110+
self.parse_ty_common(
111+
AllowPlus::Yes,
112+
AllowCVariadic::No,
113+
RecoverQPath::Yes,
114+
RecoverReturnSign::Yes,
115+
None,
116+
RecoverQuestionMark::Yes,
117+
)
118+
})
115119
}
116120

117121
pub(super) fn parse_ty_with_generics_recovery(

0 commit comments

Comments
 (0)