Skip to content

Commit

Permalink
Auto merge of rust-lang#136713 - matthiaskrgr:rollup-sy6py39, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135179 (Make sure to use `Receiver` trait when extracting object method candidate)
 - rust-lang#136554 (Add `opt_alias_variances` and use it in outlives code)
 - rust-lang#136556 ([AIX] Update tests/ui/wait-forked-but-failed-child.rs to accomodate exiting and idle processes.)
 - rust-lang#136589 (Enable "jump to def" feature on rustc docs)
 - rust-lang#136615 (sys: net: Add UEFI stubs)
 - rust-lang#136635 (Remove outdated `base_port` calculation in std net test)
 - rust-lang#136682 (Move two windows process tests to tests/ui)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 8, 2025
2 parents e060723 + 0a33d7c commit 0148a2b
Show file tree
Hide file tree
Showing 23 changed files with 722 additions and 234 deletions.
12 changes: 7 additions & 5 deletions compiler/rustc_borrowck/src/type_check/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ where
return;
}

match ty.kind() {
match *ty.kind() {
ty::Closure(_, args) => {
// Skip lifetime parameters of the enclosing item(s)

Expand Down Expand Up @@ -316,10 +316,12 @@ where
args.as_coroutine().resume_ty().visit_with(self);
}

ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// Skip lifetime parameters that are not captures.
let variances = self.tcx.variances_of(*def_id);

ty::Alias(kind, ty::AliasTy { def_id, args, .. })
if let Some(variances) = self.tcx.opt_alias_variances(kind, def_id) =>
{
// Skip lifetime parameters that are not captured, since they do
// not need member constraints registered for them; we'll erase
// them (and hopefully in the future replace them with placeholders).
for (v, s) in std::iter::zip(variances, args.iter()) {
if *v != ty::Bivariant {
s.visit_with(self);
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// yield an object-type (e.g., `&Object` or `Box<Object>`
// etc).

// FIXME: this feels, like, super dubious
self.fcx
.autoderef(self.span, self_ty)
let mut autoderef = self.fcx.autoderef(self.span, self_ty);

// We don't need to gate this behind arbitrary self types
// per se, but it does make things a bit more gated.
if self.tcx.features().arbitrary_self_types()
|| self.tcx.features().arbitrary_self_types_pointers()
{
autoderef = autoderef.use_receiver_trait();
}

autoderef
.include_raw_pointers()
.find_map(|(ty, _)| match ty.kind() {
ty::Dynamic(data, ..) => Some(closure(
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_infer/src/infer/outlives/for_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
return ty.super_visit_with(self);
}

match ty.kind() {
match *ty.kind() {
// We can prove that an alias is live two ways:
// 1. All the components are live.
//
Expand Down Expand Up @@ -95,11 +95,9 @@ where
assert!(r.type_flags().intersects(ty::TypeFlags::HAS_FREE_REGIONS));
r.visit_with(self);
} else {
// Skip lifetime parameters that are not captures.
let variances = match kind {
ty::Opaque => Some(self.tcx.variances_of(*def_id)),
_ => None,
};
// Skip lifetime parameters that are not captured, since they do
// not need to be live.
let variances = tcx.opt_alias_variances(kind, def_id);

for (idx, s) in args.iter().enumerate() {
if variances.map(|variances| variances[idx]) != Some(ty::Bivariant) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ where
// the problem is to add `T: 'r`, which isn't true. So, if there are no
// inference variables, we use a verify constraint instead of adding
// edges, which winds up enforcing the same condition.
let is_opaque = alias_ty.kind(self.tcx) == ty::Opaque;
let kind = alias_ty.kind(self.tcx);
if approx_env_bounds.is_empty()
&& trait_bounds.is_empty()
&& (alias_ty.has_infer_regions() || is_opaque)
&& (alias_ty.has_infer_regions() || kind == ty::Opaque)
{
debug!("no declared bounds");
let opt_variances = is_opaque.then(|| self.tcx.variances_of(alias_ty.def_id));
let opt_variances = self.tcx.opt_alias_variances(kind, alias_ty.def_id);
self.args_must_outlive(alias_ty.args, origin, region, opt_variances);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {

#[instrument(level = "debug", skip(self))]
pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
let alias_ty_as_ty = alias_ty.to_ty(self.tcx);

// Search the env for where clauses like `P: 'a`.
let env_bounds = self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder| {
if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars()
&& ty == alias_ty_as_ty
&& let ty::Alias(_, alias_ty_from_bound) = *ty.kind()
&& alias_ty_from_bound == alias_ty
{
// Micro-optimize if this is an exact match (this
// occurs often when there are no region variables
Expand All @@ -127,7 +126,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
// see the extensive comment in projection_must_outlive
let recursive_bound = {
let mut components = smallvec![];
compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components);
let kind = alias_ty.kind(self.tcx);
compute_alias_components_recursive(self.tcx, kind, alias_ty, &mut components);
self.bound_from_components(&components)
};

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,9 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
if tcx.sess.opts.unstable_opts.input_stats {
rustc_passes::input_stats::print_hir_stats(tcx);
}
#[cfg(debug_assertions)]
// When using rustdoc's "jump to def" feature, it enters this code and `check_crate`
// is not defined. So we need to cfg it out.
#[cfg(all(not(doc), debug_assertions))]
rustc_passes::hir_id_validator::check_crate(tcx);
let sess = tcx.sess;
sess.time("misc_checking_1", || {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.variances_of(def_id)
}

fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
def_id: DefId,
) -> Option<&'tcx [ty::Variance]> {
self.opt_alias_variances(kind, def_id)
}

fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
self.type_of(def_id)
}
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,29 @@ impl<'tcx> TyCtxt<'tcx> {

ty
}

// Computes the variances for an alias (opaque or RPITIT) that represent
// its (un)captured regions.
pub fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
def_id: DefId,
) -> Option<&'tcx [ty::Variance]> {
match kind.into() {
ty::AliasTermKind::ProjectionTy => {
if self.is_impl_trait_in_trait(def_id) {
Some(self.variances_of(def_id))
} else {
None
}
}
ty::AliasTermKind::OpaqueTy => Some(self.variances_of(def_id)),
ty::AliasTermKind::InherentTy
| ty::AliasTermKind::WeakTy
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => None,
}
}
}

struct OpaqueTypeExpander<'tcx> {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ pub trait Interner:
type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;

fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
def_id: Self::DefId,
) -> Option<Self::VariancesOf>;

fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>;

type AdtDef: AdtDef<Self>;
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_type_ir/src/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
// trait-ref. Therefore, if we see any higher-ranked regions,
// we simply fallback to the most restrictive rule, which
// requires that `Pi: 'a` for all `i`.
ty::Alias(_, alias_ty) => {
ty::Alias(kind, alias_ty) => {
if !alias_ty.has_escaping_bound_vars() {
// best case: no escaping regions, so push the
// projection and skip the subtree (thus generating no
Expand All @@ -162,7 +162,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
// OutlivesProjectionComponents. Continue walking
// through and constrain Pi.
let mut subcomponents = smallvec![];
compute_alias_components_recursive(self.cx, ty, &mut subcomponents);
compute_alias_components_recursive(self.cx, kind, alias_ty, &mut subcomponents);
self.out.push(Component::EscapingAlias(subcomponents.into_iter().collect()));
}
}
Expand Down Expand Up @@ -217,21 +217,17 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
}
}

/// Collect [Component]s for *all* the args of `parent`.
/// Collect [Component]s for *all* the args of `alias_ty`.
///
/// This should not be used to get the components of `parent` itself.
/// This should not be used to get the components of `alias_ty` itself.
/// Use [push_outlives_components] instead.
pub fn compute_alias_components_recursive<I: Interner>(
cx: I,
alias_ty: I::Ty,
kind: ty::AliasTyKind,
alias_ty: ty::AliasTy<I>,
out: &mut SmallVec<[Component<I>; 4]>,
) {
let ty::Alias(kind, alias_ty) = alias_ty.kind() else {
unreachable!("can only call `compute_alias_components_recursive` on an alias type")
};

let opt_variances =
if kind == ty::Opaque { Some(cx.variances_of(alias_ty.def_id)) } else { None };
let opt_variances = cx.opt_alias_variances(kind, alias_ty.def_id);

let mut visitor = OutlivesCollector { cx, out, visited: Default::default() };

Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_type_ir/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ impl AliasTermKind {
}
}

impl From<ty::AliasTyKind> for AliasTermKind {
fn from(value: ty::AliasTyKind) -> Self {
match value {
ty::Projection => AliasTermKind::ProjectionTy,
ty::Opaque => AliasTermKind::OpaqueTy,
ty::Weak => AliasTermKind::WeakTy,
ty::Inherent => AliasTermKind::InherentTy,
}
}
}

/// Represents the unprojected term of a projection goal.
///
/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.
Expand Down
28 changes: 7 additions & 21 deletions compiler/rustc_type_ir/src/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,14 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> {
ExpectedFound::new(a, b)
}))
} else {
let args = match a.kind(relation.cx()) {
ty::Opaque => relate_args_with_variances(
relation,
a.def_id,
relation.cx().variances_of(a.def_id),
a.args,
b.args,
let cx = relation.cx();
let args = if let Some(variances) = cx.opt_alias_variances(a.kind(cx), a.def_id) {
relate_args_with_variances(
relation, a.def_id, variances, a.args, b.args,
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
)?,
ty::Projection if relation.cx().is_impl_trait_in_trait(a.def_id) => {
relate_args_with_variances(
relation,
a.def_id,
relation.cx().variances_of(a.def_id),
a.args,
b.args,
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
)?
}
ty::Projection | ty::Weak | ty::Inherent => {
relate_args_invariantly(relation, a.args, b.args)?
}
)?
} else {
relate_args_invariantly(relation, a.args, b.args)?
};
Ok(ty::AliasTy::new_from_args(relation.cx(), a.def_id, args))
}
Expand Down
33 changes: 3 additions & 30 deletions library/std/src/net/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToS
use crate::sync::atomic::{AtomicUsize, Ordering};

static PORT: AtomicUsize = AtomicUsize::new(0);
const BASE_PORT: u16 = 19600;

pub fn next_test_ip4() -> SocketAddr {
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
}

pub fn next_test_ip6() -> SocketAddr {
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
}

Expand All @@ -30,31 +31,3 @@ pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
Err(e) => Err(e.to_string()),
}
}

// The bots run multiple builds at the same time, and these builds
// all want to use ports. This function figures out which workspace
// it is running in and assigns a port range based on it.
fn base_port() -> u16 {
let cwd = if cfg!(target_env = "sgx") {
String::from("sgx")
} else {
env::current_dir().unwrap().into_os_string().into_string().unwrap()
};
let dirs = [
"32-opt",
"32-nopt",
"musl-64-opt",
"cross-opt",
"64-opt",
"64-nopt",
"64-opt-vg",
"64-debug-opt",
"all-opt",
"snap3",
"dist",
"sgx",
];
dirs.iter().enumerate().find(|&(_, dir)| cwd.contains(dir)).map(|p| p.0).unwrap_or(0) as u16
* 1000
+ 19600
}
Loading

0 comments on commit 0148a2b

Please sign in to comment.