Skip to content

Commit d54111a

Browse files
committed
Auto merge of #65771 - Centril:rollup-upfsvrb, r=Centril
Rollup of 8 pull requests Successful merges: - #65625 (Turn crate store into a resolver output) - #65627 (Forbid non-`structural_match` types in const generics) - #65710 (Update cargo) - #65729 (Update test cases for vxWorks) - #65746 (Tweak format string error to point at arguments always) - #65753 (Don't assert for different instance on impl trait alias) - #65755 (Avoid ICE when adjusting bad self ty) - #65766 (Update hashbrown to 0.6.2) Failed merges: r? @ghost
2 parents 10a52c2 + fd6795b commit d54111a

Some content is hidden

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

51 files changed

+719
-642
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1297,9 +1297,9 @@ dependencies = [
12971297

12981298
[[package]]
12991299
name = "hashbrown"
1300-
version = "0.6.1"
1300+
version = "0.6.2"
13011301
source = "registry+https://github.com/rust-lang/crates.io-index"
1302-
checksum = "6587d09be37fb98a11cb08b9000a3f592451c1b1b613ca69d949160e313a430a"
1302+
checksum = "3cd9867f119b19fecb08cd5c326ad4488d7a1da4bf75b4d95d71db742525aaab"
13031303
dependencies = [
13041304
"autocfg",
13051305
"compiler_builtins",
@@ -4146,7 +4146,7 @@ dependencies = [
41464146
"core",
41474147
"dlmalloc",
41484148
"fortanix-sgx-abi",
4149-
"hashbrown 0.6.1",
4149+
"hashbrown 0.6.2",
41504150
"libc",
41514151
"panic_abort",
41524152
"panic_unwind",

src/librustc/hir/lowering.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ pub struct LoweringContext<'a> {
8383
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
8484
sess: &'a Session,
8585

86-
cstore: &'a dyn CrateStore,
87-
8886
resolver: &'a mut dyn Resolver,
8987

9088
/// HACK(Centril): there is a cyclic dependency between the parser and lowering
@@ -160,6 +158,8 @@ pub struct LoweringContext<'a> {
160158
}
161159

162160
pub trait Resolver {
161+
fn cstore(&self) -> &dyn CrateStore;
162+
163163
/// Obtains resolution for a `NodeId` with a single resolution.
164164
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;
165165

@@ -240,7 +240,6 @@ impl<'a> ImplTraitContext<'a> {
240240

241241
pub fn lower_crate(
242242
sess: &Session,
243-
cstore: &dyn CrateStore,
244243
dep_graph: &DepGraph,
245244
krate: &Crate,
246245
resolver: &mut dyn Resolver,
@@ -256,7 +255,6 @@ pub fn lower_crate(
256255
LoweringContext {
257256
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),
258257
sess,
259-
cstore,
260258
resolver,
261259
nt_to_tokenstream,
262260
items: BTreeMap::new(),
@@ -980,7 +978,7 @@ impl<'a> LoweringContext<'a> {
980978
if id.is_local() {
981979
self.resolver.definitions().def_key(id.index)
982980
} else {
983-
self.cstore.def_key(id)
981+
self.resolver.cstore().def_key(id)
984982
}
985983
}
986984

@@ -1727,8 +1725,8 @@ impl<'a> LoweringContext<'a> {
17271725
return n;
17281726
}
17291727
assert!(!def_id.is_local());
1730-
let item_generics =
1731-
self.cstore.item_generics_cloned_untracked(def_id, self.sess);
1728+
let item_generics = self.resolver.cstore()
1729+
.item_generics_cloned_untracked(def_id, self.sess);
17321730
let n = item_generics.own_counts().lifetimes;
17331731
self.type_def_lifetime_params.insert(def_id, n);
17341732
n

src/librustc/middle/cstore.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use syntax::ast;
1616
use syntax::symbol::Symbol;
1717
use syntax_pos::Span;
1818
use rustc_target::spec::Target;
19-
use rustc_data_structures::sync::{self, MetadataRef, Lrc};
19+
use rustc_data_structures::sync::{self, MetadataRef};
2020
use rustc_macros::HashStable;
2121

2222
pub use self::NativeLibraryKind::*;
@@ -191,6 +191,8 @@ pub trait MetadataLoader {
191191
-> Result<MetadataRef, String>;
192192
}
193193

194+
pub type MetadataLoaderDyn = dyn MetadataLoader + Sync;
195+
194196
/// A store of Rust crates, through which their metadata can be accessed.
195197
///
196198
/// Note that this trait should probably not be expanding today. All new
@@ -201,13 +203,13 @@ pub trait MetadataLoader {
201203
/// (it'd break incremental compilation) and should only be called pre-HIR (e.g.
202204
/// during resolve)
203205
pub trait CrateStore {
204-
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<dyn Any>;
206+
fn crate_data_as_any(&self, cnum: CrateNum) -> &dyn Any;
205207

206208
// resolve
207209
fn def_key(&self, def: DefId) -> DefKey;
208210
fn def_path(&self, def: DefId) -> hir_map::DefPath;
209211
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
210-
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable>;
212+
fn def_path_table(&self, cnum: CrateNum) -> &DefPathTable;
211213

212214
// "queries" used in resolve that aren't tracked for incremental compilation
213215
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol;

src/librustc/ty/context.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ pub struct GlobalCtxt<'tcx> {
10271027

10281028
interners: CtxtInterners<'tcx>,
10291029

1030-
cstore: &'tcx CrateStoreDyn,
1030+
cstore: Box<CrateStoreDyn>,
10311031

10321032
pub sess: &'tcx Session,
10331033

@@ -1195,11 +1195,10 @@ impl<'tcx> TyCtxt<'tcx> {
11951195
pub fn create_global_ctxt(
11961196
s: &'tcx Session,
11971197
lint_store: Lrc<lint::LintStore>,
1198-
cstore: &'tcx CrateStoreDyn,
11991198
local_providers: ty::query::Providers<'tcx>,
12001199
extern_providers: ty::query::Providers<'tcx>,
12011200
arenas: &'tcx AllArenas,
1202-
resolutions: ty::Resolutions,
1201+
resolutions: ty::ResolverOutputs,
12031202
hir: hir_map::Map<'tcx>,
12041203
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
12051204
crate_name: &str,
@@ -1213,34 +1212,28 @@ impl<'tcx> TyCtxt<'tcx> {
12131212
let common_lifetimes = CommonLifetimes::new(&interners);
12141213
let common_consts = CommonConsts::new(&interners, &common_types);
12151214
let dep_graph = hir.dep_graph.clone();
1216-
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
1215+
let cstore = resolutions.cstore;
1216+
let crates = cstore.crates_untracked();
1217+
let max_cnum = crates.iter().map(|c| c.as_usize()).max().unwrap_or(0);
12171218
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
12181219
providers[LOCAL_CRATE] = local_providers;
12191220

12201221
let def_path_hash_to_def_id = if s.opts.build_dep_graph() {
1221-
let upstream_def_path_tables: Vec<(CrateNum, Lrc<_>)> = cstore
1222-
.crates_untracked()
1222+
let def_path_tables = crates
12231223
.iter()
12241224
.map(|&cnum| (cnum, cstore.def_path_table(cnum)))
1225-
.collect();
1226-
1227-
let def_path_tables = || {
1228-
upstream_def_path_tables
1229-
.iter()
1230-
.map(|&(cnum, ref rc)| (cnum, &**rc))
1231-
.chain(iter::once((LOCAL_CRATE, hir.definitions().def_path_table())))
1232-
};
1225+
.chain(iter::once((LOCAL_CRATE, hir.definitions().def_path_table())));
12331226

12341227
// Precompute the capacity of the hashmap so we don't have to
12351228
// re-allocate when populating it.
1236-
let capacity = def_path_tables().map(|(_, t)| t.size()).sum::<usize>();
1229+
let capacity = def_path_tables.clone().map(|(_, t)| t.size()).sum::<usize>();
12371230

12381231
let mut map: FxHashMap<_, _> = FxHashMap::with_capacity_and_hasher(
12391232
capacity,
12401233
::std::default::Default::default()
12411234
);
12421235

1243-
for (cnum, def_path_table) in def_path_tables() {
1236+
for (cnum, def_path_table) in def_path_tables {
12441237
def_path_table.add_def_path_hashes_to(cnum, &mut map);
12451238
}
12461239

@@ -1417,8 +1410,8 @@ impl<'tcx> TyCtxt<'tcx> {
14171410

14181411
// Note that this is *untracked* and should only be used within the query
14191412
// system if the result is otherwise tracked through queries
1420-
pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Lrc<dyn Any> {
1421-
self.cstore.crate_data_as_rc_any(cnum)
1413+
pub fn crate_data_as_any(self, cnum: CrateNum) -> &'tcx dyn Any {
1414+
self.cstore.crate_data_as_any(cnum)
14221415
}
14231416

14241417
#[inline(always)]
@@ -1428,7 +1421,7 @@ impl<'tcx> TyCtxt<'tcx> {
14281421
StableHashingContext::new(self.sess,
14291422
krate,
14301423
self.hir().definitions(),
1431-
self.cstore)
1424+
&*self.cstore)
14321425
}
14331426

14341427
// This method makes sure that we have a DepNode and a Fingerprint for

src/librustc/ty/mod.rs

+129-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use self::Variance::*;
44
pub use self::AssocItemContainer::*;
55
pub use self::BorrowKind::*;
66
pub use self::IntVarValue::*;
7-
pub use self::fold::TypeFoldable;
7+
pub use self::fold::{TypeFoldable, TypeVisitor};
88

99
use crate::hir::{map as hir_map, GlobMap, TraitMap};
1010
use crate::hir::Node;
@@ -15,6 +15,7 @@ use rustc_macros::HashStable;
1515
use crate::ich::Fingerprint;
1616
use crate::ich::StableHashingContext;
1717
use crate::infer::canonical::Canonical;
18+
use crate::middle::cstore::CrateStoreDyn;
1819
use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
1920
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
2021
use crate::mir::Body;
@@ -50,7 +51,7 @@ use syntax::symbol::{kw, sym, Symbol};
5051
use syntax_pos::Span;
5152

5253
use smallvec;
53-
use rustc_data_structures::fx::FxIndexMap;
54+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
5455
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
5556
use rustc_index::vec::{Idx, IndexVec};
5657

@@ -119,8 +120,9 @@ mod sty;
119120

120121
// Data types
121122

122-
#[derive(Clone)]
123-
pub struct Resolutions {
123+
pub struct ResolverOutputs {
124+
pub definitions: hir_map::Definitions,
125+
pub cstore: Box<CrateStoreDyn>,
124126
pub extern_crate_map: NodeMap<CrateNum>,
125127
pub trait_map: TraitMap,
126128
pub maybe_unused_trait_imports: NodeSet,
@@ -3393,6 +3395,129 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
33933395
fn_like.asyncness()
33943396
}
33953397

3398+
pub enum NonStructuralMatchTy<'tcx> {
3399+
Adt(&'tcx AdtDef),
3400+
Param,
3401+
}
3402+
3403+
/// This method traverses the structure of `ty`, trying to find an
3404+
/// instance of an ADT (i.e. struct or enum) that was declared without
3405+
/// the `#[structural_match]` attribute, or a generic type parameter
3406+
/// (which cannot be determined to be `structural_match`).
3407+
///
3408+
/// The "structure of a type" includes all components that would be
3409+
/// considered when doing a pattern match on a constant of that
3410+
/// type.
3411+
///
3412+
/// * This means this method descends into fields of structs/enums,
3413+
/// and also descends into the inner type `T` of `&T` and `&mut T`
3414+
///
3415+
/// * The traversal doesn't dereference unsafe pointers (`*const T`,
3416+
/// `*mut T`), and it does not visit the type arguments of an
3417+
/// instantiated generic like `PhantomData<T>`.
3418+
///
3419+
/// The reason we do this search is Rust currently require all ADTs
3420+
/// reachable from a constant's type to be annotated with
3421+
/// `#[structural_match]`, an attribute which essentially says that
3422+
/// the implementation of `PartialEq::eq` behaves *equivalently* to a
3423+
/// comparison against the unfolded structure.
3424+
///
3425+
/// For more background on why Rust has this requirement, and issues
3426+
/// that arose when the requirement was not enforced completely, see
3427+
/// Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.
3428+
pub fn search_for_structural_match_violation<'tcx>(
3429+
tcx: TyCtxt<'tcx>,
3430+
ty: Ty<'tcx>,
3431+
) -> Option<NonStructuralMatchTy<'tcx>> {
3432+
let mut search = Search { tcx, found: None, seen: FxHashSet::default() };
3433+
ty.visit_with(&mut search);
3434+
return search.found;
3435+
3436+
struct Search<'tcx> {
3437+
tcx: TyCtxt<'tcx>,
3438+
3439+
// Records the first ADT or type parameter we find without `#[structural_match`.
3440+
found: Option<NonStructuralMatchTy<'tcx>>,
3441+
3442+
// Tracks ADTs previously encountered during search, so that
3443+
// we will not recurse on them again.
3444+
seen: FxHashSet<hir::def_id::DefId>,
3445+
}
3446+
3447+
impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
3448+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
3449+
debug!("Search visiting ty: {:?}", ty);
3450+
3451+
let (adt_def, substs) = match ty.kind {
3452+
ty::Adt(adt_def, substs) => (adt_def, substs),
3453+
ty::Param(_) => {
3454+
self.found = Some(NonStructuralMatchTy::Param);
3455+
return true; // Stop visiting.
3456+
}
3457+
ty::RawPtr(..) => {
3458+
// `#[structural_match]` ignores substructure of
3459+
// `*const _`/`*mut _`, so skip super_visit_with
3460+
//
3461+
// (But still tell caller to continue search.)
3462+
return false;
3463+
}
3464+
ty::FnDef(..) | ty::FnPtr(..) => {
3465+
// types of formals and return in `fn(_) -> _` are also irrelevant
3466+
//
3467+
// (But still tell caller to continue search.)
3468+
return false;
3469+
}
3470+
ty::Array(_, n) if n.try_eval_usize(self.tcx, ty::ParamEnv::reveal_all()) == Some(0)
3471+
=> {
3472+
// rust-lang/rust#62336: ignore type of contents
3473+
// for empty array.
3474+
return false;
3475+
}
3476+
_ => {
3477+
ty.super_visit_with(self);
3478+
return false;
3479+
}
3480+
};
3481+
3482+
if !self.tcx.has_attr(adt_def.did, sym::structural_match) {
3483+
self.found = Some(NonStructuralMatchTy::Adt(&adt_def));
3484+
debug!("Search found adt_def: {:?}", adt_def);
3485+
return true; // Stop visiting.
3486+
}
3487+
3488+
if !self.seen.insert(adt_def.did) {
3489+
debug!("Search already seen adt_def: {:?}", adt_def);
3490+
// let caller continue its search
3491+
return false;
3492+
}
3493+
3494+
// `#[structural_match]` does not care about the
3495+
// instantiation of the generics in an ADT (it
3496+
// instead looks directly at its fields outside
3497+
// this match), so we skip super_visit_with.
3498+
//
3499+
// (Must not recur on substs for `PhantomData<T>` cf
3500+
// rust-lang/rust#55028 and rust-lang/rust#55837; but also
3501+
// want to skip substs when only uses of generic are
3502+
// behind unsafe pointers `*const T`/`*mut T`.)
3503+
3504+
// even though we skip super_visit_with, we must recur on
3505+
// fields of ADT.
3506+
let tcx = self.tcx;
3507+
for field_ty in adt_def.all_fields().map(|field| field.ty(tcx, substs)) {
3508+
if field_ty.visit_with(self) {
3509+
// found an ADT without `#[structural_match]`; halt visiting!
3510+
assert!(self.found.is_some());
3511+
return true;
3512+
}
3513+
}
3514+
3515+
// Even though we do not want to recur on substs, we do
3516+
// want our caller to continue its own search.
3517+
false
3518+
}
3519+
}
3520+
}
33963521

33973522
pub fn provide(providers: &mut ty::query::Providers<'_>) {
33983523
context::provide(providers);

src/librustc/ty/relate.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,9 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
557557
x.val
558558
};
559559

560-
// Currently, the values that can be unified are those that
561-
// implement both `PartialEq` and `Eq`, corresponding to
562-
// `structural_match` types.
563-
// FIXME(const_generics): check for `structural_match` synthetic attribute.
560+
// Currently, the values that can be unified are primitive types,
561+
// and those that derive both `PartialEq` and `Eq`, corresponding
562+
// to `structural_match` types.
564563
let new_const_val = match (eagerly_eval(a), eagerly_eval(b)) {
565564
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
566565
// The caller should handle these cases!

src/librustc_codegen_llvm/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::sync::Arc;
5656
use std::ffi::CStr;
5757

5858
use rustc::dep_graph::DepGraph;
59-
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
59+
use rustc::middle::cstore::{EncodedMetadata, MetadataLoaderDyn};
6060
use rustc::session::Session;
6161
use rustc::session::config::{OutputFilenames, OutputType, PrintRequest, OptLevel};
6262
use rustc::ty::{self, TyCtxt};
@@ -260,7 +260,7 @@ impl CodegenBackend for LlvmCodegenBackend {
260260
target_features(sess)
261261
}
262262

263-
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
263+
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
264264
box metadata::LlvmMetadataLoader
265265
}
266266

0 commit comments

Comments
 (0)