Skip to content

Commit 6eba9da

Browse files
authored
Merge branch 'master' into handle_potential_query_instability_lint_for_rustc_metadata
2 parents 1b8d81f + ad9c494 commit 6eba9da

File tree

178 files changed

+2762
-1902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+2762
-1902
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ tracking issue or there are none, feel free to ignore this.
77
This PR will get automatically assigned to a reviewer. In case you would like
88
a specific user to review your work, you can assign it to them by using
99
10-
r? <reviewer name>
10+
r\? <reviewer name> (with the `\` removed)
1111
-->
1212
<!-- homu-ignore:end -->

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ jobs:
212212
# erroring about invalid credentials instead.
213213
if: github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1'
214214

215+
- name: upload job metrics to DataDog
216+
if: needs.calculate_matrix.outputs.run_type != 'pr'
217+
env:
218+
DATADOG_SITE: datadoghq.com
219+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
220+
DD_GITHUB_JOB_NAME: ${{ matrix.name }}
221+
run: |
222+
npm install -g @datadog/datadog-ci@^2.x.x
223+
python3 src/ci/scripts/upload-build-metrics.py build/cpu-usage.csv
224+
215225
# This job isused to tell bors the final status of the build, as there is no practical way to detect
216226
# when a workflow is successful listening to webhooks only in our current bors implementation (homu).
217227
outcome:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,7 @@ dependencies = [
34513451
"rustc_span",
34523452
"rustc_symbol_mangling",
34533453
"rustc_target",
3454+
"rustc_trait_selection",
34543455
"rustc_type_ir",
34553456
"serde_json",
34563457
"smallvec",

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
use rustc_data_structures::fx::FxIndexMap;
42
use rustc_data_structures::graph;
53
use rustc_index::bit_set::BitSet;
@@ -425,10 +423,6 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
425423
Borrows { tcx, body, borrow_set, borrows_out_of_scope_at_location }
426424
}
427425

428-
pub fn location(&self, idx: BorrowIndex) -> &Location {
429-
&self.borrow_set[idx].reserve_location
430-
}
431-
432426
/// Add all borrows to the kill set, if those borrows are out of scope at `location`.
433427
/// That means they went out of a nonlexical scope
434428
fn kill_loans_out_of_scope_at_location(
@@ -615,8 +609,4 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
615609
}
616610
}
617611

618-
impl DebugWithContext<Borrows<'_, '_>> for BorrowIndex {
619-
fn fmt_with(&self, ctxt: &Borrows<'_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620-
write!(f, "{:?}", ctxt.location(*self))
621-
}
622-
}
612+
impl<C> DebugWithContext<C> for BorrowIndex {}

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! [`PointerCoercion::Unsize`]: `rustc_middle::ty::adjustment::PointerCoercion::Unsize`
44
5+
use rustc_codegen_ssa::base::validate_trivial_unsize;
56
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
67

78
use crate::base::codegen_panic_nounwind;
@@ -34,20 +35,8 @@ pub(crate) fn unsized_info<'tcx>(
3435
let old_info =
3536
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
3637
if data_a.principal_def_id() == data_b.principal_def_id() {
37-
// Codegen takes advantage of the additional assumption, where if the
38-
// principal trait def id of what's being casted doesn't change,
39-
// then we don't need to adjust the vtable at all. This
40-
// corresponds to the fact that `dyn Tr<A>: Unsize<dyn Tr<B>>`
41-
// requires that `A = B`; we don't allow *upcasting* objects
42-
// between the same trait with different args. If we, for
43-
// some reason, were to relax the `Unsize` trait, it could become
44-
// unsound, so let's assert here that the trait refs are *equal*.
45-
//
46-
// We can use `assert_eq` because the binders should have been anonymized,
47-
// and because higher-ranked equality now requires the binders are equal.
48-
debug_assert_eq!(
49-
data_a.principal(),
50-
data_b.principal(),
38+
debug_assert!(
39+
validate_trivial_unsize(fx.tcx, data_a, data_b),
5140
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
5241
);
5342
return old_info;

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rustc_session = { path = "../rustc_session" }
3434
rustc_span = { path = "../rustc_span" }
3535
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
3636
rustc_target = { path = "../rustc_target" }
37+
rustc_trait_selection = { path = "../rustc_trait_selection" }
3738
rustc_type_ir = { path = "../rustc_type_ir" }
3839
serde_json = "1.0.59"
3940
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,11 +2959,12 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
29592959
}
29602960
}
29612961

2962-
/// We need to communicate four things to the linker on Apple/Darwin targets:
2962+
/// We need to communicate five things to the linker on Apple/Darwin targets:
29632963
/// - The architecture.
29642964
/// - The operating system (and that it's an Apple platform).
2965-
/// - The deployment target.
29662965
/// - The environment / ABI.
2966+
/// - The deployment target.
2967+
/// - The SDK version.
29672968
fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29682969
if !sess.target.is_like_osx {
29692970
return;
@@ -3039,7 +3040,38 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30393040
let (major, minor, patch) = current_apple_deployment_target(&sess.target);
30403041
let min_version = format!("{major}.{minor}.{patch}");
30413042

3042-
// Lie about the SDK version, we don't know it here
3043+
// The SDK version is used at runtime when compiling with a newer SDK / version of Xcode:
3044+
// - By dyld to give extra warnings and errors, see e.g.:
3045+
// <https://github.com/apple-oss-distributions/dyld/blob/dyld-1165.3/common/MachOFile.cpp#L3029>
3046+
// <https://github.com/apple-oss-distributions/dyld/blob/dyld-1165.3/common/MachOFile.cpp#L3738-L3857>
3047+
// - By system frameworks to change certain behaviour. For example, the default value of
3048+
// `-[NSView wantsBestResolutionOpenGLSurface]` is `YES` when the SDK version is >= 10.15.
3049+
// <https://developer.apple.com/documentation/appkit/nsview/1414938-wantsbestresolutionopenglsurface?language=objc>
3050+
//
3051+
// We do not currently know the actual SDK version though, so we have a few options:
3052+
// 1. Use the minimum version supported by rustc.
3053+
// 2. Use the same as the deployment target.
3054+
// 3. Use an arbitary recent version.
3055+
// 4. Omit the version.
3056+
//
3057+
// The first option is too low / too conservative, and means that users will not get the
3058+
// same behaviour from a binary compiled with rustc as with one compiled by clang.
3059+
//
3060+
// The second option is similarly conservative, and also wrong since if the user specified a
3061+
// higher deployment target than the SDK they're compiling/linking with, the runtime might
3062+
// make invalid assumptions about the capabilities of the binary.
3063+
//
3064+
// The third option requires that `rustc` is periodically kept up to date with Apple's SDK
3065+
// version, and is also wrong for similar reasons as above.
3066+
//
3067+
// The fourth option is bad because while `ld`, `otool`, `vtool` and such understand it to
3068+
// mean "absent" or `n/a`, dyld doesn't actually understand it, and will end up interpreting
3069+
// it as 0.0, which is again too low/conservative.
3070+
//
3071+
// Currently, we lie about the SDK version, and choose the second option.
3072+
//
3073+
// FIXME(madsmtm): Parse the SDK version from the SDK root instead.
3074+
// <https://github.com/rust-lang/rust/issues/129432>
30433075
let sdk_version = &*min_version;
30443076

30453077
// From the man page for ld64 (`man ld`):
@@ -3053,11 +3085,13 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30533085
cmd.link_args(&["-platform_version", platform_name, &*min_version, sdk_version]);
30543086
} else {
30553087
// cc == Cc::Yes
3088+
//
30563089
// We'd _like_ to use `-target` everywhere, since that can uniquely
3057-
// communicate all the required details, but that doesn't work on GCC,
3058-
// and since we don't know whether the `cc` compiler is Clang, GCC, or
3059-
// something else, we fall back to other options that also work on GCC
3060-
// when compiling for macOS.
3090+
// communicate all the required details except for the SDK version
3091+
// (which is read by Clang itself from the SDKROOT), but that doesn't
3092+
// work on GCC, and since we don't know whether the `cc` compiler is
3093+
// Clang, GCC, or something else, we fall back to other options that
3094+
// also work on GCC when compiling for macOS.
30613095
//
30623096
// Targets other than macOS are ill-supported by GCC (it doesn't even
30633097
// support e.g. `-miphoneos-version-min`), so in those cases we can

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,17 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
402402
let platform =
403403
rustc_target::spec::current_apple_platform(target).expect("unknown Apple target OS");
404404
let min_os = rustc_target::spec::current_apple_deployment_target(target);
405-
let (sdk_major, sdk_minor) =
406-
rustc_target::spec::current_apple_sdk_version(platform).expect("unknown Apple target OS");
407405

408406
let mut build_version = object::write::MachOBuildVersion::default();
409407
build_version.platform = platform;
410408
build_version.minos = pack_version(min_os);
411-
build_version.sdk = pack_version((sdk_major, sdk_minor, 0));
409+
// The version here does not _really_ matter, since it is only used at runtime, and we specify
410+
// it when linking the final binary, so we will omit the version. This is also what LLVM does,
411+
// and the tooling also allows this (and shows the SDK version as `n/a`). Finally, it is the
412+
// semantically correct choice, as the SDK has not influenced the binary generated by rustc at
413+
// this point in time.
414+
build_version.sdk = 0;
415+
412416
build_version
413417
}
414418

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
2727
use rustc_span::symbol::sym;
2828
use rustc_span::{DUMMY_SP, Symbol};
2929
use rustc_target::abi::FIRST_VARIANT;
30+
use rustc_trait_selection::infer::at::ToTrace;
31+
use rustc_trait_selection::infer::{BoundRegionConversionTime, TyCtxtInferExt};
32+
use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
3033
use tracing::{debug, info};
3134

3235
use crate::assert_module_sources::CguReuse;
@@ -101,6 +104,54 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
101104
bx.sext(cmp, ret_ty)
102105
}
103106

107+
/// Codegen takes advantage of the additional assumption, where if the
108+
/// principal trait def id of what's being casted doesn't change,
109+
/// then we don't need to adjust the vtable at all. This
110+
/// corresponds to the fact that `dyn Tr<A>: Unsize<dyn Tr<B>>`
111+
/// requires that `A = B`; we don't allow *upcasting* objects
112+
/// between the same trait with different args. If we, for
113+
/// some reason, were to relax the `Unsize` trait, it could become
114+
/// unsound, so let's validate here that the trait refs are subtypes.
115+
pub fn validate_trivial_unsize<'tcx>(
116+
tcx: TyCtxt<'tcx>,
117+
source_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
118+
target_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
119+
) -> bool {
120+
match (source_data.principal(), target_data.principal()) {
121+
(Some(hr_source_principal), Some(hr_target_principal)) => {
122+
let infcx = tcx.infer_ctxt().build();
123+
let universe = infcx.universe();
124+
let ocx = ObligationCtxt::new(&infcx);
125+
infcx.enter_forall(hr_target_principal, |target_principal| {
126+
let source_principal = infcx.instantiate_binder_with_fresh_vars(
127+
DUMMY_SP,
128+
BoundRegionConversionTime::HigherRankedType,
129+
hr_source_principal,
130+
);
131+
let Ok(()) = ocx.eq_trace(
132+
&ObligationCause::dummy(),
133+
ty::ParamEnv::reveal_all(),
134+
ToTrace::to_trace(
135+
&ObligationCause::dummy(),
136+
hr_target_principal,
137+
hr_source_principal,
138+
),
139+
target_principal,
140+
source_principal,
141+
) else {
142+
return false;
143+
};
144+
if !ocx.select_all_or_error().is_empty() {
145+
return false;
146+
}
147+
infcx.leak_check(universe, None).is_ok()
148+
})
149+
}
150+
(None, None) => true,
151+
_ => false,
152+
}
153+
}
154+
104155
/// Retrieves the information we are losing (making dynamic) in an unsizing
105156
/// adjustment.
106157
///
@@ -133,12 +184,8 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
133184
// between the same trait with different args. If we, for
134185
// some reason, were to relax the `Unsize` trait, it could become
135186
// unsound, so let's assert here that the trait refs are *equal*.
136-
//
137-
// We can use `assert_eq` because the binders should have been anonymized,
138-
// and because higher-ranked equality now requires the binders are equal.
139-
debug_assert_eq!(
140-
data_a.principal(),
141-
data_b.principal(),
187+
debug_assert!(
188+
validate_trivial_unsize(cx.tcx(), data_a, data_b),
142189
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
143190
);
144191

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_middle::{bug, span_bug, ty};
66
use rustc_span::def_id::DefId;
77

88
use crate::interpret::{
9-
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, throw_machine_stop,
9+
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok,
10+
throw_machine_stop,
1011
};
1112

1213
/// Macro for machine-specific `InterpError` without allocation.
@@ -79,7 +80,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
7980
throw_machine_stop_str!("can't access mutable globals in ConstProp");
8081
}
8182

82-
Ok(())
83+
interp_ok(())
8384
}
8485

8586
fn find_mir_or_eval_fn(
@@ -127,7 +128,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
127128
right: &interpret::ImmTy<'tcx, Self::Provenance>,
128129
) -> interpret::InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
129130
use rustc_middle::mir::BinOp::*;
130-
Ok(match bin_op {
131+
interp_ok(match bin_op {
131132
Eq | Ne | Lt | Le | Gt | Ge => {
132133
// Types can differ, e.g. fn ptrs with different `for`.
133134
assert_eq!(left.layout.abi, right.layout.abi);

0 commit comments

Comments
 (0)