Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 503dfcf

Browse files
committedJun 9, 2024·
Auto merge of rust-lang#126202 - jieyouxu:rollup-2ixnizz, r=jieyouxu
Rollup of 6 pull requests Successful merges: - rust-lang#125041 (Enable GVN for `AggregateKind::RawPtr`) - rust-lang#125253 (Add `FRAC_1_SQRT_2PI` constant to f16/f32/f64/f128) - rust-lang#125465 (bootstrap: vendor crates required by opt-dist to collect profiles ) - rust-lang#125470 (Add release notes for 1.79.0) - rust-lang#125963 (Remove hard-coded hashes from codegen tests) - rust-lang#126188 (Fix documentation for `impl_common_helpers` in `run-make-support`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 65d1a73 + a8cba36 commit 503dfcf

30 files changed

+767
-70
lines changed
 

‎RELEASES.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,131 @@
1+
Version 1.79.0 (2024-06-13)
2+
==========================
3+
4+
<a id="1.79.0-Language"></a>
5+
6+
Language
7+
--------
8+
- [Stabilize inline `const {}` expressions.](https://github.com/rust-lang/rust/pull/104087/)
9+
- [Prevent opaque types being instantiated twice with different regions within the same function.](https://github.com/rust-lang/rust/pull/116935/)
10+
- [Stabilize WebAssembly target features that are in phase 4 and 5.](https://github.com/rust-lang/rust/pull/117457/)
11+
- [Add the `redundant_lifetimes` lint to detect lifetimes which are semantically redundant.](https://github.com/rust-lang/rust/pull/118391/)
12+
- [Stabilize the `unnameable_types` lint for public types that can't be named.](https://github.com/rust-lang/rust/pull/120144/)
13+
- [Enable debuginfo in macros, and stabilize `-C collapse-macro-debuginfo` and `#[collapse_debuginfo]`.](https://github.com/rust-lang/rust/pull/120845/)
14+
- [Propagate temporary lifetime extension into `if` and `match` expressions.](https://github.com/rust-lang/rust/pull/121346/)
15+
- [Restrict promotion of `const fn` calls.](https://github.com/rust-lang/rust/pull/121557/)
16+
- [Warn against refining impls of crate-private traits with `refining_impl_trait` lint.](https://github.com/rust-lang/rust/pull/121720/)
17+
- [Stabilize associated type bounds (RFC 2289).](https://github.com/rust-lang/rust/pull/122055/)
18+
- [Stabilize importing `main` from other modules or crates.](https://github.com/rust-lang/rust/pull/122060/)
19+
- [Check return types of function types for well-formedness](https://github.com/rust-lang/rust/pull/115538)
20+
- [Rework `impl Trait` lifetime inference](https://github.com/rust-lang/rust/pull/116891/)
21+
- [Change inductive trait solver cycles to be ambiguous](https://github.com/rust-lang/rust/pull/122791)
22+
23+
<a id="1.79.0-Compiler"></a>
24+
25+
Compiler
26+
--------
27+
- [Define `-C strip` to only affect binaries, not artifacts like `.pdb`.](https://github.com/rust-lang/rust/pull/115120/)
28+
- [Stabilize `-Crelro-level` for controlling runtime link hardening.](https://github.com/rust-lang/rust/pull/121694/)
29+
- [Stabilize checking of `cfg` names and values at compile-time with `--check-cfg`.](https://github.com/rust-lang/rust/pull/123501/)
30+
*Note that this only stabilizes the compiler part, the Cargo part is still unstable in this release.*
31+
- [Add `aarch64-apple-visionos` and `aarch64-apple-visionos-sim` tier 3 targets.](https://github.com/rust-lang/rust/pull/121419/)
32+
- [Add `riscv32ima-unknown-none-elf` tier 3 target.](https://github.com/rust-lang/rust/pull/122696/)
33+
- [Promote several Windows targets to tier 2](https://github.com/rust-lang/rust/pull/121712): `aarch64-pc-windows-gnullvm`, `i686-pc-windows-gnullvm`, and `x86_64-pc-windows-gnullvm`.
34+
35+
Refer to Rust's [platform support page][platform-support-doc]
36+
for more information on Rust's tiered platform support.
37+
38+
<a id="1.79.0-Libraries"></a>
39+
40+
Libraries
41+
---------
42+
43+
- [Implement `FromIterator` for `(impl Default + Extend, impl Default + Extend)`.](https://github.com/rust-lang/rust/pull/107462/)
44+
- [Implement `{Div,Rem}Assign<NonZero<X>>` on `X`.](https://github.com/rust-lang/rust/pull/121952/)
45+
- [Document overrides of `clone_from()` in core/std.](https://github.com/rust-lang/rust/pull/122201/)
46+
- [Link MSVC default lib in core.](https://github.com/rust-lang/rust/pull/122268/)
47+
- [Caution against using `transmute` between pointers and integers.](https://github.com/rust-lang/rust/pull/122379/)
48+
- [Enable frame pointers for the standard library.](https://github.com/rust-lang/rust/pull/122646/)
49+
50+
<a id="1.79.0-Stabilized-APIs"></a>
51+
52+
Stabilized APIs
53+
---------------
54+
55+
- [`{integer}::unchecked_add`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.unchecked_add)
56+
- [`{integer}::unchecked_mul`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.unchecked_mul)
57+
- [`{integer}::unchecked_sub`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.unchecked_sub)
58+
- [`<[T]>::split_at_unchecked`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_at_unchecked)
59+
- [`<[T]>::split_at_mut_unchecked`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_at_mut_unchecked)
60+
- [`<[u8]>::utf8_chunks`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.utf8_chunks)
61+
- [`str::Utf8Chunks`](https://doc.rust-lang.org/stable/core/str/struct.Utf8Chunks.html)
62+
- [`str::Utf8Chunk`](https://doc.rust-lang.org/stable/core/str/struct.Utf8Chunk.html)
63+
- [`<*const T>::is_aligned`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_aligned)
64+
- [`<*mut T>::is_aligned`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_aligned-1)
65+
- [`NonNull::is_aligned`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.is_aligned)
66+
- [`<*const [T]>::len`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.len)
67+
- [`<*mut [T]>::len`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.len-1)
68+
- [`<*const [T]>::is_empty`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_empty)
69+
- [`<*mut [T]>::is_empty`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_empty-1)
70+
- [`NonNull::<[T]>::is_empty`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.is_empty)
71+
- [`CStr::count_bytes`](https://doc.rust-lang.org/stable/core/ffi/c_str/struct.CStr.html#method.count_bytes)
72+
- [`io::Error::downcast`](https://doc.rust-lang.org/stable/std/io/struct.Error.html#method.downcast)
73+
- [`num::NonZero<T>`](https://doc.rust-lang.org/stable/core/num/struct.NonZero.html)
74+
- [`path::absolute`](https://doc.rust-lang.org/stable/std/path/fn.absolute.html)
75+
- [`proc_macro::Literal::byte_character`](https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.byte_character)
76+
- [`proc_macro::Literal::c_string`](https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.c_string)
77+
78+
These APIs are now stable in const contexts:
79+
80+
- [`Atomic*::into_inner`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicUsize.html#method.into_inner)
81+
- [`io::Cursor::new`](https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#method.new)
82+
- [`io::Cursor::get_ref`](https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#method.get_ref)
83+
- [`io::Cursor::position`](https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#method.position)
84+
- [`io::empty`](https://doc.rust-lang.org/stable/std/io/fn.empty.html)
85+
- [`io::repeat`](https://doc.rust-lang.org/stable/std/io/fn.repeat.html)
86+
- [`io::sink`](https://doc.rust-lang.org/stable/std/io/fn.sink.html)
87+
- [`panic::Location::caller`](https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.caller)
88+
- [`panic::Location::file`](https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.file)
89+
- [`panic::Location::line`](https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.line)
90+
- [`panic::Location::column`](https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.column)
91+
92+
<a id="1.79.0-Cargo"></a>
93+
94+
Cargo
95+
-----
96+
97+
- [Prevent dashes in `lib.name`, always normalizing to `_`.](https://github.com/rust-lang/cargo/pull/12783/)
98+
- [Stabilize MSRV-aware version requirement selection in `cargo add`.](https://github.com/rust-lang/cargo/pull/13608/)
99+
- [Switch to using `gitoxide` by default for listing files.](https://github.com/rust-lang/cargo/pull/13696/)
100+
- [Error on `[project]` in Edition 2024; `cargo fix --edition` will change it to `[package]`.](https://github.com/rust-lang/cargo/pull/13747/)
101+
102+
<a id="1.79.0-Rustdoc"></a>
103+
104+
Rustdoc
105+
-----
106+
107+
- [Always display stability version even if it's the same as the containing item.](https://github.com/rust-lang/rust/pull/118441/)
108+
- [Show a single search result for items with multiple paths.](https://github.com/rust-lang/rust/pull/119912/)
109+
- [Support typing `/` in docs to begin a search.](https://github.com/rust-lang/rust/pull/123355/)
110+
111+
<a id="1.79.0-Misc"></a>
112+
113+
Misc
114+
----
115+
116+
<a id="1.79.0-Compatibility-Notes"></a>
117+
118+
Compatibility Notes
119+
-------------------
120+
121+
- [Update the minimum external LLVM to 17.](https://github.com/rust-lang/rust/pull/122649/)
122+
- [`RustcEncodable` and `RustcDecodable` are soft-destabilized, to be removed
123+
from the prelude in next edition.](https://github.com/rust-lang/rust/pull/116016/)
124+
- [The `wasm_c_abi` future-incompatibility lint will warn about use of the
125+
non-spec-compliant C ABI.](https://github.com/rust-lang/rust/pull/117918/)
126+
Use `wasm-bindgen v0.2.88` to generate forward-compatible bindings.
127+
- [Check return types of function types for well-formedness](https://github.com/rust-lang/rust/pull/115538)
128+
1129
Version 1.78.0 (2024-05-02)
2130
==========================
3131

‎compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
//! that contain `AllocId`s.
8484
8585
use rustc_const_eval::const_eval::DummyMachine;
86-
use rustc_const_eval::interpret::{intern_const_alloc_for_constprop, MemoryKind};
87-
use rustc_const_eval::interpret::{ImmTy, InterpCx, OpTy, Projectable, Scalar};
86+
use rustc_const_eval::interpret::{intern_const_alloc_for_constprop, MemPlaceMeta, MemoryKind};
87+
use rustc_const_eval::interpret::{ImmTy, Immediate, InterpCx, OpTy, Projectable, Scalar};
8888
use rustc_data_structures::fx::FxIndexSet;
8989
use rustc_data_structures::graph::dominators::Dominators;
9090
use rustc_hir::def::DefKind;
@@ -99,7 +99,7 @@ use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
9999
use rustc_middle::ty::{self, Ty, TyCtxt};
100100
use rustc_span::def_id::DefId;
101101
use rustc_span::DUMMY_SP;
102-
use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT};
102+
use rustc_target::abi::{self, Abi, FieldIdx, Size, VariantIdx, FIRST_VARIANT};
103103
use smallvec::SmallVec;
104104
use std::borrow::Cow;
105105

@@ -177,6 +177,12 @@ enum AggregateTy<'tcx> {
177177
Array,
178178
Tuple,
179179
Def(DefId, ty::GenericArgsRef<'tcx>),
180+
RawPtr {
181+
/// Needed for cast propagation.
182+
data_pointer_ty: Ty<'tcx>,
183+
/// The data pointer can be anything thin, so doesn't determine the output.
184+
output_pointer_ty: Ty<'tcx>,
185+
},
180186
}
181187

182188
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@@ -385,11 +391,22 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
385391
AggregateTy::Def(def_id, args) => {
386392
self.tcx.type_of(def_id).instantiate(self.tcx, args)
387393
}
394+
AggregateTy::RawPtr { output_pointer_ty, .. } => output_pointer_ty,
388395
};
389396
let variant = if ty.is_enum() { Some(variant) } else { None };
390397
let ty = self.ecx.layout_of(ty).ok()?;
391398
if ty.is_zst() {
392399
ImmTy::uninit(ty).into()
400+
} else if matches!(kind, AggregateTy::RawPtr { .. }) {
401+
// Pointers don't have fields, so don't `project_field` them.
402+
let data = self.ecx.read_pointer(fields[0]).ok()?;
403+
let meta = if fields[1].layout.is_zst() {
404+
MemPlaceMeta::None
405+
} else {
406+
MemPlaceMeta::Meta(self.ecx.read_scalar(fields[1]).ok()?)
407+
};
408+
let ptr_imm = Immediate::new_pointer_with_meta(data, meta, &self.ecx);
409+
ImmTy::from_immediate(ptr_imm, ty).into()
393410
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
394411
let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?;
395412
let variant_dest = if let Some(variant) = variant {
@@ -864,10 +881,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
864881
rvalue: &mut Rvalue<'tcx>,
865882
location: Location,
866883
) -> Option<VnIndex> {
867-
let Rvalue::Aggregate(box ref kind, ref mut fields) = *rvalue else { bug!() };
884+
let Rvalue::Aggregate(box ref kind, ref mut field_ops) = *rvalue else { bug!() };
868885

869886
let tcx = self.tcx;
870-
if fields.is_empty() {
887+
if field_ops.is_empty() {
871888
let is_zst = match *kind {
872889
AggregateKind::Array(..)
873890
| AggregateKind::Tuple
@@ -886,13 +903,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
886903
}
887904
}
888905

889-
let (ty, variant_index) = match *kind {
906+
let (mut ty, variant_index) = match *kind {
890907
AggregateKind::Array(..) => {
891-
assert!(!fields.is_empty());
908+
assert!(!field_ops.is_empty());
892909
(AggregateTy::Array, FIRST_VARIANT)
893910
}
894911
AggregateKind::Tuple => {
895-
assert!(!fields.is_empty());
912+
assert!(!field_ops.is_empty());
896913
(AggregateTy::Tuple, FIRST_VARIANT)
897914
}
898915
AggregateKind::Closure(did, args)
@@ -903,15 +920,49 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
903920
}
904921
// Do not track unions.
905922
AggregateKind::Adt(_, _, _, _, Some(_)) => return None,
906-
// FIXME: Do the extra work to GVN `from_raw_parts`
907-
AggregateKind::RawPtr(..) => return None,
923+
AggregateKind::RawPtr(pointee_ty, mtbl) => {
924+
assert_eq!(field_ops.len(), 2);
925+
let data_pointer_ty = field_ops[FieldIdx::ZERO].ty(self.local_decls, self.tcx);
926+
let output_pointer_ty = Ty::new_ptr(self.tcx, pointee_ty, mtbl);
927+
(AggregateTy::RawPtr { data_pointer_ty, output_pointer_ty }, FIRST_VARIANT)
928+
}
908929
};
909930

910-
let fields: Option<Vec<_>> = fields
931+
let fields: Option<Vec<_>> = field_ops
911932
.iter_mut()
912933
.map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
913934
.collect();
914-
let fields = fields?;
935+
let mut fields = fields?;
936+
937+
if let AggregateTy::RawPtr { data_pointer_ty, output_pointer_ty } = &mut ty {
938+
let mut was_updated = false;
939+
940+
// Any thin pointer of matching mutability is fine as the data pointer.
941+
while let Value::Cast {
942+
kind: CastKind::PtrToPtr,
943+
value: cast_value,
944+
from: cast_from,
945+
to: _,
946+
} = self.get(fields[0])
947+
&& let ty::RawPtr(from_pointee_ty, from_mtbl) = cast_from.kind()
948+
&& let ty::RawPtr(_, output_mtbl) = output_pointer_ty.kind()
949+
&& from_mtbl == output_mtbl
950+
&& from_pointee_ty.is_sized(self.tcx, self.param_env)
951+
{
952+
fields[0] = *cast_value;
953+
*data_pointer_ty = *cast_from;
954+
was_updated = true;
955+
}
956+
957+
if was_updated {
958+
if let Some(const_) = self.try_as_constant(fields[0]) {
959+
field_ops[FieldIdx::ZERO] = Operand::Constant(Box::new(const_));
960+
} else if let Some(local) = self.try_as_local(fields[0], location) {
961+
field_ops[FieldIdx::ZERO] = Operand::Copy(Place::from(local));
962+
self.reused_locals.insert(local);
963+
}
964+
}
965+
}
915966

916967
if let AggregateTy::Array = ty
917968
&& fields.len() > 4
@@ -943,6 +994,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
943994
(UnOp::Not, Value::BinaryOp(BinOp::Ne, lhs, rhs)) => {
944995
Value::BinaryOp(BinOp::Eq, *lhs, *rhs)
945996
}
997+
(UnOp::PtrMetadata, Value::Aggregate(AggregateTy::RawPtr { .. }, _, fields)) => {
998+
return Some(fields[1]);
999+
}
9461000
_ => return None,
9471001
};
9481002

@@ -1094,6 +1148,23 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10941148
return self.new_opaque();
10951149
}
10961150

1151+
let mut was_updated = false;
1152+
1153+
// If that cast just casts away the metadata again,
1154+
if let PtrToPtr = kind
1155+
&& let Value::Aggregate(AggregateTy::RawPtr { data_pointer_ty, .. }, _, fields) =
1156+
self.get(value)
1157+
&& let ty::RawPtr(to_pointee, _) = to.kind()
1158+
&& to_pointee.is_sized(self.tcx, self.param_env)
1159+
{
1160+
from = *data_pointer_ty;
1161+
value = fields[0];
1162+
was_updated = true;
1163+
if *data_pointer_ty == to {
1164+
return Some(fields[0]);
1165+
}
1166+
}
1167+
10971168
if let PtrToPtr | PointerCoercion(MutToConstPointer) = kind
10981169
&& let Value::Cast { kind: inner_kind, value: inner_value, from: inner_from, to: _ } =
10991170
*self.get(value)
@@ -1102,9 +1173,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
11021173
from = inner_from;
11031174
value = inner_value;
11041175
*kind = PtrToPtr;
1176+
was_updated = true;
11051177
if inner_from == to {
11061178
return Some(inner_value);
11071179
}
1180+
}
1181+
1182+
if was_updated {
11081183
if let Some(const_) = self.try_as_constant(value) {
11091184
*operand = Operand::Constant(Box::new(const_));
11101185
} else if let Some(local) = self.try_as_local(value, location) {

‎library/core/src/num/f128.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ pub mod consts {
6868
pub const FRAC_1_SQRT_PI: f128 =
6969
0.564189583547756286948079451560772585844050629328998856844086_f128;
7070

71+
/// 1/sqrt(2π)
72+
#[doc(alias = "FRAC_1_SQRT_TAU")]
73+
#[unstable(feature = "f128", issue = "116909")]
74+
// Also, #[unstable(feature = "more_float_constants", issue = "103883")]
75+
pub const FRAC_1_SQRT_2PI: f128 =
76+
0.398942280401432677939946059934381868475858631164934657665926_f128;
77+
7178
/// 2/π
7279
#[unstable(feature = "f128", issue = "116909")]
7380
pub const FRAC_2_PI: f128 = 0.636619772367581343075535053490057448137838582961825794990669_f128;

‎library/core/src/num/f16.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ pub mod consts {
6767
// Also, #[unstable(feature = "more_float_constants", issue = "103883")]
6868
pub const FRAC_1_SQRT_PI: f16 = 0.564189583547756286948079451560772586_f16;
6969

70+
/// 1/sqrt(2π)
71+
#[doc(alias = "FRAC_1_SQRT_TAU")]
72+
#[unstable(feature = "f16", issue = "116909")]
73+
// Also, #[unstable(feature = "more_float_constants", issue = "103883")]
74+
pub const FRAC_1_SQRT_2PI: f16 = 0.398942280401432677939946059934381868_f16;
75+
7076
/// 2/π
7177
#[unstable(feature = "f16", issue = "116909")]
7278
pub const FRAC_2_PI: f16 = 0.636619772367581343075535053490057448_f16;

‎library/core/src/num/f32.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ pub mod consts {
327327
#[unstable(feature = "more_float_constants", issue = "103883")]
328328
pub const FRAC_1_SQRT_PI: f32 = 0.564189583547756286948079451560772586_f32;
329329

330+
/// 1/sqrt(2π)
331+
#[doc(alias = "FRAC_1_SQRT_TAU")]
332+
#[unstable(feature = "more_float_constants", issue = "103883")]
333+
pub const FRAC_1_SQRT_2PI: f32 = 0.398942280401432677939946059934381868_f32;
334+
330335
/// 2/π
331336
#[stable(feature = "rust1", since = "1.0.0")]
332337
pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32;

‎library/core/src/num/f64.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ pub mod consts {
327327
#[unstable(feature = "more_float_constants", issue = "103883")]
328328
pub const FRAC_1_SQRT_PI: f64 = 0.564189583547756286948079451560772586_f64;
329329

330+
/// 1/sqrt(2π)
331+
#[doc(alias = "FRAC_1_SQRT_TAU")]
332+
#[unstable(feature = "more_float_constants", issue = "103883")]
333+
pub const FRAC_1_SQRT_2PI: f64 = 0.398942280401432677939946059934381868_f64;
334+
330335
/// 2/π
331336
#[stable(feature = "rust1", since = "1.0.0")]
332337
pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;

‎src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,21 @@ impl Step for PlainSourceTarball {
10411041
.env("RUSTC_BOOTSTRAP", "1")
10421042
.current_dir(plain_dst_src);
10431043

1044+
// Vendor packages that are required by opt-dist to collect PGO profiles.
1045+
let pkgs_for_pgo_training = build_helper::LLVM_PGO_CRATES
1046+
.iter()
1047+
.chain(build_helper::RUSTC_PGO_CRATES)
1048+
.map(|pkg| {
1049+
let mut manifest_path =
1050+
builder.src.join("./src/tools/rustc-perf/collector/compile-benchmarks");
1051+
manifest_path.push(pkg);
1052+
manifest_path.push("Cargo.toml");
1053+
manifest_path
1054+
});
1055+
for manifest_path in pkgs_for_pgo_training {
1056+
cmd.arg("--sync").arg(manifest_path);
1057+
}
1058+
10441059
let config = if !builder.config.dry_run() {
10451060
t!(String::from_utf8(t!(cmd.output()).stdout))
10461061
} else {

‎src/tools/build_helper/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Types and functions shared across tools in this workspace.

‎src/tools/build_helper/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
//! Types and functions shared across tools in this workspace.
2+
13
pub mod ci;
24
pub mod git;
35
pub mod metrics;
46
pub mod stage0_parser;
57
pub mod util;
8+
9+
/// The default set of crates for opt-dist to collect LLVM profiles.
10+
pub const LLVM_PGO_CRATES: &[&str] = &[
11+
"syn-1.0.89",
12+
"cargo-0.60.0",
13+
"serde-1.0.136",
14+
"ripgrep-13.0.0",
15+
"regex-1.5.5",
16+
"clap-3.1.6",
17+
"hyper-0.14.18",
18+
];
19+
20+
/// The default set of crates for opt-dist to collect rustc profiles.
21+
pub const RUSTC_PGO_CRATES: &[&str] = &[
22+
"externs",
23+
"ctfe-stress-5",
24+
"cargo-0.60.0",
25+
"token-stream-stress",
26+
"match-stress",
27+
"tuple-stress",
28+
"diesel-1.4.8",
29+
"bitmaps-3.1.0",
30+
];

‎src/tools/opt-dist/src/training.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,10 @@ use crate::exec::{cmd, CmdBuilder};
33
use crate::utils::io::{count_files, delete_directory};
44
use crate::utils::with_log_group;
55
use anyhow::Context;
6+
use build_helper::{LLVM_PGO_CRATES, RUSTC_PGO_CRATES};
67
use camino::{Utf8Path, Utf8PathBuf};
78
use humansize::BINARY;
89

9-
const LLVM_PGO_CRATES: &[&str] = &[
10-
"syn-1.0.89",
11-
"cargo-0.60.0",
12-
"serde-1.0.136",
13-
"ripgrep-13.0.0",
14-
"regex-1.5.5",
15-
"clap-3.1.6",
16-
"hyper-0.14.18",
17-
];
18-
19-
const RUSTC_PGO_CRATES: &[&str] = &[
20-
"externs",
21-
"ctfe-stress-5",
22-
"cargo-0.60.0",
23-
"token-stream-stress",
24-
"match-stress",
25-
"tuple-stress",
26-
"diesel-1.4.8",
27-
"bitmaps-3.1.0",
28-
];
29-
3010
fn init_compiler_benchmarks(
3111
env: &Environment,
3212
profiles: &[&str],

‎src/tools/run-make-support/src/lib.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -318,38 +318,30 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
318318
}
319319

320320
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
321-
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
321+
/// containing a `cmd: Command` field. The provided helpers are:
322322
///
323323
/// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
324324
/// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
325325
/// new specific helper methods over relying on these generic argument providers.
326326
/// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
327327
/// methods of the same name on [`Command`].
328-
/// 3. Output and execution: `output`, `run` and `run_fail` are provided. `output` waits for the
329-
/// command to finish running and returns the process's [`Output`]. `run` and `run_fail` are
330-
/// higher-level convenience methods which waits for the command to finish running and assert
331-
/// that the command successfully ran or failed as expected. Prefer `run` and `run_fail` when
332-
/// possible.
328+
/// 3. Output and execution: `run` and `run_fail` are provided. These are
329+
/// higher-level convenience methods which wait for the command to finish running and assert
330+
/// that the command successfully ran or failed as expected. They return
331+
/// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
332+
/// process.
333333
///
334334
/// Example usage:
335335
///
336336
/// ```ignore (illustrative)
337337
/// struct CommandWrapper { cmd: Command } // <- required `cmd` field
338338
///
339-
/// impl CommandWrapper {
340-
/// /// Get the [`Output`][::std::process::Output] of the finished process.
341-
/// pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method
342-
/// }
343-
///
344339
/// crate::impl_common_helpers!(CommandWrapper);
345340
///
346341
/// impl CommandWrapper {
347342
/// // ... additional specific helper methods
348343
/// }
349344
/// ```
350-
///
351-
/// [`Command`]: ::std::process::Command
352-
/// [`Output`]: ::std::process::Output
353345
macro_rules! impl_common_helpers {
354346
($wrapper: ident) => {
355347
impl $wrapper {

‎src/tools/tidy/src/deps.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)
6767
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
6868
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
6969
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
70+
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None),
7071
("src/tools/x", &[], None),
7172
// tidy-alphabetical-end
7273
];
@@ -142,6 +143,22 @@ const EXCEPTIONS_RUST_ANALYZER: ExceptionList = &[
142143
// tidy-alphabetical-end
143144
];
144145

146+
const EXCEPTIONS_RUSTC_PERF: ExceptionList = &[
147+
// tidy-alphabetical-start
148+
("alloc-no-stdlib", "BSD-3-Clause"),
149+
("alloc-stdlib", "BSD-3-Clause"),
150+
("brotli", "BSD-3-Clause/MIT"),
151+
("brotli-decompressor", "BSD-3-Clause/MIT"),
152+
("encoding_rs", "(Apache-2.0 OR MIT) AND BSD-3-Clause"),
153+
("inferno", "CDDL-1.0"),
154+
("instant", "BSD-3-Clause"),
155+
("ring", NON_STANDARD_LICENSE), // see EXCEPTIONS_NON_STANDARD_LICENSE_DEPS for more.
156+
("ryu", "Apache-2.0 OR BSL-1.0"),
157+
("snap", "BSD-3-Clause"),
158+
("subtle", "BSD-3-Clause"),
159+
// tidy-alphabetical-end
160+
];
161+
145162
const EXCEPTIONS_CRANELIFT: ExceptionList = &[
146163
// tidy-alphabetical-start
147164
("cranelift-bforest", "Apache-2.0 WITH LLVM-exception"),
@@ -178,6 +195,20 @@ const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[
178195
("r-efi", "MIT OR Apache-2.0 OR LGPL-2.1-or-later"), // LGPL is not acceptible, but we use it under MIT OR Apache-2.0
179196
];
180197

198+
/// Placeholder for non-standard license file.
199+
const NON_STANDARD_LICENSE: &str = "NON_STANDARD_LICENSE";
200+
201+
/// These dependencies have non-standard licenses but are genenrally permitted.
202+
const EXCEPTIONS_NON_STANDARD_LICENSE_DEPS: &[&str] = &[
203+
// `ring` is included because it is an optional dependency of `hyper`,
204+
// which is a training data in rustc-perf for optimized build.
205+
// The license of it is generally `ISC AND MIT AND OpenSSL`,
206+
// though the `package.license` field is not set.
207+
//
208+
// See https://github.com/briansmith/ring/issues/902
209+
"ring",
210+
];
211+
181212
/// These are the root crates that are part of the runtime. The licenses for
182213
/// these and all their dependencies *must not* be in the exception list.
183214
const RUNTIME_CRATES: &[&str] = &["std", "core", "alloc", "test", "panic_abort", "panic_unwind"];
@@ -610,6 +641,11 @@ fn check_license_exceptions(metadata: &Metadata, exceptions: &[(&str, &str)], ba
610641
for pkg in metadata.packages.iter().filter(|p| p.name == *name) {
611642
match &pkg.license {
612643
None => {
644+
if *license == NON_STANDARD_LICENSE
645+
&& EXCEPTIONS_NON_STANDARD_LICENSE_DEPS.contains(&pkg.name.as_str())
646+
{
647+
continue;
648+
}
613649
tidy_error!(
614650
bad,
615651
"dependency exception `{}` does not declare a license expression",

‎src/tools/tidy/src/extdeps.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ use std::fs;
44
use std::path::Path;
55

66
/// List of allowed sources for packages.
7-
const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""];
7+
const ALLOWED_SOURCES: &[&str] = &[
8+
r#""registry+https://github.com/rust-lang/crates.io-index""#,
9+
// This is `rust_team_data` used by `site` in src/tools/rustc-perf,
10+
r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
11+
];
812

913
/// Checks for external package sources. `root` is the path to the directory that contains the
1014
/// workspace `Cargo.toml`.

‎tests/assembly/asm/global_asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
2525
global_asm!("call {}", sym my_func);
2626
// CHECK: lea rax, [rip + MY_STATIC]
2727
global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
28-
// CHECK: call _RNvCsddMtV7nAi4C_10global_asm6foobar
28+
// CHECK: call _RNvC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_10global_asm6foobar
2929
global_asm!("call {}", sym foobar);
30-
// CHECK: _RNvCsddMtV7nAi4C_10global_asm6foobar:
30+
// CHECK: _RNvC[[CRATE_IDENT]]_10global_asm6foobar:
3131
fn foobar() {
3232
loop {}
3333
}

‎tests/codegen/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// CHECK: @STATIC = {{.*}}, align 4
1010

1111
// This checks the constants from inline_enum_const
12-
// CHECK: @alloc_af1f8e8e6f4b341431a1d405e652df2d = {{.*}}, align 2
12+
// CHECK: @alloc_[[INLINE_ENUM_HASH:[a-f0-9]{32}]] = {{.*}}, align 2
1313

1414
// This checks the constants from {low,high}_align_const, they share the same
1515
// constant, but the alignment differs, so the higher one should be used
16-
// CHECK: [[LOW_HIGH:@alloc_[a-f0-9]+]] = {{.*}}, align 4
16+
// CHECK: [[LOW_HIGH:@alloc_[a-f0-9]{32}]] = {{.*}}, align 4
1717

1818
#[derive(Copy, Clone)]
1919
// repr(i16) is required for the {low,high}_align_const test

‎tests/codegen/pattern_type_symbols.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn foo<T>() {}
1515

1616
pub fn bar() {
1717
// CHECK: call pattern_type_symbols::foo::<u32>
18-
// CHECK: call void @_RINvCs3QvG2ESzx2Q_20pattern_type_symbols3foomEB2_
18+
// CHECK: call void @_RINvC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_20pattern_type_symbols3foomEB2_
1919
foo::<u32>();
2020
// CHECK: call pattern_type_symbols::foo::<(u32, [(); 0], [(); 999999999], [(); true])>
21-
// CHECK: call void @_RINvCs3QvG2ESzx2Q_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_Aub1_EEB2_
21+
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_Aub1_EEB2_
2222
foo::<NanoU32>();
2323
}

‎tests/codegen/virtual-function-elimination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn taking_u(u: &dyn U) -> i32 {
8181
}
8282

8383
pub fn taking_v(v: &dyn V) -> i32 {
84-
// CHECK: @llvm.type.checked.load({{.*}}, i32 24, metadata !"NtCs64ITQYi9761_28virtual_function_elimination1V")
84+
// CHECK: @llvm.type.checked.load({{.*}}, i32 24, metadata !"NtC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_28virtual_function_elimination1V")
8585
v.public_function()
8686
}
8787

@@ -96,5 +96,5 @@ pub fn main() {
9696
// CHECK: ![[TYPE0]] = !{i64 0, !"[[MANGLED_TYPE0]]"}
9797
// CHECK: ![[VCALL_VIS0]] = !{i64 2}
9898
// CHECK: ![[TYPE1]] = !{i64 0, !"[[MANGLED_TYPE1]]"}
99-
// CHECK: ![[TYPE2]] = !{i64 0, !"NtCs64ITQYi9761_28virtual_function_elimination1V"}
99+
// CHECK: ![[TYPE2]] = !{i64 0, !"NtC[[CRATE_IDENT]]_28virtual_function_elimination1V"}
100100
// CHECK: ![[VCALL_VIS2]] = !{i64 1}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
- // MIR for `casts_before_aggregate_raw_ptr` before GVN
2+
+ // MIR for `casts_before_aggregate_raw_ptr` after GVN
3+
4+
fn casts_before_aggregate_raw_ptr(_1: *const u32) -> *const [u8] {
5+
debug x => _1;
6+
let mut _0: *const [u8];
7+
let _2: *const [u8; 4];
8+
let mut _3: *const u32;
9+
let mut _5: *const [u8; 4];
10+
let mut _7: *const u8;
11+
let mut _8: *const ();
12+
scope 1 {
13+
debug x => _2;
14+
let _4: *const u8;
15+
scope 2 {
16+
debug x => _4;
17+
let _6: *const ();
18+
scope 3 {
19+
debug x => _6;
20+
}
21+
}
22+
}
23+
24+
bb0: {
25+
- StorageLive(_2);
26+
+ nop;
27+
StorageLive(_3);
28+
_3 = _1;
29+
- _2 = move _3 as *const [u8; 4] (PtrToPtr);
30+
+ _2 = _1 as *const [u8; 4] (PtrToPtr);
31+
StorageDead(_3);
32+
- StorageLive(_4);
33+
+ nop;
34+
StorageLive(_5);
35+
_5 = _2;
36+
- _4 = move _5 as *const u8 (PtrToPtr);
37+
+ _4 = _1 as *const u8 (PtrToPtr);
38+
StorageDead(_5);
39+
- StorageLive(_6);
40+
+ nop;
41+
StorageLive(_7);
42+
_7 = _4;
43+
- _6 = move _7 as *const () (PtrToPtr);
44+
+ _6 = _1 as *const () (PtrToPtr);
45+
StorageDead(_7);
46+
StorageLive(_8);
47+
_8 = _6;
48+
- _0 = *const [u8] from (move _8, const 4_usize);
49+
+ _0 = *const [u8] from (_1, const 4_usize);
50+
StorageDead(_8);
51+
- StorageDead(_6);
52+
- StorageDead(_4);
53+
- StorageDead(_2);
54+
+ nop;
55+
+ nop;
56+
+ nop;
57+
return;
58+
}
59+
}
60+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
- // MIR for `casts_before_aggregate_raw_ptr` before GVN
2+
+ // MIR for `casts_before_aggregate_raw_ptr` after GVN
3+
4+
fn casts_before_aggregate_raw_ptr(_1: *const u32) -> *const [u8] {
5+
debug x => _1;
6+
let mut _0: *const [u8];
7+
let _2: *const [u8; 4];
8+
let mut _3: *const u32;
9+
let mut _5: *const [u8; 4];
10+
let mut _7: *const u8;
11+
let mut _8: *const ();
12+
scope 1 {
13+
debug x => _2;
14+
let _4: *const u8;
15+
scope 2 {
16+
debug x => _4;
17+
let _6: *const ();
18+
scope 3 {
19+
debug x => _6;
20+
}
21+
}
22+
}
23+
24+
bb0: {
25+
- StorageLive(_2);
26+
+ nop;
27+
StorageLive(_3);
28+
_3 = _1;
29+
- _2 = move _3 as *const [u8; 4] (PtrToPtr);
30+
+ _2 = _1 as *const [u8; 4] (PtrToPtr);
31+
StorageDead(_3);
32+
- StorageLive(_4);
33+
+ nop;
34+
StorageLive(_5);
35+
_5 = _2;
36+
- _4 = move _5 as *const u8 (PtrToPtr);
37+
+ _4 = _1 as *const u8 (PtrToPtr);
38+
StorageDead(_5);
39+
- StorageLive(_6);
40+
+ nop;
41+
StorageLive(_7);
42+
_7 = _4;
43+
- _6 = move _7 as *const () (PtrToPtr);
44+
+ _6 = _1 as *const () (PtrToPtr);
45+
StorageDead(_7);
46+
StorageLive(_8);
47+
_8 = _6;
48+
- _0 = *const [u8] from (move _8, const 4_usize);
49+
+ _0 = *const [u8] from (_1, const 4_usize);
50+
StorageDead(_8);
51+
- StorageDead(_6);
52+
- StorageDead(_4);
53+
- StorageDead(_2);
54+
+ nop;
55+
+ nop;
56+
+ nop;
57+
return;
58+
}
59+
}
60+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `meta_of_ref_to_slice` before GVN
2+
+ // MIR for `meta_of_ref_to_slice` after GVN
3+
4+
fn meta_of_ref_to_slice(_1: *const i32) -> usize {
5+
debug x => _1;
6+
let mut _0: usize;
7+
let _2: *const [i32];
8+
let mut _3: *const i32;
9+
let mut _4: *const [i32];
10+
scope 1 {
11+
debug ptr => _2;
12+
}
13+
14+
bb0: {
15+
- StorageLive(_2);
16+
+ nop;
17+
StorageLive(_3);
18+
_3 = _1;
19+
- _2 = *const [i32] from (move _3, const 1_usize);
20+
+ _2 = *const [i32] from (_1, const 1_usize);
21+
StorageDead(_3);
22+
StorageLive(_4);
23+
_4 = _2;
24+
- _0 = PtrMetadata(move _4);
25+
+ _0 = const 1_usize;
26+
StorageDead(_4);
27+
- StorageDead(_2);
28+
+ nop;
29+
return;
30+
}
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `meta_of_ref_to_slice` before GVN
2+
+ // MIR for `meta_of_ref_to_slice` after GVN
3+
4+
fn meta_of_ref_to_slice(_1: *const i32) -> usize {
5+
debug x => _1;
6+
let mut _0: usize;
7+
let _2: *const [i32];
8+
let mut _3: *const i32;
9+
let mut _4: *const [i32];
10+
scope 1 {
11+
debug ptr => _2;
12+
}
13+
14+
bb0: {
15+
- StorageLive(_2);
16+
+ nop;
17+
StorageLive(_3);
18+
_3 = _1;
19+
- _2 = *const [i32] from (move _3, const 1_usize);
20+
+ _2 = *const [i32] from (_1, const 1_usize);
21+
StorageDead(_3);
22+
StorageLive(_4);
23+
_4 = _2;
24+
- _0 = PtrMetadata(move _4);
25+
+ _0 = const 1_usize;
26+
StorageDead(_4);
27+
- StorageDead(_2);
28+
+ nop;
29+
return;
30+
}
31+
}
32+

‎tests/mir-opt/gvn.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,39 @@ fn non_freeze<T: Copy>(x: T) {
783783
}
784784
}
785785

786+
// Check that we can const-prop into `from_raw_parts`
787+
fn slice_const_length(x: &[i32]) -> *const [i32] {
788+
// CHECK-LABEL: fn slice_const_length(
789+
// CHECK: _0 = *const [i32] from ({{_[0-9]+}}, const 123_usize);
790+
let ptr = x.as_ptr();
791+
let len = 123;
792+
std::intrinsics::aggregate_raw_ptr(ptr, len)
793+
}
794+
795+
fn meta_of_ref_to_slice(x: *const i32) -> usize {
796+
// CHECK-LABEL: fn meta_of_ref_to_slice
797+
// CHECK: _0 = const 1_usize
798+
let ptr: *const [i32] = std::intrinsics::aggregate_raw_ptr(x, 1);
799+
std::intrinsics::ptr_metadata(ptr)
800+
}
801+
802+
fn slice_from_raw_parts_as_ptr(x: *const u16, n: usize) -> (*const u16, *const f32) {
803+
// CHECK-LABEL: fn slice_from_raw_parts_as_ptr
804+
// CHECK: _8 = _1 as *const f32 (PtrToPtr);
805+
// CHECK: _0 = (_1, move _8);
806+
let ptr: *const [u16] = std::intrinsics::aggregate_raw_ptr(x, n);
807+
(ptr as *const u16, ptr as *const f32)
808+
}
809+
810+
fn casts_before_aggregate_raw_ptr(x: *const u32) -> *const [u8] {
811+
// CHECK-LABEL: fn casts_before_aggregate_raw_ptr
812+
// CHECK: _0 = *const [u8] from (_1, const 4_usize);
813+
let x = x as *const [u8; 4];
814+
let x = x as *const u8;
815+
let x = x as *const ();
816+
std::intrinsics::aggregate_raw_ptr(x, 4)
817+
}
818+
786819
fn main() {
787820
subexpression_elimination(2, 4, 5);
788821
wrap_unwrap(5);
@@ -807,6 +840,9 @@ fn main() {
807840
wide_ptr_integer();
808841
borrowed(5);
809842
non_freeze(5);
843+
slice_const_length(&[1]);
844+
meta_of_ref_to_slice(&42);
845+
slice_from_raw_parts_as_ptr(&123, 456);
810846
}
811847

812848
#[inline(never)]
@@ -840,3 +876,7 @@ fn identity<T>(x: T) -> T {
840876
// EMIT_MIR gvn.wide_ptr_integer.GVN.diff
841877
// EMIT_MIR gvn.borrowed.GVN.diff
842878
// EMIT_MIR gvn.non_freeze.GVN.diff
879+
// EMIT_MIR gvn.slice_const_length.GVN.diff
880+
// EMIT_MIR gvn.meta_of_ref_to_slice.GVN.diff
881+
// EMIT_MIR gvn.slice_from_raw_parts_as_ptr.GVN.diff
882+
// EMIT_MIR gvn.casts_before_aggregate_raw_ptr.GVN.diff
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
- // MIR for `slice_const_length` before GVN
2+
+ // MIR for `slice_const_length` after GVN
3+
4+
fn slice_const_length(_1: &[i32]) -> *const [i32] {
5+
debug x => _1;
6+
let mut _0: *const [i32];
7+
let _2: *const i32;
8+
let mut _3: &[i32];
9+
let mut _5: *const i32;
10+
let mut _6: usize;
11+
scope 1 {
12+
debug ptr => _2;
13+
let _4: usize;
14+
scope 2 {
15+
debug len => _4;
16+
}
17+
}
18+
19+
bb0: {
20+
- StorageLive(_2);
21+
+ nop;
22+
StorageLive(_3);
23+
_3 = &(*_1);
24+
_2 = core::slice::<impl [i32]>::as_ptr(move _3) -> [return: bb1, unwind unreachable];
25+
}
26+
27+
bb1: {
28+
StorageDead(_3);
29+
- StorageLive(_4);
30+
+ nop;
31+
_4 = const 123_usize;
32+
StorageLive(_5);
33+
_5 = _2;
34+
StorageLive(_6);
35+
- _6 = _4;
36+
- _0 = *const [i32] from (move _5, move _6);
37+
+ _6 = const 123_usize;
38+
+ _0 = *const [i32] from (_2, const 123_usize);
39+
StorageDead(_6);
40+
StorageDead(_5);
41+
- StorageDead(_4);
42+
- StorageDead(_2);
43+
+ nop;
44+
+ nop;
45+
return;
46+
}
47+
}
48+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
- // MIR for `slice_const_length` before GVN
2+
+ // MIR for `slice_const_length` after GVN
3+
4+
fn slice_const_length(_1: &[i32]) -> *const [i32] {
5+
debug x => _1;
6+
let mut _0: *const [i32];
7+
let _2: *const i32;
8+
let mut _3: &[i32];
9+
let mut _5: *const i32;
10+
let mut _6: usize;
11+
scope 1 {
12+
debug ptr => _2;
13+
let _4: usize;
14+
scope 2 {
15+
debug len => _4;
16+
}
17+
}
18+
19+
bb0: {
20+
- StorageLive(_2);
21+
+ nop;
22+
StorageLive(_3);
23+
_3 = &(*_1);
24+
_2 = core::slice::<impl [i32]>::as_ptr(move _3) -> [return: bb1, unwind continue];
25+
}
26+
27+
bb1: {
28+
StorageDead(_3);
29+
- StorageLive(_4);
30+
+ nop;
31+
_4 = const 123_usize;
32+
StorageLive(_5);
33+
_5 = _2;
34+
StorageLive(_6);
35+
- _6 = _4;
36+
- _0 = *const [i32] from (move _5, move _6);
37+
+ _6 = const 123_usize;
38+
+ _0 = *const [i32] from (_2, const 123_usize);
39+
StorageDead(_6);
40+
StorageDead(_5);
41+
- StorageDead(_4);
42+
- StorageDead(_2);
43+
+ nop;
44+
+ nop;
45+
return;
46+
}
47+
}
48+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
- // MIR for `slice_from_raw_parts_as_ptr` before GVN
2+
+ // MIR for `slice_from_raw_parts_as_ptr` after GVN
3+
4+
fn slice_from_raw_parts_as_ptr(_1: *const u16, _2: usize) -> (*const u16, *const f32) {
5+
debug x => _1;
6+
debug n => _2;
7+
let mut _0: (*const u16, *const f32);
8+
let _3: *const [u16];
9+
let mut _4: *const u16;
10+
let mut _5: usize;
11+
let mut _6: *const u16;
12+
let mut _7: *const [u16];
13+
let mut _8: *const f32;
14+
let mut _9: *const [u16];
15+
scope 1 {
16+
debug ptr => _3;
17+
}
18+
19+
bb0: {
20+
- StorageLive(_3);
21+
+ nop;
22+
StorageLive(_4);
23+
_4 = _1;
24+
StorageLive(_5);
25+
_5 = _2;
26+
- _3 = *const [u16] from (move _4, move _5);
27+
+ _3 = *const [u16] from (_1, _2);
28+
StorageDead(_5);
29+
StorageDead(_4);
30+
StorageLive(_6);
31+
StorageLive(_7);
32+
_7 = _3;
33+
- _6 = move _7 as *const u16 (PtrToPtr);
34+
+ _6 = _1;
35+
StorageDead(_7);
36+
StorageLive(_8);
37+
StorageLive(_9);
38+
_9 = _3;
39+
- _8 = move _9 as *const f32 (PtrToPtr);
40+
+ _8 = _1 as *const f32 (PtrToPtr);
41+
StorageDead(_9);
42+
- _0 = (move _6, move _8);
43+
+ _0 = (_1, move _8);
44+
StorageDead(_8);
45+
StorageDead(_6);
46+
- StorageDead(_3);
47+
+ nop;
48+
return;
49+
}
50+
}
51+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
- // MIR for `slice_from_raw_parts_as_ptr` before GVN
2+
+ // MIR for `slice_from_raw_parts_as_ptr` after GVN
3+
4+
fn slice_from_raw_parts_as_ptr(_1: *const u16, _2: usize) -> (*const u16, *const f32) {
5+
debug x => _1;
6+
debug n => _2;
7+
let mut _0: (*const u16, *const f32);
8+
let _3: *const [u16];
9+
let mut _4: *const u16;
10+
let mut _5: usize;
11+
let mut _6: *const u16;
12+
let mut _7: *const [u16];
13+
let mut _8: *const f32;
14+
let mut _9: *const [u16];
15+
scope 1 {
16+
debug ptr => _3;
17+
}
18+
19+
bb0: {
20+
- StorageLive(_3);
21+
+ nop;
22+
StorageLive(_4);
23+
_4 = _1;
24+
StorageLive(_5);
25+
_5 = _2;
26+
- _3 = *const [u16] from (move _4, move _5);
27+
+ _3 = *const [u16] from (_1, _2);
28+
StorageDead(_5);
29+
StorageDead(_4);
30+
StorageLive(_6);
31+
StorageLive(_7);
32+
_7 = _3;
33+
- _6 = move _7 as *const u16 (PtrToPtr);
34+
+ _6 = _1;
35+
StorageDead(_7);
36+
StorageLive(_8);
37+
StorageLive(_9);
38+
_9 = _3;
39+
- _8 = move _9 as *const f32 (PtrToPtr);
40+
+ _8 = _1 as *const f32 (PtrToPtr);
41+
StorageDead(_9);
42+
- _0 = (move _6, move _8);
43+
+ _0 = (_1, move _8);
44+
StorageDead(_8);
45+
StorageDead(_6);
46+
- StorageDead(_3);
47+
+ nop;
48+
return;
49+
}
50+
}
51+

‎tests/mir-opt/pre-codegen/ptr_offset.demo_byte_add_fat.PreCodegen.after.panic-abort.mir

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
1212
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
1313
}
1414
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
15-
let mut _5: *const ();
16-
let mut _6: usize;
15+
let mut _5: usize;
1716
scope 5 (inlined std::ptr::metadata::<[u32]>) {
1817
}
1918
scope 6 (inlined std::ptr::from_raw_parts::<[u32], ()>) {
@@ -28,11 +27,8 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
2827
_4 = Offset(_3, _2);
2928
StorageDead(_3);
3029
StorageLive(_5);
31-
_5 = _4 as *const () (PtrToPtr);
32-
StorageLive(_6);
33-
_6 = PtrMetadata(_1);
34-
_0 = *const [u32] from (_5, _6);
35-
StorageDead(_6);
30+
_5 = PtrMetadata(_1);
31+
_0 = *const [u32] from (_4, _5);
3632
StorageDead(_5);
3733
StorageDead(_4);
3834
return;

‎tests/mir-opt/pre-codegen/ptr_offset.demo_byte_add_fat.PreCodegen.after.panic-unwind.mir

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
1212
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
1313
}
1414
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
15-
let mut _5: *const ();
16-
let mut _6: usize;
15+
let mut _5: usize;
1716
scope 5 (inlined std::ptr::metadata::<[u32]>) {
1817
}
1918
scope 6 (inlined std::ptr::from_raw_parts::<[u32], ()>) {
@@ -28,11 +27,8 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
2827
_4 = Offset(_3, _2);
2928
StorageDead(_3);
3029
StorageLive(_5);
31-
_5 = _4 as *const () (PtrToPtr);
32-
StorageLive(_6);
33-
_6 = PtrMetadata(_1);
34-
_0 = *const [u32] from (_5, _6);
35-
StorageDead(_6);
30+
_5 = PtrMetadata(_1);
31+
_0 = *const [u32] from (_4, _5);
3632
StorageDead(_5);
3733
StorageDead(_4);
3834
return;

‎tests/mir-opt/pre-codegen/ptr_offset.demo_byte_add_thin.PreCodegen.after.panic-abort.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
2020
}
2121

2222
bb0: {
23+
StorageLive(_4);
2324
StorageLive(_3);
2425
_3 = _1 as *const u8 (PtrToPtr);
2526
_4 = Offset(_3, _2);
2627
StorageDead(_3);
2728
_0 = _4 as *const u32 (PtrToPtr);
29+
StorageDead(_4);
2830
return;
2931
}
3032
}

‎tests/mir-opt/pre-codegen/ptr_offset.demo_byte_add_thin.PreCodegen.after.panic-unwind.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
2020
}
2121

2222
bb0: {
23+
StorageLive(_4);
2324
StorageLive(_3);
2425
_3 = _1 as *const u8 (PtrToPtr);
2526
_4 = Offset(_3, _2);
2627
StorageDead(_3);
2728
_0 = _4 as *const u32 (PtrToPtr);
29+
StorageDead(_4);
2830
return;
2931
}
3032
}

0 commit comments

Comments
 (0)
This repository has been archived.