Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #104932

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ name = "cargo"
version = "0.68.0"
dependencies = [
"anyhow",
"atty",
"bytesize",
"cargo-platform 0.1.2",
"cargo-test-macro",
Expand All @@ -298,7 +297,7 @@ dependencies = [
"crates-io",
"curl",
"curl-sys",
"env_logger 0.9.0",
"env_logger 0.10.0",
"filetime",
"flate2",
"fwdansi",
Expand All @@ -312,6 +311,7 @@ dependencies = [
"ignore",
"im-rc",
"indexmap",
"is-terminal",
"itertools",
"jobserver",
"lazy_static",
Expand Down Expand Up @@ -1213,6 +1213,40 @@ dependencies = [
"termcolor",
]

[[package]]
name = "env_logger"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
dependencies = [
"humantime 2.0.1",
"is-terminal",
"log",
"regex",
"termcolor",
]

[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]

[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]

[[package]]
name = "error_index_generator"
version = "0.0.0"
Expand Down Expand Up @@ -1907,6 +1941,28 @@ dependencies = [
"unic-langid",
]

[[package]]
name = "io-lifetimes"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e394faa0efb47f9f227f1cd89978f854542b318a6f64fa695489c9c993056656"
dependencies = [
"libc",
"windows-sys",
]

[[package]]
name = "is-terminal"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d"
dependencies = [
"hermit-abi 0.2.6",
"io-lifetimes",
"rustix",
"windows-sys",
]

[[package]]
name = "itertools"
version = "0.10.5"
Expand Down Expand Up @@ -2116,6 +2172,12 @@ dependencies = [
"walkdir",
]

[[package]]
name = "linux-raw-sys"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"

[[package]]
name = "litemap"
version = "0.6.0"
Expand Down Expand Up @@ -4508,6 +4570,20 @@ dependencies = [
"unicode_categories",
]

[[package]]
name = "rustix"
version = "0.36.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]

[[package]]
name = "rustversion"
version = "1.0.5"
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ LLVMRustOptimize(
bool DebugPassManager = false;

PassInstrumentationCallbacks PIC;
#if LLVM_VERSION_LT(16, 0)
StandardInstrumentations SI(DebugPassManager);
#else
StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
#endif
SI.registerCallbacks(PIC);

if (LlvmSelfProfiler){
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/ty/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,16 @@ macro_rules! define_callbacks {

impl Default for Providers {
fn default() -> Self {
use crate::query::Key;

Providers {
$($name: |_, key| bug!(
"`tcx.{}({:?})` is not supported for external or local crate;\n
hint: Queries can be either made to the local crate, or the external crate. This error means you tried to use it for one that's not supported (likely the local crate).\n
"`tcx.{}({:?})` is not supported for {} crate;\n
hint: Queries can be either made to the local crate, or the external crate. This error means you tried to use it for one that's not supported.\n
If that's not the case, {} was likely never assigned to a provider function.\n",
stringify!($name),
key,
if key.query_crate_is_local() { "local" } else { "external" },
stringify!($name),
),)*
}
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ impl<'tcx> Inliner<'tcx> {
return Err("incompatible sanitizer set");
}

if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set {
// Two functions are compatible if the callee has no attribute (meaning
// that it's codegen agnostic), or sets an attribute that is identical
// to this function's attribute.
if callee_attrs.instruction_set.is_some()
&& callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set
{
return Err("incompatible instruction set");
}

Expand Down Expand Up @@ -453,6 +458,15 @@ impl<'tcx> Inliner<'tcx> {
if ty.needs_drop(tcx, self.param_env) && let Some(unwind) = unwind {
work_list.push(unwind);
}
} else if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set
&& matches!(term.kind, TerminatorKind::InlineAsm { .. })
{
// During the attribute checking stage we allow a callee with no
// instruction_set assigned to count as compatible with a function that does
// assign one. However, during this stage we require an exact match when any
// inline-asm is detected. LLVM will still possibly do an inline later on
// if the no-attribute function ends up with the same instruction set anyway.
return Err("Cannot move inline-asm across instruction sets");
} else {
work_list.extend(term.successors())
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern crate rustc_middle;
use rustc_data_structures::sync::AtomicU64;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::{self, DepKindStruct};
use rustc_middle::query::Key;
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
use rustc_middle::ty::TyCtxt;
Expand All @@ -32,8 +33,6 @@ use rustc_query_system::query::*;
#[cfg(parallel_compiler)]
pub use rustc_query_system::query::{deadlock, QueryContext};

use rustc_middle::query::Key;

pub use rustc_query_system::query::QueryConfig;
pub(crate) use rustc_query_system::query::QueryVTable;

Expand Down
157 changes: 50 additions & 107 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_infer::traits::ObligationCauseCode;
Expand Down Expand Up @@ -57,122 +55,67 @@ pub fn type_op_ascribe_user_type_with_span<'tcx>(
"type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}",
mir_ty, def_id, user_substs
);
let cx = AscribeUserTypeCx { ocx, param_env, span: span.unwrap_or(DUMMY_SP) };
cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs)?;
Ok(())
}
let span = span.unwrap_or(DUMMY_SP);

struct AscribeUserTypeCx<'me, 'tcx> {
ocx: &'me ObligationCtxt<'me, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span,
}
let UserSubsts { user_self_ty, substs } = user_substs;
let tcx = ocx.infcx.tcx;
let cause = ObligationCause::dummy_with_span(span);

impl<'me, 'tcx> AscribeUserTypeCx<'me, 'tcx> {
fn normalize<T>(&self, value: T) -> T
where
T: TypeFoldable<'tcx>,
{
self.normalize_with_cause(value, ObligationCause::misc(self.span, hir::CRATE_HIR_ID))
}
let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
let ty = ocx.normalize(cause.clone(), param_env, ty);
debug!("relate_type_and_user_type: ty of def-id is {:?}", ty);

fn normalize_with_cause<T>(&self, value: T, cause: ObligationCause<'tcx>) -> T
where
T: TypeFoldable<'tcx>,
{
self.ocx.normalize(cause, self.param_env, value)
}
ocx.eq(&cause, param_env, mir_ty, ty)?;

fn eq<T>(&self, a: T, b: T) -> Result<(), NoSolution>
where
T: ToTrace<'tcx>,
{
Ok(self.ocx.eq(&ObligationCause::dummy_with_span(self.span), self.param_env, a, b)?)
}
// Prove the predicates coming along with `def_id`.
//
// Also, normalize the `instantiated_predicates`
// because otherwise we wind up with duplicate "type
// outlives" error messages.
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);

fn prove_predicate(&self, predicate: Predicate<'tcx>, cause: ObligationCause<'tcx>) {
self.ocx.register_obligation(Obligation::new(
self.ocx.infcx.tcx,
cause,
self.param_env,
predicate,
));
}
debug!(?instantiated_predicates);
for (instantiated_predicate, predicate_span) in
zip(instantiated_predicates.predicates, instantiated_predicates.spans)
{
let span = if span == DUMMY_SP { predicate_span } else { span };
let cause = ObligationCause::new(
span,
hir::CRATE_HIR_ID,
ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span),
);
let instantiated_predicate =
ocx.normalize(cause.clone(), param_env, instantiated_predicate);

fn tcx(&self) -> TyCtxt<'tcx> {
self.ocx.infcx.tcx
ocx.register_obligation(Obligation::new(tcx, cause, param_env, instantiated_predicate));
}

#[instrument(level = "debug", skip(self))]
fn relate_mir_and_user_ty(
&self,
mir_ty: Ty<'tcx>,
def_id: DefId,
user_substs: UserSubsts<'tcx>,
) -> Result<(), NoSolution> {
let UserSubsts { user_self_ty, substs } = user_substs;
let tcx = self.tcx();

let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
let ty = self.normalize(ty);
debug!("relate_type_and_user_type: ty of def-id is {:?}", ty);

self.eq(mir_ty, ty)?;

// Prove the predicates coming along with `def_id`.
//
// Also, normalize the `instantiated_predicates`
// because otherwise we wind up with duplicate "type
// outlives" error messages.
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);

let cause = ObligationCause::dummy_with_span(self.span);

debug!(?instantiated_predicates);
for (instantiated_predicate, predicate_span) in
zip(instantiated_predicates.predicates, instantiated_predicates.spans)
{
let span = if self.span == DUMMY_SP { predicate_span } else { self.span };
let cause = ObligationCause::new(
span,
hir::CRATE_HIR_ID,
ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span),
);
let instantiated_predicate =
self.normalize_with_cause(instantiated_predicate, cause.clone());
self.prove_predicate(instantiated_predicate, cause);
}
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
let impl_self_ty = tcx.bound_type_of(impl_def_id).subst(tcx, substs);
let impl_self_ty = ocx.normalize(cause.clone(), param_env, impl_self_ty);

if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
let impl_self_ty = tcx.bound_type_of(impl_def_id).subst(tcx, substs);
let impl_self_ty = self.normalize(impl_self_ty);
ocx.eq(&cause, param_env, self_ty, impl_self_ty)?;

self.eq(self_ty, impl_self_ty)?;

self.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::WellFormed(impl_self_ty.into()))
.to_predicate(tcx),
cause.clone(),
);
}

// In addition to proving the predicates, we have to
// prove that `ty` is well-formed -- this is because
// the WF of `ty` is predicated on the substs being
// well-formed, and we haven't proven *that*. We don't
// want to prove the WF of types from `substs` directly because they
// haven't been normalized.
//
// FIXME(nmatsakis): Well, perhaps we should normalize
// them? This would only be relevant if some input
// type were ill-formed but did not appear in `ty`,
// which...could happen with normalization...
self.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into())).to_predicate(tcx),
cause,
);
Ok(())
let predicate: Predicate<'tcx> =
ty::Binder::dummy(ty::PredicateKind::WellFormed(impl_self_ty.into())).to_predicate(tcx);
ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, predicate));
}

// In addition to proving the predicates, we have to
// prove that `ty` is well-formed -- this is because
// the WF of `ty` is predicated on the substs being
// well-formed, and we haven't proven *that*. We don't
// want to prove the WF of types from `substs` directly because they
// haven't been normalized.
//
// FIXME(nmatsakis): Well, perhaps we should normalize
// them? This would only be relevant if some input
// type were ill-formed but did not appear in `ty`,
// which...could happen with normalization...
let predicate: Predicate<'tcx> =
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into())).to_predicate(tcx);
ocx.register_obligation(Obligation::new(tcx, cause, param_env, predicate));
Ok(())
}

fn type_op_eq<'tcx>(
Expand Down
Loading