diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-05 23:35:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-05 23:35:23 +0200 |
| commit | 83155b39002bd77a80b93e7698fba90ab662101a (patch) | |
| tree | cc3fac9fe0c6b7a9844825b3296910c6a0fde334 /compiler | |
| parent | 9cb3688f1febd9234d880759ed7cf852015af206 (diff) | |
| parent | 212417b87f8415d92ea0a365605011050a555e28 (diff) | |
| download | rust-83155b39002bd77a80b93e7698fba90ab662101a.tar.gz rust-83155b39002bd77a80b93e7698fba90ab662101a.zip | |
Rollup merge of #128688 - RalfJung:custom-mir-tail-calls, r=compiler-errors
custom MIR: add support for tail calls Cc ``@WaffleLapkin``
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/custom/parse/instruction.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index 3d4b706aa65..56896d945e5 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -75,6 +75,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { @call(mir_call, args) => { self.parse_call(args) }, + @call(mir_tail_call, args) => { + self.parse_tail_call(args) + }, ExprKind::Match { scrutinee, arms, .. } => { let discr = self.parse_operand(*scrutinee)?; self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t }) @@ -187,6 +190,25 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { ) } + fn parse_tail_call(&self, args: &[ExprId]) -> PResult<TerminatorKind<'tcx>> { + parse_by_kind!(self, args[0], _, "tail call", + ExprKind::Call { fun, args, fn_span, .. } => { + let fun = self.parse_operand(*fun)?; + let args = args + .iter() + .map(|arg| + Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } ) + ) + .collect::<PResult<Box<[_]>>>()?; + Ok(TerminatorKind::TailCall { + func: fun, + args, + fn_span: *fn_span, + }) + }, + ) + } + fn parse_rvalue(&self, expr_id: ExprId) -> PResult<Rvalue<'tcx>> { parse_by_kind!(self, expr_id, expr, "rvalue", @call(mir_discriminant, args) => self.parse_place(args[0]).map(Rvalue::Discriminant), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9977fa7425a..94cf21da4ef 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1216,6 +1216,7 @@ symbols! { mir_static_mut, mir_storage_dead, mir_storage_live, + mir_tail_call, mir_unreachable, mir_unwind_cleanup, mir_unwind_continue, |
