Skip to content

Commit b364405

Browse files
committed
Auto merge of rust-lang#106162 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backport rollup * Revert "Replace usage of ResumeTy in async lowering with Context" rust-lang#105915 * Don't copy symbols from dylibs with -Zdylib-lto rust-lang#105800 * rustdoc: Only hide lines starting with # in rust code blocks rust-lang#105539 * Mangle "main" as "__main_void" on wasm32-wasi rust-lang#105468 r? `@ghost`
2 parents 352eb59 + dbc1048 commit b364405

21 files changed

+141
-74
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+21-36
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616
use rustc_hir::definitions::DefPathData;
1717
use rustc_session::errors::report_lit_error;
1818
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
19-
use rustc_span::symbol::{kw, sym, Ident};
19+
use rustc_span::symbol::{sym, Ident};
2020
use rustc_span::DUMMY_SP;
2121
use thin_vec::thin_vec;
2222

@@ -585,38 +585,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
585585
) -> hir::ExprKind<'hir> {
586586
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
587587

588-
// Resume argument type, which should be `&mut Context<'_>`.
589-
// NOTE: Using the `'static` lifetime here is technically cheating.
590-
// The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
591-
// express the fact that we are not storing it across yield-points yet,
592-
// and we would thus run into lifetime errors.
593-
// See <https://github.com/rust-lang/rust/issues/68923>.
594-
// Our lowering makes sure we are not mis-using the `_task_context` input type
595-
// in the sense that we are indeed not using it across yield points. We
596-
// get a fresh `&mut Context` for each resume / call of `Future::poll`.
597-
// This "cheating" was previously done with a `ResumeTy` that contained a raw
598-
// pointer, and a `get_context` accessor that pulled the `Context` lifetimes
599-
// out of thin air.
600-
let context_lifetime_ident = Ident::with_dummy_span(kw::StaticLifetime);
601-
let context_lifetime = self.arena.alloc(hir::Lifetime {
602-
hir_id: self.next_id(),
603-
ident: context_lifetime_ident,
604-
res: hir::LifetimeName::Static,
605-
});
606-
let context_path =
607-
hir::QPath::LangItem(hir::LangItem::Context, self.lower_span(span), None);
608-
let context_ty = hir::MutTy {
609-
ty: self.arena.alloc(hir::Ty {
610-
hir_id: self.next_id(),
611-
kind: hir::TyKind::Path(context_path),
612-
span: self.lower_span(span),
613-
}),
614-
mutbl: hir::Mutability::Mut,
615-
};
588+
// Resume argument type: `ResumeTy`
589+
let unstable_span =
590+
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
591+
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
616592
let input_ty = hir::Ty {
617593
hir_id: self.next_id(),
618-
kind: hir::TyKind::Rptr(context_lifetime, context_ty),
619-
span: self.lower_span(span),
594+
kind: hir::TyKind::Path(resume_ty),
595+
span: unstable_span,
620596
};
621597

622598
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -674,9 +650,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
674650
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
675651

676652
let hir_id = self.lower_node_id(closure_node_id);
677-
let unstable_span =
678-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
679653
if track_caller {
654+
let unstable_span = self.mark_span_with_reason(
655+
DesugaringKind::Async,
656+
span,
657+
self.allow_gen_future.clone(),
658+
);
680659
self.lower_attrs(
681660
hir_id,
682661
&[Attribute {
@@ -719,7 +698,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
719698
/// mut __awaitee => loop {
720699
/// match unsafe { ::std::future::Future::poll(
721700
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
722-
/// task_context,
701+
/// ::std::future::get_context(task_context),
723702
/// ) } {
724703
/// ::std::task::Poll::Ready(result) => break result,
725704
/// ::std::task::Poll::Pending => {}
@@ -760,7 +739,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
760739
// unsafe {
761740
// ::std::future::Future::poll(
762741
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
763-
// task_context,
742+
// ::std::future::get_context(task_context),
764743
// )
765744
// }
766745
let poll_expr = {
@@ -778,10 +757,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
778757
arena_vec![self; ref_mut_awaitee],
779758
Some(expr_hir_id),
780759
);
760+
let get_context = self.expr_call_lang_item_fn_mut(
761+
gen_future_span,
762+
hir::LangItem::GetContext,
763+
arena_vec![self; task_context],
764+
Some(expr_hir_id),
765+
);
781766
let call = self.expr_call_lang_item_fn(
782767
span,
783768
hir::LangItem::FuturePoll,
784-
arena_vec![self; new_unchecked, task_context],
769+
arena_vec![self; new_unchecked, get_context],
785770
Some(expr_hir_id),
786771
);
787772
self.arena.alloc(self.expr_unsafe(call))

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub fn each_linked_rlib(
253253
};
254254
for &cnum in crates {
255255
match fmts.get(cnum.as_usize() - 1) {
256-
Some(&Linkage::NotLinked | &Linkage::IncludedFromDylib) => continue,
256+
Some(&Linkage::NotLinked | &Linkage::Dynamic | &Linkage::IncludedFromDylib) => continue,
257257
Some(_) => {}
258258
None => return Err(errors::LinkRlibError::MissingFormat),
259259
}

compiler/rustc_hir/src/lang_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ language_item_table! {
286286

287287
// FIXME(swatinem): the following lang items are used for async lowering and
288288
// should become obsolete eventually.
289+
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
289290
IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
291+
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
290292

291-
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
292293
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
293294

294295
FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

compiler/rustc_span/src/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ symbols! {
165165
Capture,
166166
Center,
167167
Clone,
168-
Context,
169168
Continue,
170169
Copy,
171170
Count,
@@ -265,6 +264,7 @@ symbols! {
265264
Relaxed,
266265
Release,
267266
Result,
267+
ResumeTy,
268268
Return,
269269
Right,
270270
Rust,
@@ -754,6 +754,7 @@ symbols! {
754754
generic_associated_types_extended,
755755
generic_const_exprs,
756756
generic_param_attrs,
757+
get_context,
757758
global_allocator,
758759
global_asm,
759760
globs,

compiler/rustc_target/src/spec/wasm32_wasi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ pub fn target() -> Target {
104104
// `args::args()` makes the WASI API calls itself.
105105
options.main_needs_argc_argv = false;
106106

107+
// And, WASI mangles the name of "main" to distinguish between different
108+
// signatures.
109+
options.entry_name = "__main_void".into();
110+
107111
Target {
108112
llvm_target: "wasm32-wasi".into(),
109113
pointer_width: 32,

library/core/src/future/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use poll_fn::{poll_fn, PollFn};
4444
/// non-Send/Sync as well, and we don't want that.
4545
///
4646
/// It also simplifies the HIR lowering of `.await`.
47-
// FIXME(swatinem): This type can be removed when bumping the bootstrap compiler
47+
#[cfg_attr(not(bootstrap), lang = "ResumeTy")]
4848
#[doc(hidden)]
4949
#[unstable(feature = "gen_future", issue = "50547")]
5050
#[derive(Debug, Copy, Clone)]
@@ -61,7 +61,6 @@ unsafe impl Sync for ResumeTy {}
6161
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
6262
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
6363
// This is `const` to avoid extra errors after we recover from `const async fn`
64-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
6564
#[cfg_attr(bootstrap, lang = "from_generator")]
6665
#[doc(hidden)]
6766
#[unstable(feature = "gen_future", issue = "50547")]
@@ -103,8 +102,7 @@ where
103102
GenFuture(gen)
104103
}
105104

106-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
107-
#[cfg_attr(bootstrap, lang = "get_context")]
105+
#[lang = "get_context"]
108106
#[doc(hidden)]
109107
#[unstable(feature = "gen_future", issue = "50547")]
110108
#[must_use]
@@ -115,10 +113,6 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
115113
unsafe { &mut *cx.0.as_ptr().cast() }
116114
}
117115

118-
// FIXME(swatinem): This fn is currently needed to work around shortcomings
119-
// in type and lifetime inference.
120-
// See the comment at the bottom of `LoweringContext::make_async_expr` and
121-
// <https://github.com/rust-lang/rust/issues/104826>.
122116
#[cfg_attr(not(bootstrap), lang = "identity_future")]
123117
#[doc(hidden)]
124118
#[unstable(feature = "gen_future", issue = "50547")]

library/core/src/task/wake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl RawWakerVTable {
174174
/// Currently, `Context` only serves to provide access to a [`&Waker`](Waker)
175175
/// which can be used to wake the current task.
176176
#[stable(feature = "futures_api", since = "1.36.0")]
177-
#[cfg_attr(not(bootstrap), lang = "Context")]
178177
pub struct Context<'a> {
179178
waker: &'a Waker,
180179
// Ensure we future-proof against variance changes by forcing

src/librustdoc/html/markdown.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
246246
_ => {}
247247
}
248248
}
249-
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
250-
let text = lines.intersperse("\n".into()).collect::<String>();
251249

252250
let parse_result = match kind {
253251
CodeBlockKind::Fenced(ref lang) => {
@@ -260,7 +258,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
260258
<pre class=\"language-{}\"><code>{}</code></pre>\
261259
</div>",
262260
lang,
263-
Escape(&text),
261+
Escape(&origtext),
264262
)
265263
.into(),
266264
));
@@ -270,6 +268,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
270268
CodeBlockKind::Indented => Default::default(),
271269
};
272270

271+
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
272+
let text = lines.intersperse("\n".into()).collect::<String>();
273+
273274
compile_fail = parse_result.compile_fail;
274275
should_panic = parse_result.should_panic;
275276
ignore = parse_result.ignore;

src/librustdoc/html/markdown/tests.rs

+37
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,40 @@ fn test_find_testable_code_line() {
309309
t("```rust\n```\n```rust\n```", &[1, 3]);
310310
t("```rust\n```\n ```rust\n```", &[1, 3]);
311311
}
312+
313+
#[test]
314+
fn test_ascii_with_prepending_hashtag() {
315+
fn t(input: &str, expect: &str) {
316+
let mut map = IdMap::new();
317+
let output = Markdown {
318+
content: input,
319+
links: &[],
320+
ids: &mut map,
321+
error_codes: ErrorCodes::Yes,
322+
edition: DEFAULT_EDITION,
323+
playground: &None,
324+
heading_offset: HeadingOffset::H2,
325+
}
326+
.into_string();
327+
assert_eq!(output, expect, "original: {}", input);
328+
}
329+
330+
t(
331+
r#"```ascii
332+
#..#.####.#....#.....##..
333+
#..#.#....#....#....#..#.
334+
####.###..#....#....#..#.
335+
#..#.#....#....#....#..#.
336+
#..#.#....#....#....#..#.
337+
#..#.####.####.####..##..
338+
```"#,
339+
"<div class=\"example-wrap\"><pre class=\"language-ascii\"><code>\
340+
#..#.####.#....#.....##..
341+
#..#.#....#....#....#..#.
342+
####.###..#....#....#..#.
343+
#..#.#....#....#....#..#.
344+
#..#.#....#....#....#..#.
345+
#..#.####.####.####..##..
346+
</code></pre></div>",
347+
);
348+
}

src/test/ui/async-await/async-await-let-else.drop-tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | async fn bar2<T>(_: T) -> ! {
4040
LL | | panic!()
4141
LL | | }
4242
| |_^
43-
= note: required because it captures the following types: `&mut Context<'_>`, `Option<bool>`, `impl Future<Output = !>`, `()`
43+
= note: required because it captures the following types: `ResumeTy`, `Option<bool>`, `impl Future<Output = !>`, `()`
4444
note: required because it's used within this `async fn` body
4545
--> $DIR/async-await-let-else.rs:21:32
4646
|

src/test/ui/async-await/issue-68112.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC
5757
|
5858
LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>`
60+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>`
6161
note: required because it's used within this `async` block
6262
--> $DIR/issue-68112.rs:60:20
6363
|

src/test/ui/async-await/issue-68112.no_drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC
5757
|
5858
LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>`
60+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>`
6161
note: required because it's used within this `async` block
6262
--> $DIR/issue-68112.rs:60:20
6363
|

src/test/ui/async-await/issue-69446-fnmut-capture.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ LL | | });
1414
|
1515
= note: `FnMut` closures only have access to their captured variables while they are executing...
1616
= note: ...therefore, they cannot allow references to captured variables to escape
17-
= note: requirement occurs because of a mutable reference to `Context<'_>`
18-
= note: mutable references are invariant over their type parameter
19-
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
2017

2118
error: aborting due to previous error
2219

src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
1818
| ___________________________________________________________________^
1919
LL | | }
2020
| |_^
21-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = ()>`, `()`
21+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = ()>`, `()`
2222
note: required because it's used within this `async` block
2323
--> $DIR/issue-70935-complex-spans.rs:16:5
2424
|

src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | async fn foo() {
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`
14-
= note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `()`, `impl Future<Output = ()>`
14+
= note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `()`, `impl Future<Output = ()>`
1515
note: required because it's used within this `async fn` body
1616
--> $DIR/partial-drop-partial-reinit.rs:31:16
1717
|

src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | async fn foo() {
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`
14-
= note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `impl Future<Output = ()>`, `()`
14+
= note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `impl Future<Output = ()>`, `()`
1515
note: required because it's used within this `async fn` body
1616
--> $DIR/partial-drop-partial-reinit.rs:31:16
1717
|
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Auxiliary crate for test issue-105637: the LTOed dylib which had duplicate symbols from libstd,
2+
// breaking the panic hook feature.
3+
//
4+
// This simulates the `rustc_driver` crate, and the main crate simulates rustc's main binary hooking
5+
// into this driver.
6+
7+
// compile-flags: -Zdylib-lto -C lto=thin
8+
9+
use std::panic;
10+
11+
pub fn main() {
12+
// Install the hook we want to see executed
13+
panic::set_hook(Box::new(|_| {
14+
eprintln!("LTOed auxiliary crate panic hook");
15+
}));
16+
17+
// Trigger the panic hook with an ICE
18+
run_compiler();
19+
}
20+
21+
fn run_compiler() {
22+
panic!("ICEing");
23+
}

src/test/ui/lto/issue-105637.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Regression test for issue #105637: `-Zdylib-lto` with LTO duplicated symbols from other dylibs,
2+
// in this case from libstd.
3+
//
4+
// That manifested as both `rustc_driver` and rustc's "main" (`compiler/rustc`) having their own
5+
// `std::panicking::HOOK` static, and the hook in rustc's main (the default stdlib's) being executed
6+
// when rustc ICEs, instead of the overriden hook from `rustc_driver` (which also displays the query
7+
// stack and information on how to open a GH issue for the encountered ICE).
8+
//
9+
// In this test, we reproduce this setup by installing a panic hook in both the main and an LTOed
10+
// dylib: the last hook set should be the one being executed, the dylib's.
11+
12+
// aux-build: thinlto-dylib.rs
13+
// run-fail
14+
// check-run-results
15+
16+
extern crate thinlto_dylib;
17+
18+
use std::panic;
19+
20+
fn main() {
21+
// We don't want to see this panic hook executed
22+
std::panic::set_hook(Box::new(|_| {
23+
eprintln!("main crate panic hook");
24+
}));
25+
26+
// Have the LTOed dylib install its own hook and panic, we want to see its hook executed.
27+
thinlto_dylib::main();
28+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LTOed auxiliary crate panic hook

0 commit comments

Comments
 (0)