Skip to content

Rollup of 8 pull requests #113475

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c37afcd
Enable zlib in LLVM on aarch64-apple-darwin
cbeuw Jun 22, 2023
d43131b
Bump download-ci-llvm-stamp
cbeuw Jun 24, 2023
181d7b4
tests: unset `RUSTC_LOG_COLOR`
davidtwco Jun 29, 2023
f880246
CI: include workflow name in concurrency group
Kobzol Jun 29, 2023
142075a
Make `UsageMap::get_user_items` infallible.
nnethercote Jul 4, 2023
22d4c79
Use `iter()` instead of `iter_mut()` in one place.
nnethercote Jul 4, 2023
b51169c
Remove the field name from `MonoItemPlacement::SingleCgu`.
nnethercote Jul 5, 2023
3078e4d
Minor comment fix.
nnethercote Jul 6, 2023
906d2b1
Structurally normalize again for byte string lit pat checking
compiler-errors Jul 6, 2023
284df9f
Wrap SMIR bool and tuple into a Rigid variant
spastorino Jun 28, 2023
d03b0f5
If re-export is private, get the next item until a public one is foun…
GuillaumeGomez Jul 5, 2023
e3b7035
Add regression test for #81141
GuillaumeGomez Jul 5, 2023
52a7615
Improve code readability
GuillaumeGomez Jul 7, 2023
f37a6b0
Extend issue-81141-private-reexport-in-public-api test to cover more …
GuillaumeGomez Jul 7, 2023
1d1951b
Rename `first_not_private` into `first_non_private`
GuillaumeGomez Jul 7, 2023
010ee7b
Remove an AFIT test that isn't an AFIT test
compiler-errors Jul 4, 2023
713f9bb
Mark more hanging new-solver tests
compiler-errors Jul 4, 2023
f55b046
Normalize opaques during codegen in new solver
compiler-errors Jul 4, 2023
61adcaf
Add rustc_ty_to_ty basic tests
spastorino Jul 5, 2023
73e816e
Add Char ty to SMIR
spastorino Jul 5, 2023
458ead4
Add Int ty to SMIR
spastorino Jul 5, 2023
42eccff
Add Uint ty to SMIR
spastorino Jul 5, 2023
9ca51b9
Add Float ty to SMIR
spastorino Jul 5, 2023
4a1e06b
Correctly handle `super` and `::`
GuillaumeGomez Jul 7, 2023
b48f2b3
Rollup merge of #112931 - cbeuw:apple-zlib, r=Mark-Simulacrum
compiler-errors Jul 8, 2023
eb3b666
Rollup merge of #113158 - davidtwco:unset-rustc-log-color-in-test, r=…
compiler-errors Jul 8, 2023
4736bf8
Rollup merge of #113173 - Kobzol:ci-concurrency-group-workflow, r=pie…
compiler-errors Jul 8, 2023
1f98612
Rollup merge of #113335 - compiler-errors:reveal-opaques-in-new-solve…
compiler-errors Jul 8, 2023
0d14e26
Rollup merge of #113374 - GuillaumeGomez:private-to-public-path, r=no…
compiler-errors Jul 8, 2023
1df22bd
Rollup merge of #113390 - nnethercote:cgu-tweaks, r=wesleywiser
compiler-errors Jul 8, 2023
297e480
Rollup merge of #113399 - compiler-errors:next-solver-byte-pat-again,…
compiler-errors Jul 8, 2023
ed2cc0d
Rollup merge of #113412 - spastorino:smir-types-1, r=oli-obk
compiler-errors Jul 8, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defaults:
run:
shell: bash
concurrency:
group: "${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}"
group: "${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}"
cancel-in-progress: true
jobs:
pr:
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut pat_ty = ty;
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
let expected = self.structurally_resolve_type(span, expected);
if let ty::Ref(_, inner_ty, _) = expected.kind()
&& matches!(inner_ty.kind(), ty::Slice(_))
if let ty::Ref(_, inner_ty, _) = *expected.kind()
&& self.try_structurally_resolve_type(span, inner_ty).is_slice()
{
let tcx = self.tcx;
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ impl<'tcx> UsageMap<'tcx> {
assert!(self.used_map.insert(user_item, used_items).is_none());
}

pub fn get_user_items(&self, item: MonoItem<'tcx>) -> Option<&[MonoItem<'tcx>]> {
self.user_map.get(&item).map(|items| items.as_slice())
pub fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] {
self.user_map.get(&item).map(|items| items.as_slice()).unwrap_or(&[])
}

/// Internally iterate over all inlined items used by `item`.
Expand Down
44 changes: 22 additions & 22 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ fn merge_codegen_units<'tcx>(
// zero-padded suffixes, which means they are automatically sorted by
// names. The numeric suffix width depends on the number of CGUs, which
// is always greater than zero:
// - [1,9] CGUS: `0`, `1`, `2`, ...
// - [10,99] CGUS: `00`, `01`, `02`, ...
// - [100,999] CGUS: `000`, `001`, `002`, ...
// - [1,9] CGUs: `0`, `1`, `2`, ...
// - [10,99] CGUs: `00`, `01`, `02`, ...
// - [100,999] CGUs: `000`, `001`, `002`, ...
// - etc.
//
// If we didn't zero-pad the sorted-by-name order would be `XYZ-cgu.0`,
Expand Down Expand Up @@ -458,29 +458,29 @@ fn internalize_symbols<'tcx>(
/// used to keep track of that.
#[derive(Clone, PartialEq, Eq, Debug)]
enum MonoItemPlacement {
SingleCgu { cgu_name: Symbol },
SingleCgu(Symbol),
MultipleCgus,
}

let mut mono_item_placements = FxHashMap::default();
let single_codegen_unit = codegen_units.len() == 1;

if !single_codegen_unit {
for cgu in codegen_units.iter_mut() {
for cgu in codegen_units.iter() {
for item in cgu.items().keys() {
// If there is more than one codegen unit, we need to keep track
// in which codegen units each monomorphization is placed.
match mono_item_placements.entry(*item) {
Entry::Occupied(e) => {
let placement = e.into_mut();
debug_assert!(match *placement {
MonoItemPlacement::SingleCgu { cgu_name } => cgu_name != cgu.name(),
MonoItemPlacement::SingleCgu(cgu_name) => cgu_name != cgu.name(),
MonoItemPlacement::MultipleCgus => true,
});
*placement = MonoItemPlacement::MultipleCgus;
}
Entry::Vacant(e) => {
e.insert(MonoItemPlacement::SingleCgu { cgu_name: cgu.name() });
e.insert(MonoItemPlacement::SingleCgu(cgu.name()));
}
}
}
Expand All @@ -490,7 +490,7 @@ fn internalize_symbols<'tcx>(
// For each internalization candidates in each codegen unit, check if it is
// used from outside its defining codegen unit.
for cgu in codegen_units {
let home_cgu = MonoItemPlacement::SingleCgu { cgu_name: cgu.name() };
let home_cgu = MonoItemPlacement::SingleCgu(cgu.name());

for (item, linkage_and_visibility) in cgu.items_mut() {
if !internalization_candidates.contains(item) {
Expand All @@ -501,20 +501,20 @@ fn internalize_symbols<'tcx>(
if !single_codegen_unit {
debug_assert_eq!(mono_item_placements[item], home_cgu);

if let Some(user_items) = cx.usage_map.get_user_items(*item) {
if user_items
.iter()
.filter_map(|user_item| {
// Some user mono items might not have been
// instantiated. We can safely ignore those.
mono_item_placements.get(user_item)
})
.any(|placement| *placement != home_cgu)
{
// Found a user from another CGU, so skip to the next item
// without marking this one as internal.
continue;
}
if cx
.usage_map
.get_user_items(*item)
.iter()
.filter_map(|user_item| {
// Some user mono items might not have been
// instantiated. We can safely ignore those.
mono_item_placements.get(user_item)
})
.any(|placement| *placement != home_cgu)
{
// Found a user from another CGU, so skip to the next item
// without marking this one as internal.
continue;
}
}

Expand Down
36 changes: 27 additions & 9 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//!
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.

use crate::stable_mir::{self, ty::TyKind, Context};
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
use crate::stable_mir::{self, Context};
use rustc_middle::mir;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
Expand Down Expand Up @@ -69,11 +70,28 @@ pub struct Tables<'tcx> {
impl<'tcx> Tables<'tcx> {
fn rustc_ty_to_ty(&mut self, ty: Ty<'tcx>) -> TyKind {
match ty.kind() {
ty::Bool => TyKind::Bool,
ty::Char => todo!(),
ty::Int(_) => todo!(),
ty::Uint(_) => todo!(),
ty::Float(_) => todo!(),
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
ty::Char => TyKind::RigidTy(RigidTy::Char),
ty::Int(int_ty) => match int_ty {
ty::IntTy::Isize => TyKind::RigidTy(RigidTy::Int(IntTy::Isize)),
ty::IntTy::I8 => TyKind::RigidTy(RigidTy::Int(IntTy::I8)),
ty::IntTy::I16 => TyKind::RigidTy(RigidTy::Int(IntTy::I16)),
ty::IntTy::I32 => TyKind::RigidTy(RigidTy::Int(IntTy::I32)),
ty::IntTy::I64 => TyKind::RigidTy(RigidTy::Int(IntTy::I64)),
ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)),
},
ty::Uint(uint_ty) => match uint_ty {
ty::UintTy::Usize => TyKind::RigidTy(RigidTy::Uint(UintTy::Usize)),
ty::UintTy::U8 => TyKind::RigidTy(RigidTy::Uint(UintTy::U8)),
ty::UintTy::U16 => TyKind::RigidTy(RigidTy::Uint(UintTy::U16)),
ty::UintTy::U32 => TyKind::RigidTy(RigidTy::Uint(UintTy::U32)),
ty::UintTy::U64 => TyKind::RigidTy(RigidTy::Uint(UintTy::U64)),
ty::UintTy::U128 => TyKind::RigidTy(RigidTy::Uint(UintTy::U128)),
},
ty::Float(float_ty) => match float_ty {
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
},
ty::Adt(_, _) => todo!(),
ty::Foreign(_) => todo!(),
ty::Str => todo!(),
Expand All @@ -90,9 +108,9 @@ impl<'tcx> Tables<'tcx> {
ty::GeneratorWitness(_) => todo!(),
ty::GeneratorWitnessMIR(_, _) => todo!(),
ty::Never => todo!(),
ty::Tuple(fields) => {
TyKind::Tuple(fields.iter().map(|ty| self.intern_ty(ty)).collect())
}
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
fields.iter().map(|ty| self.intern_ty(ty)).collect(),
)),
ty::Alias(_, _) => todo!(),
ty::Param(_) => todo!(),
ty::Bound(_, _) => todo!(),
Expand Down
36 changes: 36 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,43 @@ impl Ty {
}
}

#[derive(Clone, Debug)]
pub enum TyKind {
RigidTy(RigidTy),
}

#[derive(Clone, Debug)]
pub enum RigidTy {
Bool,
Char,
Int(IntTy),
Uint(UintTy),
Float(FloatTy),
Tuple(Vec<Ty>),
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IntTy {
Isize,
I8,
I16,
I32,
I64,
I128,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum UintTy {
Usize,
U8,
U16,
U32,
U64,
U128,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FloatTy {
F32,
F64,
}
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/solve/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
// We don't normalize opaque types unless we have
// `Reveal::All`, even if we're in the defining scope.
let data = match *ty.kind() {
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::UserFacing => {
alias_ty
}
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::All => alias_ty,
_ => return ty.try_super_fold_with(self),
};

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/download-ci-llvm-stamp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Change this file to make users of the `download-ci-llvm` configuration download
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.

Last change is for: https://github.com/rust-lang/rust/pull/96971
Last change is for: https://github.com/rust-lang/rust/pull/112931
2 changes: 1 addition & 1 deletion src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl Step for Llvm {
// Disable zstd to avoid a dependency on libzstd.so.
cfg.define("LLVM_ENABLE_ZSTD", "OFF");

if target != "aarch64-apple-darwin" && !target.contains("windows") {
if !target.contains("windows") {
cfg.define("LLVM_ENABLE_ZLIB", "ON");
} else {
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
Expand Down
2 changes: 1 addition & 1 deletion src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ concurrency:
# For a given workflow, if we push to the same branch, cancel all previous builds on that branch.
# We add an exception for try builds (try branch) and unrolled rollup builds (try-perf), which
# are all triggered on the same branch, but which should be able to run concurrently.
group: ${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}
group: ${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}
cancel-in-progress: true

jobs:
Expand Down
100 changes: 97 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,97 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
Item::from_def_id_and_parts(assoc_item.def_id, Some(assoc_item.name), kind, cx)
}

/// The goal of this function is to return the first `Path` which is not private (ie not private
/// or `doc(hidden)`). If it's not possible, it'll return the "end type".
///
/// If the path is not a re-export or is public, it'll return `None`.
fn first_non_private(
cx: &mut DocContext<'_>,
hir_id: hir::HirId,
path: &hir::Path<'_>,
) -> Option<Path> {
let (parent_def_id, mut ident) = match &path.segments[..] {
[] => return None,
// Relative paths are available in the same scope as the owner.
[leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident),
// So are self paths.
[parent, leaf] if parent.ident.name == kw::SelfLower => {
(cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident)
}
// Crate paths are not. We start from the crate root.
[parent, leaf] if matches!(parent.ident.name, kw::Crate | kw::PathRoot) => {
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
}
[parent, leaf] if parent.ident.name == kw::Super => {
let parent_mod = cx.tcx.parent_module(hir_id);
if let Some(super_parent) = cx.tcx.opt_local_parent(parent_mod) {
(super_parent, leaf.ident)
} else {
// If we can't find the parent of the parent, then the parent is already the crate.
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
}
}
// Absolute paths are not. We start from the parent of the item.
[.., parent, leaf] => (parent.res.opt_def_id()?.as_local()?, leaf.ident),
};
let target_def_id = path.res.opt_def_id()?;
// First we try to get the `DefId` of the item.
for child in
cx.tcx.module_children_local(parent_def_id).iter().filter(move |c| c.ident == ident)
{
if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = child.res {
continue;
}

if let Some(def_id) = child.res.opt_def_id() && target_def_id == def_id {
let mut last_path_res = None;
'reexps: for reexp in child.reexport_chain.iter() {
if let Some(use_def_id) = reexp.id() &&
let Some(local_use_def_id) = use_def_id.as_local()
{
let hir = cx.tcx.hir();
for item_id in hir.module_items(cx.tcx.local_parent(local_use_def_id)) {
let item = hir.item(item_id);
if item.ident == ident && let hir::ItemKind::Use(path, _) = item.kind {
for res in &path.res {
if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = res {
continue;
}
if !cx.tcx.is_doc_hidden(use_def_id) &&
cx.tcx.local_visibility(local_use_def_id).is_public() {
break 'reexps;
}
ident = path.segments.last().unwrap().ident;
last_path_res = Some((path, res));
continue 'reexps;
}
}
}
}
}
if !child.reexport_chain.is_empty() {
// So in here, we use the data we gathered from iterating the reexports. If
// `last_path_res` is set, it can mean two things:
//
// 1. We found a public reexport.
// 2. We didn't find a public reexport so it's the "end type" path.
if let Some((path, res)) = last_path_res {
let path = hir::Path { segments: path.segments, res: *res, span: path.span };
return Some(clean_path(&path, cx));
}
// If `last_path_res` is `None`, it can mean two things:
//
// 1. The re-export is public, no need to change anything, just use the path as is.
// 2. Nothing was found, so let's just return the original path.
return None;
}
}
}
None
}

fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type {
let hir::Ty { hir_id: _, span, ref kind } = *hir_ty;
let hir::Ty { hir_id, span, ref kind } = *hir_ty;
let hir::TyKind::Path(qpath) = kind else { unreachable!() };

match qpath {
Expand All @@ -1497,7 +1586,12 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
if let Some(expanded) = maybe_expand_private_type_alias(cx, path) {
expanded
} else {
let path = clean_path(path, cx);
// First we check if it's a private re-export.
let path = if let Some(path) = first_non_private(cx, hir_id, &path) {
path
} else {
clean_path(path, cx)
};
resolve_type(cx, path)
}
}
Expand Down Expand Up @@ -1649,7 +1743,7 @@ fn maybe_expand_private_type_alias<'tcx>(
}
}

Some(cx.enter_alias(substs, def_id.to_def_id(), |cx| clean_ty(ty, cx)))
Some(cx.enter_alias(substs, def_id.to_def_id(), |cx| clean_ty(&ty, cx)))
}

pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type {
Expand Down
13 changes: 13 additions & 0 deletions tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// edition:2015

#![crate_name = "foo"]

use external::Public as Private;

pub mod external {
pub struct Public;

// @has 'foo/external/fn.make.html'
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public'
pub fn make() -> ::Private { super::Private }
}
Loading