Skip to content

Commit 767f594

Browse files
committed
Auto merge of #60460 - Centril:rollup-gz5bc8i, r=Centril
Rollup of 7 pull requests Successful merges: - #59634 (Added an explanation for the E0704 error.) - #60348 (move some functions from parser.rs to diagostics.rs) - #60385 (Emit metadata files earlier) - #60428 (Refactor `eval_body_using_ecx` so that it doesn't need to query for MIR) - #60437 (Ensure that drop order of `async fn` matches `fn` and that users cannot refer to generated arguments.) - #60439 (doc: Warn about possible zombie apocalypse) - #60452 (Remove Context and ContextKind) Failed merges: r? @ghost
2 parents ea68bee + 4ff1234 commit 767f594

File tree

35 files changed

+1132
-789
lines changed

35 files changed

+1132
-789
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,7 @@ dependencies = [
28022802
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
28032803
"rustc_allocator 0.0.0",
28042804
"rustc_borrowck 0.0.0",
2805+
"rustc_codegen_ssa 0.0.0",
28052806
"rustc_codegen_utils 0.0.0",
28062807
"rustc_data_structures 0.0.0",
28072808
"rustc_errors 0.0.0",
@@ -2821,6 +2822,7 @@ dependencies = [
28212822
"syntax 0.0.0",
28222823
"syntax_ext 0.0.0",
28232824
"syntax_pos 0.0.0",
2825+
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
28242826
]
28252827

28262828
[[package]]

src/librustc/hir/lowering.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -2996,8 +2996,33 @@ impl<'a> LoweringContext<'a> {
29962996
if let IsAsync::Async { closure_id, ref arguments, .. } = asyncness {
29972997
let mut body = body.clone();
29982998

2999+
// Async function arguments are lowered into the closure body so that they are
3000+
// captured and so that the drop order matches the equivalent non-async functions.
3001+
//
3002+
// async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
3003+
// async move {
3004+
// }
3005+
// }
3006+
//
3007+
// // ...becomes...
3008+
// fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
3009+
// async move {
3010+
// let __arg2 = __arg2;
3011+
// let <pattern> = __arg2;
3012+
// let __arg1 = __arg1;
3013+
// let <pattern> = __arg1;
3014+
// let __arg0 = __arg0;
3015+
// let <pattern> = __arg0;
3016+
// }
3017+
// }
3018+
//
3019+
// If `<pattern>` is a simple ident, then it is lowered to a single
3020+
// `let <pattern> = <pattern>;` statement as an optimization.
29993021
for a in arguments.iter().rev() {
3000-
body.stmts.insert(0, a.stmt.clone());
3022+
if let Some(pat_stmt) = a.pat_stmt.clone() {
3023+
body.stmts.insert(0, pat_stmt);
3024+
}
3025+
body.stmts.insert(0, a.move_stmt.clone());
30013026
}
30023027

30033028
let async_expr = this.make_async_expr(
@@ -3093,7 +3118,11 @@ impl<'a> LoweringContext<'a> {
30933118
let mut decl = decl.clone();
30943119
// Replace the arguments of this async function with the generated
30953120
// arguments that will be moved into the closure.
3096-
decl.inputs = arguments.clone().drain(..).map(|a| a.arg).collect();
3121+
for (i, a) in arguments.clone().drain(..).enumerate() {
3122+
if let Some(arg) = a.arg {
3123+
decl.inputs[i] = arg;
3124+
}
3125+
}
30973126
lower_fn(&decl)
30983127
} else {
30993128
lower_fn(decl)
@@ -3590,7 +3619,11 @@ impl<'a> LoweringContext<'a> {
35903619
let mut sig = sig.clone();
35913620
// Replace the arguments of this async function with the generated
35923621
// arguments that will be moved into the closure.
3593-
sig.decl.inputs = arguments.clone().drain(..).map(|a| a.arg).collect();
3622+
for (i, a) in arguments.clone().drain(..).enumerate() {
3623+
if let Some(arg) = a.arg {
3624+
sig.decl.inputs[i] = arg;
3625+
}
3626+
}
35943627
lower_method(&sig)
35953628
} else {
35963629
lower_method(sig)

src/librustc/hir/map/def_collector.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ impl<'a> DefCollector<'a> {
9494
// Walk the generated arguments for the `async fn`.
9595
for a in arguments {
9696
use visit::Visitor;
97-
this.visit_ty(&a.arg.ty);
97+
if let Some(arg) = &a.arg {
98+
this.visit_ty(&arg.ty);
99+
}
98100
}
99101

100102
// We do not invoke `walk_fn_decl` as this will walk the arguments that are being
@@ -105,10 +107,13 @@ impl<'a> DefCollector<'a> {
105107
*closure_id, DefPathData::ClosureExpr, REGULAR_SPACE, span,
106108
);
107109
this.with_parent(closure_def, |this| {
110+
use visit::Visitor;
111+
// Walk each of the generated statements before the regular block body.
108112
for a in arguments {
109-
use visit::Visitor;
110-
// Walk each of the generated statements before the regular block body.
111-
this.visit_stmt(&a.stmt);
113+
this.visit_stmt(&a.move_stmt);
114+
if let Some(pat_stmt) = &a.pat_stmt {
115+
this.visit_stmt(&pat_stmt);
116+
}
112117
}
113118

114119
visit::walk_block(this, &body);

src/librustc/lint/context.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1334,14 +1334,19 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
13341334
if let ast::IsAsync::Async { ref arguments, .. } = header.asyncness.node {
13351335
for a in arguments {
13361336
// Visit the argument..
1337-
self.visit_pat(&a.arg.pat);
1338-
if let ast::ArgSource::AsyncFn(pat) = &a.arg.source {
1339-
self.visit_pat(pat);
1337+
if let Some(arg) = &a.arg {
1338+
self.visit_pat(&arg.pat);
1339+
if let ast::ArgSource::AsyncFn(pat) = &arg.source {
1340+
self.visit_pat(pat);
1341+
}
1342+
self.visit_ty(&arg.ty);
13401343
}
1341-
self.visit_ty(&a.arg.ty);
13421344

13431345
// ..and the statement.
1344-
self.visit_stmt(&a.stmt);
1346+
self.visit_stmt(&a.move_stmt);
1347+
if let Some(pat_stmt) = &a.pat_stmt {
1348+
self.visit_stmt(&pat_stmt);
1349+
}
13451350
}
13461351
}
13471352
}

src/librustc_codegen_llvm/base.rs

+4-36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc::mir::mono::{Linkage, Visibility, Stats};
2828
use rustc::middle::cstore::{EncodedMetadata};
2929
use rustc::ty::TyCtxt;
3030
use rustc::middle::exported_symbols;
31-
use rustc::session::config::{self, DebugInfo};
31+
use rustc::session::config::DebugInfo;
3232
use rustc_codegen_ssa::mono_item::MonoItemExt;
3333
use rustc_data_structures::small_c_str::SmallCStr;
3434

@@ -42,47 +42,16 @@ use rustc::hir::CodegenFnAttrs;
4242

4343
use crate::value::Value;
4444

45-
46-
pub fn write_metadata<'a, 'gcx>(
45+
pub fn write_compressed_metadata<'a, 'gcx>(
4746
tcx: TyCtxt<'a, 'gcx, 'gcx>,
47+
metadata: &EncodedMetadata,
4848
llvm_module: &mut ModuleLlvm
49-
) -> EncodedMetadata {
49+
) {
5050
use std::io::Write;
5151
use flate2::Compression;
5252
use flate2::write::DeflateEncoder;
5353

5454
let (metadata_llcx, metadata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
55-
56-
#[derive(PartialEq, Eq, PartialOrd, Ord)]
57-
enum MetadataKind {
58-
None,
59-
Uncompressed,
60-
Compressed
61-
}
62-
63-
let kind = tcx.sess.crate_types.borrow().iter().map(|ty| {
64-
match *ty {
65-
config::CrateType::Executable |
66-
config::CrateType::Staticlib |
67-
config::CrateType::Cdylib => MetadataKind::None,
68-
69-
config::CrateType::Rlib => MetadataKind::Uncompressed,
70-
71-
config::CrateType::Dylib |
72-
config::CrateType::ProcMacro => MetadataKind::Compressed,
73-
}
74-
}).max().unwrap_or(MetadataKind::None);
75-
76-
if kind == MetadataKind::None {
77-
return EncodedMetadata::new();
78-
}
79-
80-
let metadata = tcx.encode_metadata();
81-
if kind == MetadataKind::Uncompressed {
82-
return metadata;
83-
}
84-
85-
assert!(kind == MetadataKind::Compressed);
8655
let mut compressed = tcx.metadata_encoding_version();
8756
DeflateEncoder::new(&mut compressed, Compression::fast())
8857
.write_all(&metadata.raw_data).unwrap();
@@ -107,7 +76,6 @@ pub fn write_metadata<'a, 'gcx>(
10776
let directive = CString::new(directive).unwrap();
10877
llvm::LLVMSetModuleInlineAsm(metadata_llmod, directive.as_ptr())
10978
}
110-
return metadata;
11179
}
11280

11381
pub struct ValueIter<'ll> {

src/librustc_codegen_llvm/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
110110
ModuleLlvm::new_metadata(tcx, mod_name)
111111
}
112112

113-
fn write_metadata<'b, 'gcx>(
113+
fn write_compressed_metadata<'b, 'gcx>(
114114
&self,
115115
tcx: TyCtxt<'b, 'gcx, 'gcx>,
116-
metadata: &mut ModuleLlvm
117-
) -> EncodedMetadata {
118-
base::write_metadata(tcx, metadata)
116+
metadata: &EncodedMetadata,
117+
llvm_module: &mut ModuleLlvm
118+
) {
119+
base::write_compressed_metadata(tcx, metadata, llvm_module)
119120
}
120121
fn codegen_allocator<'b, 'gcx>(
121122
&self,
@@ -289,9 +290,12 @@ impl CodegenBackend for LlvmCodegenBackend {
289290
fn codegen_crate<'b, 'tcx>(
290291
&self,
291292
tcx: TyCtxt<'b, 'tcx, 'tcx>,
293+
metadata: EncodedMetadata,
294+
need_metadata_module: bool,
292295
rx: mpsc::Receiver<Box<dyn Any + Send>>
293296
) -> Box<dyn Any> {
294-
box rustc_codegen_ssa::base::codegen_crate(LlvmCodegenBackend(()), tcx, rx)
297+
box rustc_codegen_ssa::base::codegen_crate(
298+
LlvmCodegenBackend(()), tcx, metadata, need_metadata_module, rx)
295299
}
296300

297301
fn join_codegen_and_link(

0 commit comments

Comments
 (0)