Skip to content

Commit fc14dc6

Browse files
committed
Auto merge of #154203 - Zalathar:rollup-tqV88T3, r=Zalathar
Rollup of 7 pull requests Successful merges: - #122668 (Add APIs for dealing with titlecase) - #153312 (Packages as namespaces part 1) - #153534 (Remove a flaky `got_timeout` assert from two channel tests) - #154175 (Add new alias for Guillaume Gomez email address) - #154182 (diagnostics: avoid ICE for undeclared generic parameter in impl) - #154188 (Update the tracking issue for #[diagnostic::on_move]) - #154201 (Use enums to clarify `DepNodeColorMap` color marking )
2 parents 562dee4 + 8375bdd commit fc14dc6

53 files changed

Lines changed: 1173 additions & 202 deletions

Some content is hidden

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

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Guillaume Gomez <guillaume1.gomez@gmail.com>
262262
Guillaume Gomez <guillaume1.gomez@gmail.com> ggomez <ggomez@ggo.ifr.lan>
263263
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <ggomez@ggo.ifr.lan>
264264
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <guillaume.gomez@huawei.com>
265+
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <contact@guillaume-gomez.fr>
265266
gnzlbg <gonzalobg88@gmail.com> <gnzlbg@users.noreply.github.com>
266267
hamidreza kalbasi <hamidrezakalbasi@protonmail.com>
267268
Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ declare_features! (
473473
/// Allows giving non-const impls custom diagnostic messages if attempted to be used as const
474474
(unstable, diagnostic_on_const, "1.93.0", Some(143874)),
475475
/// Allows giving on-move borrowck custom diagnostic messages for a type
476-
(unstable, diagnostic_on_move, "CURRENT_RUSTC_VERSION", Some(150935)),
476+
(unstable, diagnostic_on_move, "CURRENT_RUSTC_VERSION", Some(154181)),
477477
/// Allows `#[doc(cfg(...))]`.
478478
(unstable, doc_cfg, "1.21.0", Some(43781)),
479479
/// Allows `#[doc(masked)]`.

compiler/rustc_hir/src/def.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,13 @@ pub enum Res<Id = hir::HirId> {
590590
/// **Belongs to the type namespace.**
591591
ToolMod,
592592

593+
/// The resolution for an open module in a namespaced crate. E.g. `my_api`
594+
/// in the namespaced crate `my_api::utils` when `my_api` isn't part of the
595+
/// extern prelude.
596+
///
597+
/// **Belongs to the type namespace.**
598+
OpenMod(Symbol),
599+
593600
// Macro namespace
594601
/// An attribute that is *not* implemented via macro.
595602
/// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
@@ -838,6 +845,7 @@ impl<Id> Res<Id> {
838845
| Res::SelfTyAlias { .. }
839846
| Res::SelfCtor(..)
840847
| Res::ToolMod
848+
| Res::OpenMod(..)
841849
| Res::NonMacroAttr(..)
842850
| Res::Err => None,
843851
}
@@ -869,6 +877,7 @@ impl<Id> Res<Id> {
869877
Res::Local(..) => "local variable",
870878
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => "self type",
871879
Res::ToolMod => "tool module",
880+
Res::OpenMod(..) => "namespaced crate",
872881
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
873882
Res::Err => "unresolved item",
874883
}
@@ -895,6 +904,7 @@ impl<Id> Res<Id> {
895904
Res::SelfTyAlias { alias_to, is_trait_impl }
896905
}
897906
Res::ToolMod => Res::ToolMod,
907+
Res::OpenMod(sym) => Res::OpenMod(sym),
898908
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
899909
Res::Err => Res::Err,
900910
}
@@ -911,6 +921,7 @@ impl<Id> Res<Id> {
911921
Res::SelfTyAlias { alias_to, is_trait_impl }
912922
}
913923
Res::ToolMod => Res::ToolMod,
924+
Res::OpenMod(sym) => Res::OpenMod(sym),
914925
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
915926
Res::Err => Res::Err,
916927
})
@@ -936,9 +947,11 @@ impl<Id> Res<Id> {
936947
pub fn ns(&self) -> Option<Namespace> {
937948
match self {
938949
Res::Def(kind, ..) => kind.ns(),
939-
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::ToolMod => {
940-
Some(Namespace::TypeNS)
941-
}
950+
Res::PrimTy(..)
951+
| Res::SelfTyParam { .. }
952+
| Res::SelfTyAlias { .. }
953+
| Res::ToolMod
954+
| Res::OpenMod(..) => Some(Namespace::TypeNS),
942955
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
943956
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
944957
Res::Err => None,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
28302830
| Res::SelfCtor(_)
28312831
| Res::Local(_)
28322832
| Res::ToolMod
2833+
| Res::OpenMod(..)
28332834
| Res::NonMacroAttr(_)
28342835
| Res::Err) => Const::new_error_with_message(
28352836
tcx,

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ impl DepGraph {
164164
);
165165
assert_eq!(red_node_index, DepNodeIndex::FOREVER_RED_NODE);
166166
if prev_graph_node_count > 0 {
167-
colors.insert_red(SerializedDepNodeIndex::from_u32(
168-
DepNodeIndex::FOREVER_RED_NODE.as_u32(),
169-
));
167+
let prev_index =
168+
const { SerializedDepNodeIndex::from_u32(DepNodeIndex::FOREVER_RED_NODE.as_u32()) };
169+
let result = colors.try_set_color(prev_index, DesiredColor::Red);
170+
assert_matches!(result, TrySetColorResult::Success);
170171
}
171172

172173
DepGraph {
@@ -1415,28 +1416,29 @@ impl DepNodeColorMap {
14151416
if value <= DepNodeIndex::MAX_AS_U32 { Some(DepNodeIndex::from_u32(value)) } else { None }
14161417
}
14171418

1418-
/// This tries to atomically mark a node green and assign `index` as the new
1419-
/// index if `green` is true, otherwise it will try to atomicaly mark it red.
1419+
/// Atomically sets the color of a previous-session dep node to either green
1420+
/// or red, if it has not already been colored.
14201421
///
1421-
/// This returns `Ok` if `index` gets assigned or the node is marked red, otherwise it returns
1422-
/// the already allocated index in `Err` if it is green already. If it was already
1423-
/// red, `Err(None)` is returned.
1422+
/// If the node already has a color, the new color is ignored, and the
1423+
/// return value indicates the existing color.
14241424
#[inline(always)]
1425-
pub(super) fn try_mark(
1425+
pub(super) fn try_set_color(
14261426
&self,
14271427
prev_index: SerializedDepNodeIndex,
1428-
index: DepNodeIndex,
1429-
green: bool,
1430-
) -> Result<(), Option<DepNodeIndex>> {
1431-
let value = &self.values[prev_index];
1432-
match value.compare_exchange(
1428+
color: DesiredColor,
1429+
) -> TrySetColorResult {
1430+
match self.values[prev_index].compare_exchange(
14331431
COMPRESSED_UNKNOWN,
1434-
if green { index.as_u32() } else { COMPRESSED_RED },
1432+
match color {
1433+
DesiredColor::Red => COMPRESSED_RED,
1434+
DesiredColor::Green { index } => index.as_u32(),
1435+
},
14351436
Ordering::Relaxed,
14361437
Ordering::Relaxed,
14371438
) {
1438-
Ok(_) => Ok(()),
1439-
Err(v) => Err(if v == COMPRESSED_RED { None } else { Some(DepNodeIndex::from_u32(v)) }),
1439+
Ok(_) => TrySetColorResult::Success,
1440+
Err(COMPRESSED_RED) => TrySetColorResult::AlreadyRed,
1441+
Err(index) => TrySetColorResult::AlreadyGreen { index: DepNodeIndex::from_u32(index) },
14401442
}
14411443
}
14421444

@@ -1454,13 +1456,28 @@ impl DepNodeColorMap {
14541456
DepNodeColor::Unknown
14551457
}
14561458
}
1459+
}
14571460

1458-
#[inline]
1459-
pub(super) fn insert_red(&self, index: SerializedDepNodeIndex) {
1460-
let value = self.values[index].swap(COMPRESSED_RED, Ordering::Release);
1461-
// Sanity check for duplicate nodes
1462-
assert_eq!(value, COMPRESSED_UNKNOWN, "tried to color an already colored node as red");
1463-
}
1461+
/// The color that [`DepNodeColorMap::try_set_color`] should try to apply to a node.
1462+
#[derive(Clone, Copy, Debug)]
1463+
pub(super) enum DesiredColor {
1464+
/// Try to mark the node red.
1465+
Red,
1466+
/// Try to mark the node green, associating it with a current-session node index.
1467+
Green { index: DepNodeIndex },
1468+
}
1469+
1470+
/// Return value of [`DepNodeColorMap::try_set_color`], indicating success or failure,
1471+
/// and (on failure) what the existing color is.
1472+
#[derive(Clone, Copy, Debug)]
1473+
pub(super) enum TrySetColorResult {
1474+
/// The [`DesiredColor`] was freshly applied to the node.
1475+
Success,
1476+
/// Coloring failed because the node was already marked red.
1477+
AlreadyRed,
1478+
/// Coloring failed because the node was already marked green,
1479+
/// and corresponds to node `index` in the current-session dep graph.
1480+
AlreadyGreen { index: DepNodeIndex },
14641481
}
14651482

14661483
#[inline(never)]

compiler/rustc_middle/src/dep_graph/serialized.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
5858
use rustc_session::Session;
5959
use tracing::{debug, instrument};
6060

61-
use super::graph::{CurrentDepGraph, DepNodeColorMap};
61+
use super::graph::{CurrentDepGraph, DepNodeColorMap, DesiredColor, TrySetColorResult};
6262
use super::retained::RetainedDepGraph;
6363
use super::{DepKind, DepNode, DepNodeIndex};
6464
use crate::dep_graph::edges::EdgesVec;
@@ -905,13 +905,14 @@ impl GraphEncoder {
905905
let mut local = self.status.local.borrow_mut();
906906

907907
let index = self.status.next_index(&mut *local);
908+
let color = if is_green { DesiredColor::Green { index } } else { DesiredColor::Red };
908909

909-
// Use `try_mark` to avoid racing when `send_promoted` is called concurrently
910+
// Use `try_set_color` to avoid racing when `send_promoted` is called concurrently
910911
// on the same index.
911-
match colors.try_mark(prev_index, index, is_green) {
912-
Ok(()) => (),
913-
Err(None) => panic!("dep node {:?} is unexpectedly red", prev_index),
914-
Err(Some(dep_node_index)) => return dep_node_index,
912+
match colors.try_set_color(prev_index, color) {
913+
TrySetColorResult::Success => {}
914+
TrySetColorResult::AlreadyRed => panic!("dep node {prev_index:?} is unexpectedly red"),
915+
TrySetColorResult::AlreadyGreen { index } => return index,
915916
}
916917

917918
self.status.bump_index(&mut *local);
@@ -923,7 +924,8 @@ impl GraphEncoder {
923924
/// from the previous dep graph and expects all edges to already have a new dep node index
924925
/// assigned.
925926
///
926-
/// This will also ensure the dep node is marked green if `Some` is returned.
927+
/// Tries to mark the dep node green, and returns Some if it is now green,
928+
/// or None if had already been concurrently marked red.
927929
#[inline]
928930
pub(crate) fn send_promoted(
929931
&self,
@@ -935,10 +937,10 @@ impl GraphEncoder {
935937
let mut local = self.status.local.borrow_mut();
936938
let index = self.status.next_index(&mut *local);
937939

938-
// Use `try_mark_green` to avoid racing when `send_promoted` or `send_and_color`
940+
// Use `try_set_color` to avoid racing when `send_promoted` or `send_and_color`
939941
// is called concurrently on the same index.
940-
match colors.try_mark(prev_index, index, true) {
941-
Ok(()) => {
942+
match colors.try_set_color(prev_index, DesiredColor::Green { index }) {
943+
TrySetColorResult::Success => {
942944
self.status.bump_index(&mut *local);
943945
self.status.encode_promoted_node(
944946
index,
@@ -949,7 +951,8 @@ impl GraphEncoder {
949951
);
950952
Some(index)
951953
}
952-
Err(dep_node_index) => dep_node_index,
954+
TrySetColorResult::AlreadyRed => None,
955+
TrySetColorResult::AlreadyGreen { index } => Some(index),
953956
}
954957
}
955958

compiler/rustc_passes/src/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
157157
Res::Def(_, def_id) => self.check_def_id(def_id),
158158
Res::SelfTyParam { trait_: t } => self.check_def_id(t),
159159
Res::SelfTyAlias { alias_to: i, .. } => self.check_def_id(i),
160-
Res::ToolMod | Res::NonMacroAttr(..) | Res::Err => {}
160+
Res::ToolMod | Res::NonMacroAttr(..) | Res::OpenMod(..) | Res::Err => {}
161161
}
162162
}
163163

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
357357
| Res::SelfTyParam { .. }
358358
| Res::SelfTyAlias { .. }
359359
| Res::SelfCtor(..)
360+
| Res::OpenMod(..)
360361
| Res::Err => bug!("unexpected resolution: {:?}", res),
361362
}
362363
}

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17401740
Res::Def(DefKind::Macro(kinds), _) => {
17411741
format!("{} {}", kinds.article(), kinds.descr())
17421742
}
1743-
Res::ToolMod => {
1744-
// Don't confuse the user with tool modules.
1743+
Res::ToolMod | Res::OpenMod(..) => {
1744+
// Don't confuse the user with tool modules or open modules.
17451745
continue;
17461746
}
17471747
Res::Def(DefKind::Trait, _) if macro_kind == MacroKind::Derive => {
@@ -1978,7 +1978,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19781978
let (built_in, from) = match scope {
19791979
Scope::StdLibPrelude | Scope::MacroUsePrelude => ("", " from prelude"),
19801980
Scope::ExternPreludeFlags
1981-
if self.tcx.sess.opts.externs.get(ident.as_str()).is_some() =>
1981+
if self.tcx.sess.opts.externs.get(ident.as_str()).is_some()
1982+
|| matches!(res, Res::OpenMod(..)) =>
19821983
{
19831984
("", " passed with `--extern`")
19841985
}

compiler/rustc_resolve/src/ident.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
AmbiguityError, AmbiguityKind, AmbiguityWarning, BindingKey, CmResolver, Decl, DeclKind,
2727
Determinacy, Finalize, IdentKey, ImportKind, LateDecl, Module, ModuleKind, ModuleOrUniformRoot,
2828
ParentScope, PathResult, PrivacyError, Res, ResolutionError, Resolver, Scope, ScopeSet,
29-
Segment, Stage, Used, errors,
29+
Segment, Stage, Symbol, Used, errors,
3030
};
3131

3232
#[derive(Copy, Clone)]
@@ -386,7 +386,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
386386
}
387387

388388
/// Resolve an identifier in the specified set of scopes.
389-
#[instrument(level = "debug", skip(self))]
390389
pub(crate) fn resolve_ident_in_scope_set<'r>(
391390
self: CmResolver<'r, 'ra, 'tcx>,
392391
orig_ident: Ident,
@@ -976,6 +975,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
976975
ignore_import,
977976
)
978977
}
978+
ModuleOrUniformRoot::OpenModule(sym) => {
979+
let open_ns_name = format!("{}::{}", sym.as_str(), ident.name);
980+
let ns_ident = IdentKey::with_root_ctxt(Symbol::intern(&open_ns_name));
981+
match self.extern_prelude_get_flag(ns_ident, ident.span, finalize.is_some()) {
982+
Some(decl) => Ok(decl),
983+
None => Err(Determinacy::Determined),
984+
}
985+
}
979986
ModuleOrUniformRoot::ModuleAndExternPrelude(module) => self.resolve_ident_in_scope_set(
980987
ident,
981988
ScopeSet::ModuleAndExternPrelude(ns, module),
@@ -1962,7 +1969,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19621969
}
19631970

19641971
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(res);
1965-
if let Some(def_id) = binding.res().module_like_def_id() {
1972+
if let Res::OpenMod(sym) = binding.res() {
1973+
module = Some(ModuleOrUniformRoot::OpenModule(sym));
1974+
record_segment_res(self.reborrow(), finalize, res, id);
1975+
} else if let Some(def_id) = binding.res().module_like_def_id() {
19661976
if self.mods_with_parse_errors.contains(&def_id) {
19671977
module_had_parse_errors = true;
19681978
}

0 commit comments

Comments
 (0)