Skip to content

Commit cfb7841

Browse files
committed
implement checks for tail calls
this implements checks necessary to guarantee that we can actually perform a tail call. while extremely restrictive, this is what is documented in the RFC, and all these checks are needed for one reason or another.
1 parent c1cfab2 commit cfb7841

18 files changed

+848
-0
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ rustc_queries! {
916916
cache_on_disk_if { true }
917917
}
918918

919+
/// Checks well-formedness of tail calls (`become f()`).
920+
query check_tail_calls(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
921+
desc { |tcx| "tail-call-checking `{}`", tcx.def_path_str(key) }
922+
cache_on_disk_if { true }
923+
}
924+
919925
/// Returns the types assumed to be well formed while "inside" of the given item.
920926
///
921927
/// Note that we've liberated the late bound regions of function signatures, so

compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub(crate) fn mir_build<'tcx>(tcx: TyCtxtAt<'tcx>, def: LocalDefId) -> Body<'tcx
5050
return construct_error(tcx, def, e);
5151
}
5252

53+
if let Err(err) = tcx.check_tail_calls(def) {
54+
return construct_error(tcx, def, err);
55+
}
56+
5357
let body = match tcx.thir_body(def) {
5458
Err(error_reported) => construct_error(tcx, def, error_reported),
5559
Ok((thir, expr)) => {

0 commit comments

Comments
 (0)