Skip to content

Commit 2106b63

Browse files
committed
Auto merge of rust-lang#117335 - workingjubilee:rollup-jsomm41, r=workingjubilee
Rollup of 5 pull requests Successful merges: - rust-lang#115773 (tvOS simulator support on Apple Silicon for rustc) - rust-lang#117162 (Remove `cfg_match` from the prelude) - rust-lang#117311 (-Zunpretty help: add missing possible values) - rust-lang#117316 (Mark constructor of `BinaryHeap` as const fn) - rust-lang#117319 (explain why we don't inline when target features differ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2cad938 + f907d0e commit 2106b63

File tree

10 files changed

+138
-92
lines changed

10 files changed

+138
-92
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
28802880
}
28812881

28822882
let sdk_name = match (arch.as_ref(), os.as_ref()) {
2883+
("aarch64", "tvos") if llvm_target.ends_with("-simulator") => "appletvsimulator",
28832884
("aarch64", "tvos") => "appletvos",
28842885
("x86_64", "tvos") => "appletvsimulator",
28852886
("arm", "ios") => "iphoneos",

compiler/rustc_mir_transform/src/inline.rs

+5
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ impl<'tcx> Inliner<'tcx> {
439439
}
440440

441441
if callee_attrs.target_features != self.codegen_fn_attrs.target_features {
442+
// In general it is not correct to inline a callee with target features that are a
443+
// subset of the caller. This is because the callee might contain calls, and the ABI of
444+
// those calls depends on the target features of the surrounding function. By moving a
445+
// `Call` terminator from one MIR body to another with more target features, we might
446+
// change the ABI of that call!
442447
return Err("incompatible target features");
443448
}
444449

compiler/rustc_session/src/options.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,7 @@ written to standard error output)"),
18991899
`hir` (the HIR), `hir,identified`,
19001900
`hir,typed` (HIR with types for each node),
19011901
`hir-tree` (dump the raw HIR),
1902+
`thir-tree`, `thir-flat`,
19021903
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
19031904
unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
19041905
"enable unsound and buggy MIR optimizations (default: no)"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use super::apple_base::{opts, tvos_sim_llvm_target, Arch};
2+
use crate::spec::{FramePointer, Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let arch = Arch::Arm64_sim;
6+
Target {
7+
llvm_target: tvos_sim_llvm_target(arch).into(),
8+
pointer_width: 64,
9+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
10+
arch: arch.target_arch(),
11+
options: TargetOptions {
12+
features: "+neon,+fp-armv8,+apple-a7".into(),
13+
max_atomic_width: Some(128),
14+
forces_embed_bitcode: true,
15+
frame_pointer: FramePointer::NonLeaf,
16+
// Taken from (and slightly modified) the aarch64-apple-ios-sim spec which says:
17+
// Taken from a clang build on Xcode 11.4.1.
18+
// These arguments are not actually invoked - they just have
19+
// to look right to pass App Store validation.
20+
bitcode_llvm_cmdline: "-triple\0\
21+
arm64-apple-tvos15.0-simulator\0\
22+
-emit-obj\0\
23+
-disable-llvm-passes\0\
24+
-target-abi\0\
25+
darwinpcs\0\
26+
-Os\0"
27+
.into(),
28+
..opts("tvos", arch)
29+
},
30+
}
31+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,7 @@ supported_targets! {
16031603
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
16041604
("aarch64-apple-ios-sim", aarch64_apple_ios_sim),
16051605
("aarch64-apple-tvos", aarch64_apple_tvos),
1606+
("aarch64-apple-tvos-sim", aarch64_apple_tvos_sim),
16061607
("x86_64-apple-tvos", x86_64_apple_tvos),
16071608

16081609
("armv7k-apple-watchos", armv7k_apple_watchos),

library/alloc/src/collections/binary_heap/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ impl<T: Ord> BinaryHeap<T> {
434434
/// heap.push(4);
435435
/// ```
436436
#[stable(feature = "rust1", since = "1.0.0")]
437+
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
437438
#[must_use]
438-
pub fn new() -> BinaryHeap<T> {
439+
pub const fn new() -> BinaryHeap<T> {
439440
BinaryHeap { data: vec![] }
440441
}
441442

@@ -477,8 +478,9 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
477478
/// heap.push(4);
478479
/// ```
479480
#[unstable(feature = "allocator_api", issue = "32838")]
481+
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
480482
#[must_use]
481-
pub fn new_in(alloc: A) -> BinaryHeap<T, A> {
483+
pub const fn new_in(alloc: A) -> BinaryHeap<T, A> {
482484
BinaryHeap { data: Vec::new_in(alloc) }
483485
}
484486

library/core/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ pub mod assert_matches {
290290
pub use crate::macros::{assert_matches, debug_assert_matches};
291291
}
292292

293+
#[unstable(feature = "cfg_match", issue = "115585")]
294+
pub use crate::macros::cfg_match;
295+
293296
#[macro_use]
294297
mod internal_macros;
295298

library/core/src/macros/mod.rs

+88-89
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,94 @@ pub macro assert_matches {
168168
},
169169
}
170170

171+
/// A macro for defining `#[cfg]` match-like statements.
172+
///
173+
/// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
174+
/// `#[cfg]` cases, emitting the implementation which matches first.
175+
///
176+
/// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
177+
/// without having to rewrite each clause multiple times.
178+
///
179+
/// Trailing `_` wildcard match arms are **optional** and they indicate a fallback branch when
180+
/// all previous declarations do not evaluate to true.
181+
///
182+
/// # Example
183+
///
184+
/// ```
185+
/// #![feature(cfg_match)]
186+
///
187+
/// cfg_match! {
188+
/// cfg(unix) => {
189+
/// fn foo() { /* unix specific functionality */ }
190+
/// }
191+
/// cfg(target_pointer_width = "32") => {
192+
/// fn foo() { /* non-unix, 32-bit functionality */ }
193+
/// }
194+
/// _ => {
195+
/// fn foo() { /* fallback implementation */ }
196+
/// }
197+
/// }
198+
/// ```
199+
#[unstable(feature = "cfg_match", issue = "115585")]
200+
#[rustc_diagnostic_item = "cfg_match"]
201+
pub macro cfg_match {
202+
// with a final wildcard
203+
(
204+
$(cfg($initial_meta:meta) => { $($initial_tokens:item)* })+
205+
_ => { $($extra_tokens:item)* }
206+
) => {
207+
cfg_match! {
208+
@__items ();
209+
$((($initial_meta) ($($initial_tokens)*)),)+
210+
(() ($($extra_tokens)*)),
211+
}
212+
},
213+
214+
// without a final wildcard
215+
(
216+
$(cfg($extra_meta:meta) => { $($extra_tokens:item)* })*
217+
) => {
218+
cfg_match! {
219+
@__items ();
220+
$((($extra_meta) ($($extra_tokens)*)),)*
221+
}
222+
},
223+
224+
// Internal and recursive macro to emit all the items
225+
//
226+
// Collects all the previous cfgs in a list at the beginning, so they can be
227+
// negated. After the semicolon is all the remaining items.
228+
(@__items ($($_:meta,)*);) => {},
229+
(
230+
@__items ($($no:meta,)*);
231+
(($($yes:meta)?) ($($tokens:item)*)),
232+
$($rest:tt,)*
233+
) => {
234+
// Emit all items within one block, applying an appropriate #[cfg]. The
235+
// #[cfg] will require all `$yes` matchers specified and must also negate
236+
// all previous matchers.
237+
#[cfg(all(
238+
$($yes,)?
239+
not(any($($no),*))
240+
))]
241+
cfg_match! { @__identity $($tokens)* }
242+
243+
// Recurse to emit all other items in `$rest`, and when we do so add all
244+
// our `$yes` matchers to the list of `$no` matchers as future emissions
245+
// will have to negate everything we just matched as well.
246+
cfg_match! {
247+
@__items ($($no,)* $($yes,)?);
248+
$($rest,)*
249+
}
250+
},
251+
252+
// Internal macro to make __apply work out right for different match types,
253+
// because of how macros match/expand stuff.
254+
(@__identity $($tokens:item)*) => {
255+
$($tokens)*
256+
}
257+
}
258+
171259
/// Asserts that a boolean expression is `true` at runtime.
172260
///
173261
/// This will invoke the [`panic!`] macro if the provided expression cannot be
@@ -321,95 +409,6 @@ pub macro debug_assert_matches($($arg:tt)*) {
321409
}
322410
}
323411

324-
/// A macro for defining `#[cfg]` match-like statements.
325-
///
326-
/// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
327-
/// `#[cfg]` cases, emitting the implementation which matches first.
328-
///
329-
/// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
330-
/// without having to rewrite each clause multiple times.
331-
///
332-
/// Trailing `_` wildcard match arms are **optional** and they indicate a fallback branch when
333-
/// all previous declarations do not evaluate to true.
334-
///
335-
/// # Example
336-
///
337-
/// ```
338-
/// #![feature(cfg_match)]
339-
///
340-
/// cfg_match! {
341-
/// cfg(unix) => {
342-
/// fn foo() { /* unix specific functionality */ }
343-
/// }
344-
/// cfg(target_pointer_width = "32") => {
345-
/// fn foo() { /* non-unix, 32-bit functionality */ }
346-
/// }
347-
/// _ => {
348-
/// fn foo() { /* fallback implementation */ }
349-
/// }
350-
/// }
351-
/// ```
352-
#[macro_export]
353-
#[unstable(feature = "cfg_match", issue = "115585")]
354-
#[rustc_diagnostic_item = "cfg_match"]
355-
macro_rules! cfg_match {
356-
// with a final wildcard
357-
(
358-
$(cfg($initial_meta:meta) => { $($initial_tokens:item)* })+
359-
_ => { $($extra_tokens:item)* }
360-
) => {
361-
cfg_match! {
362-
@__items ();
363-
$((($initial_meta) ($($initial_tokens)*)),)+
364-
(() ($($extra_tokens)*)),
365-
}
366-
};
367-
368-
// without a final wildcard
369-
(
370-
$(cfg($extra_meta:meta) => { $($extra_tokens:item)* })*
371-
) => {
372-
cfg_match! {
373-
@__items ();
374-
$((($extra_meta) ($($extra_tokens)*)),)*
375-
}
376-
};
377-
378-
// Internal and recursive macro to emit all the items
379-
//
380-
// Collects all the previous cfgs in a list at the beginning, so they can be
381-
// negated. After the semicolon is all the remaining items.
382-
(@__items ($($_:meta,)*);) => {};
383-
(
384-
@__items ($($no:meta,)*);
385-
(($($yes:meta)?) ($($tokens:item)*)),
386-
$($rest:tt,)*
387-
) => {
388-
// Emit all items within one block, applying an appropriate #[cfg]. The
389-
// #[cfg] will require all `$yes` matchers specified and must also negate
390-
// all previous matchers.
391-
#[cfg(all(
392-
$($yes,)?
393-
not(any($($no),*))
394-
))]
395-
cfg_match! { @__identity $($tokens)* }
396-
397-
// Recurse to emit all other items in `$rest`, and when we do so add all
398-
// our `$yes` matchers to the list of `$no` matchers as future emissions
399-
// will have to negate everything we just matched as well.
400-
cfg_match! {
401-
@__items ($($no,)* $($yes,)?);
402-
$($rest,)*
403-
}
404-
};
405-
406-
// Internal macro to make __apply work out right for different match types,
407-
// because of how macros match/expand stuff.
408-
(@__identity $($tokens:item)*) => {
409-
$($tokens)*
410-
};
411-
}
412-
413412
/// Returns whether the given expression matches any of the given patterns.
414413
///
415414
/// Like in a `match` expression, the pattern can be optionally followed by `if`

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ target | std | host | notes
217217
-------|:---:|:----:|-------
218218
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
219219
[`aarch64-apple-tvos`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS
220+
[`aarch64-apple-tvos-sim`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS Simulator
220221
[`aarch64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | ARM64 Apple WatchOS Simulator
221222
[`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3
222223
[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon

src/doc/rustc/src/platform-support/apple-tvos.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The targets can be built by enabling them for a `rustc` build in `config.toml`,
5252
```toml
5353
[build]
5454
build-stage = 1
55-
target = ["aarch64-apple-tvos", "x86_64-apple-tvos"]
55+
target = ["aarch64-apple-tvos", "x86_64-apple-tvos", "aarch64-apple-tvos-sim"]
5656
```
5757

5858
It's possible that cargo under `-Zbuild-std` may also be used to target them.
@@ -67,6 +67,8 @@ Rust programs can be built for these targets
6767
$ rustc --target aarch64-apple-tvos your-code.rs
6868
...
6969
$ rustc --target x86_64-apple-tvos your-code.rs
70+
...
71+
$ rustc --target aarch64-apple-tvos-sim your-code.rs
7072
```
7173

7274
## Testing

0 commit comments

Comments
 (0)