Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8925fcc
hashmap compiles
Robert-Cunningham Aug 13, 2022
d84ecf2
write all_local_trait_impls in terms of new query
Robert-Cunningham Aug 13, 2022
8acd145
remove fom resolver
Robert-Cunningham Aug 13, 2022
2d54ab7
convert hashmap to indexmap
Robert-Cunningham Aug 14, 2022
ab7c2ba
add eval_always
Robert-Cunningham Aug 15, 2022
d3426dd
stop prinnting dep graph
Robert-Cunningham Aug 15, 2022
251fcbc
clean up
Robert-Cunningham Aug 15, 2022
83ca511
revert derive formatting changes
Robert-Cunningham Aug 15, 2022
31222de
remove comments
Robert-Cunningham Aug 15, 2022
5a7d801
remove last robert-trait annotation
Robert-Cunningham Aug 15, 2022
058b8dc
implement cjg first suggestion
Robert-Cunningham Sep 12, 2022
c2a2636
Merge branch 'rust-lang:master' into impls_in_crate
Robert-Cunningham Sep 12, 2022
687280d
Merge branch 'impls_in_crate' of github.com:Robert-Cunningham/rust in…
Robert-Cunningham Sep 12, 2022
6b0ab18
temporary changed found january
Robert-Cunningham Jan 13, 2023
44364ae
resolve merge comfinclits
Robert-Cunningham Jan 13, 2023
11b2ade
make compile after merge
Robert-Cunningham Jan 13, 2023
3b486b2
fix git rename misses
Robert-Cunningham Jan 13, 2023
621ba62
debug checks
Robert-Cunningham Jan 14, 2023
bd35683
change type to option
Robert-Cunningham Jan 15, 2023
58d1577
remove local_impls_in_crate, find cycle
Robert-Cunningham Jan 15, 2023
90e12e8
passing tests
Robert-Cunningham Jan 15, 2023
0655439
revert everything
Robert-Cunningham Jan 16, 2023
ecc2c08
clean and clarify
Robert-Cunningham Jan 16, 2023
66179b9
passes tests
Robert-Cunningham Jan 16, 2023
6e61761
merge upstream changes
Robert-Cunningham Jan 17, 2023
a1bee1c
finish merge
Robert-Cunningham Jan 17, 2023
d313486
remove comment churn
Robert-Cunningham Jan 17, 2023
5c07123
remove last comment
Robert-Cunningham Jan 17, 2023
37aba45
add comment to address review
Robert-Cunningham Jan 21, 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
Prev Previous commit
Next Next commit
clean up
  • Loading branch information
Robert-Cunningham committed Aug 15, 2022
commit 251fcbcecb1581ad36d562095329540ac9422bfa
3 changes: 1 addition & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.root.traits.decode(self).map(move |index| self.local_def_id(index))
}

// robert-trait: this implements trait_impls_in_crate_untracked
/// Decodes all trait impls in the crate (for rustdoc).
fn get_trait_impls(self) -> impl Iterator<Item = (DefId, DefId, Option<SimplifiedType>)> + 'a {
self.cdata.trait_impls.iter().flat_map(move |(&(trait_cnum_raw, trait_index), impls)| {
Expand All @@ -1262,6 +1261,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
})
}

/// Decodes a map from trait to impls.
fn get_trait_impl_map(self) -> FxIndexMap<DefId, Vec<(DefId, Option<SimplifiedType>)>> {
self.cdata
.trait_impls
Expand Down Expand Up @@ -1296,7 +1296,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

// robert-trait: ultimately uses decoder.trait_impls. this is for external crates, and is used in trait_impls_of, which iterates over external crates and calls this.
fn get_implementations_of_trait(
self,
tcx: TyCtxt<'tcx>,
Expand Down
52 changes: 1 addition & 51 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,39 +1813,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_array(self.tcx.traits_in_crate(LOCAL_CRATE).iter().map(|def_id| def_id.index))
}

// robert-trait: serialize traits to meta vir HIR iteration
/// Encodes an index, mapping each trait to its (local) implementations.
fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
debug!("EncodeContext::encode_traits_and_impls()");
empty_proc_macro!(self);
let tcx = self.tcx;
/*
let mut fx_hash_map: FxHashMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
FxHashMap::default();

for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) {
let simplified_self_ty = fast_reject::simplify_type(
self.tcx,
trait_ref.self_ty(),
TreatParams::AsInfer,
);

fx_hash_map
.entry(trait_ref.def_id)
.or_default()
.push((id.def_id.local_def_index, simplified_self_ty));
}
}
}
*/

let fx_hash_map = self.tcx.impls_in_crate(LOCAL_CRATE).to_owned();

// let mut all_impls: Vec<(DefId, Vec<(DefId, Option<SimplifiedTypeGen<DefId>>)>)>
let mut all_impls: Vec<_> = fx_hash_map.into_iter().collect();
//.map(|(trait_def_id, impls)| (trait_def_id, impls.iter().map(|(impl_def_, d)| (c.expect_local().local_def_index, d))));

// Bring everything into deterministic order for hashing
all_impls.sort_by_cached_key(|&(trait_def_id, _)| tcx.def_path_hash(trait_def_id));
Expand Down Expand Up @@ -2297,11 +2272,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
pub fn provide(providers: &mut Providers) {
*providers = Providers {
all_local_trait_impls: |tcx, _| {
// with just top live, error.
// with just bottom live, success.
// with both live, fails.
// so although the top has no impact on the output, it causes the failure.

let o: FxIndexMap<_, _> = tcx
.impls_in_crate(LOCAL_CRATE)
.iter()
Expand All @@ -2314,49 +2284,29 @@ pub fn provide(providers: &mut Providers) {
.collect();

tcx.arena.alloc(o)

//providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
//&tcx.resolutions(()).trait_impls
},
traits_in_crate: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);

let mut traits = Vec::new();
for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Trait | DefKind::TraitAlias) {
//println!("matches b");
traits.push(id.def_id.to_def_id())
}
}

// Bring everything into deterministic order.
//traits.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id));
// This is not necessary, since the default order is source-code order.
// We don't need to sort, since the default order is source-code order.
// The source code is hashed into crate_hash, so if crate_hash is stable then it must be stable too.

tcx.arena.alloc_slice(&traits)
},
impls_in_crate: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);

/*
let mut impls = Vec::new();

for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
impls.push(id.def_id.to_def_id());
}
}

tcx.arena.alloc_slice(&impls) // no need to sort, source-code order is fine.
*/
let mut fx_hash_map: FxIndexMap<DefId, Vec<(DefId, Option<SimplifiedType>)>> =
FxIndexMap::default();

for id in tcx.hir().items() {
//println!("{:?}", id);
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
//println!("matches a");
if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) {
let simplified_self_ty = fast_reject::simplify_type(
tcx,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,8 @@ impl<'hir> Map<'hir> {
}
}

// robert-trait: ultimately provided by resolver outputs.
pub fn trait_impls(self, trait_did: DefId) -> &'hir [LocalDefId] {
self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
//self.tcx.impls_in_crate(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
}

/// Gets the attributes on the crate. This is preferable to
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ pub fn provide(providers: &mut Providers) {
}
};
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
// robert-resolver
//providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
providers.expn_that_defined = |tcx, id| {
let id = id.expect_local();
tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root())
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ pub struct ResolverOutputs {
/// via `extern crate` item and not `--extern` option or compiler built-in.
pub extern_prelude: FxHashMap<Symbol, bool>,
pub main_def: Option<MainDefinition>,
//pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
/// A list of proc macro LocalDefIds, written out in the order in which
/// they are declared in the static array generated by proc_macro_harness.
pub proc_macros: Vec<LocalDefId>,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

// robert-trait: ultimately provided by decoder.trait_impls
// Query provider for `trait_impls_of`.
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls {
let mut impls = TraitImpls::default();
Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,16 +2620,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|this, trait_id| {
let item_def_id = this.r.local_def_id(item_id);

// Register the trait definitions from here.
// robert-resolver
//if let Some(trait_id) = trait_id {
// this.r
// .trait_impls
// .entry(trait_id)
// .or_default()
// .push(item_def_id);
//}

let item_def_id = item_def_id.to_def_id();
let res = Res::SelfTy {
trait_: trait_id,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,6 @@ pub struct Resolver<'a> {
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,

main_def: Option<MainDefinition>,
//trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
/// A list of proc macro LocalDefIds, written out in the order in which
/// they are declared in the static array generated by proc_macro_harness.
proc_macros: Vec<NodeId>,
Expand Down Expand Up @@ -1358,7 +1357,6 @@ impl<'a> Resolver<'a> {
legacy_const_generic_args: Default::default(),
item_generics_num_lifetimes: Default::default(),
main_def: Default::default(),
//trait_impls: Default::default(),
proc_macros: Default::default(),
confused_type_with_std_module: Default::default(),
access_levels: Default::default(),
Expand Down Expand Up @@ -1439,7 +1437,6 @@ impl<'a> Resolver<'a> {
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
.collect(),
main_def,
//trait_impls: self.trait_impls,
proc_macros,
confused_type_with_std_module,
registered_tools: self.registered_tools,
Expand Down Expand Up @@ -1483,7 +1480,6 @@ impl<'a> Resolver<'a> {
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
.collect(),
main_def: self.main_def,
//trait_impls: self.trait_impls.clone(),
proc_macros,
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
registered_tools: self.registered_tools.clone(),
Expand Down