Skip to content

Move structures from ty/mod.rs into their own modules #111208

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
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e467f43
Move `ty::Visibility` to its own little module (cute)
WaffleLapkin May 3, 2023
5854e46
Move `ty::ImplPolarity` to its own little module (cute)
WaffleLapkin May 3, 2023
9990165
Move `ty::BoundConstness` to its own little module (cute)
WaffleLapkin May 3, 2023
05c8728
Move `ty::{Predicate, PredicateKind}` to their own little module (cute)
WaffleLapkin May 3, 2023
fb29d65
Move `ty::InstantiatedPredicates` to its own little module (cute)
WaffleLapkin May 3, 2023
c19b3f1
Move `ty::{TraitPredicate, PolyTraitPredicate}` to their own little m…
WaffleLapkin May 3, 2023
7ca97d1
Move `ty::{OutlivesPredicate, PolyRegionOutlivesPredicate, PolyTypeOu…
WaffleLapkin May 3, 2023
81f69a3
Move `ty::{PolyTraitPredicate, TraitPredicate}` to their own little m…
WaffleLapkin May 3, 2023
94d522e
Move `ty::{CoercePredicate, PolyCoercePredicate}` to their own little…
WaffleLapkin May 3, 2023
8a600a3
Move `ty::{PolyProjectionPredicate, ProjectionPredicate}` to their ow…
WaffleLapkin May 3, 2023
64c7cc2
Move `ty::ToPredicate` to its own little module (cute)
WaffleLapkin May 3, 2023
528e9b5
Move `ty::{ParamEnv, ParamEnvAnd}` to their own little module (cute)
WaffleLapkin May 3, 2023
24c89cd
Move `ty::{Term, TermKind}` to their own little module (cute)
WaffleLapkin May 3, 2023
79f92ae
Move `ty::Ty` to its own little module (cute)
WaffleLapkin May 3, 2023
a409b98
Move `ty::AliasRelationDirection` to its own little module (cute)
WaffleLapkin May 3, 2023
29a7901
Move `ty::OpaqueHiddenType` to its own little module (cute)
WaffleLapkin May 3, 2023
71e0bb4
Move `ty::VariantDef` to its own little module (cute)
WaffleLapkin May 3, 2023
8be9b84
Move `ty::FieldDef` to its own little module (cute)
WaffleLapkin May 3, 2023
cacaab6
Move `ty::{Placeholder, PlaceholderConst, PlaceholderRegion, Placehol…
WaffleLapkin May 3, 2023
3c0e0ce
Move `ty::SymbolName` to its own little module (cute)
WaffleLapkin May 3, 2023
0810f88
Move/merge impls out of `ty/mod.rs`
WaffleLapkin May 3, 2023
32fe946
Move `ty::{ResolverAstLowering, ResolverGlobalCtxt, ResolverOutputs}`…
WaffleLapkin May 3, 2023
9db043f
Move `ty::MainDefinition` to its own little module (cute)
WaffleLapkin May 3, 2023
5e441b8
Move `ty::Clause` to its own little module (cute)
WaffleLapkin May 3, 2023
7a41522
Move `ty::CratePredicatesMap` to its own little module (cute)
WaffleLapkin May 3, 2023
a1e3cb4
Move `ty::ImplTraitInTraitData` to its own little module (cute)
WaffleLapkin May 4, 2023
9acb574
Move `ty::{BoundConst, CReaderCacheKey, ClosureSizeProfileData, Crate…
WaffleLapkin May 4, 2023
3c941b2
Rearange [pub] uses
WaffleLapkin May 4, 2023
2c556f5
group `ty::coherence` in one file
WaffleLapkin May 5, 2023
a04bd9b
group `ty::opaque` in one file
WaffleLapkin May 5, 2023
335f7ca
Move `BoundConst` to `ty::consts`
WaffleLapkin May 5, 2023
b6237e6
Group adt adjesent types into `ty::adt`
WaffleLapkin May 5, 2023
413370b
Move `rustc_middle::{ty=>}::resolver_outputs`
WaffleLapkin May 5, 2023
e3de992
Group `ty::Predicate` internals in one file
WaffleLapkin May 5, 2023
07e0e75
Move `ParamTerm` to `term.rs`
WaffleLapkin May 5, 2023
fa016bc
Destribute placeholders
WaffleLapkin May 5, 2023
5793896
Move `InferVarInfo` to `ty_.rs`
WaffleLapkin May 5, 2023
7fad53e
Move `AliasRelationDirection` to `predicate.rs`
WaffleLapkin May 5, 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
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::PredicateOrigin;
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_middle::resolver_outputs::ResolverAstLowering;
use rustc_middle::ty::TyCtxt;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, sym, Ident};
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::definitions::DefPathData;
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::{
span_bug,
ty::{ResolverAstLowering, TyCtxt},
};
use rustc_middle::{resolver_outputs::ResolverAstLowering, span_bug, ty::TyCtxt};
use rustc_session::parse::{add_feature_diagnostics, feature_err};
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::DesugaringKind;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lifetime_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::ResolverAstLoweringExt;
use rustc_ast::visit::{self, BoundKind, LifetimeCtxt, Visitor};
use rustc_ast::{FnRetTy, GenericBounds, Lifetime, NodeId, PathSegment, PolyTraitRef, Ty, TyKind};
use rustc_hir::def::LifetimeRes;
use rustc_middle::resolver_outputs::ResolverAstLowering;
use rustc_middle::span_bug;
use rustc_middle::ty::ResolverAstLowering;
use rustc_span::symbol::{kw, Ident};
use rustc_span::Span;

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintSto
use rustc_metadata::creader::CStore;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::resolver_outputs::{ResolverAstLowering, ResolverOutputs};
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt};
use rustc_mir_build as mir_build;
Expand Down Expand Up @@ -557,7 +558,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
fn resolver_for_lowering<'tcx>(
tcx: TyCtxt<'tcx>,
(): (),
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
) -> &'tcx Steal<(ResolverAstLowering, Lrc<ast::Crate>)> {
let arenas = Resolver::arenas();
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();
Expand All @@ -567,7 +568,7 @@ fn resolver_for_lowering<'tcx>(
// Make sure we don't mutate the cstore from here on.
tcx.untracked().cstore.leak();

let ty::ResolverOutputs {
let ResolverOutputs {
global_ctxt: untracked_resolutions,
ast_lowering: untracked_resolver_for_lowering,
} = resolver.into_outputs();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ macro_rules! arena_types {
[decode] borrowck_result:
rustc_middle::mir::BorrowCheckResult<'tcx>,
[] resolver: rustc_data_structures::steal::Steal<(
rustc_middle::ty::ResolverAstLowering,
rustc_middle::resolver_outputs::ResolverAstLowering,
rustc_data_structures::sync::Lrc<rustc_ast::Crate>,
)>,
[] output_filenames: std::sync::Arc<rustc_session::config::OutputFilenames>,
[] metadata_loader: rustc_data_structures::steal::Steal<Box<rustc_session::cstore::MetadataLoaderDyn>>,
[] crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>,
[] resolutions: rustc_middle::ty::ResolverGlobalCtxt,
[] resolutions: rustc_middle::resolver_outputs::ResolverGlobalCtxt,
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
[] const_allocs: rustc_middle::mir::interpret::Allocation,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub mod lint;
pub mod metadata;
pub mod middle;
pub mod mir;
pub mod resolver_outputs;
pub mod thir;
pub mod traits;
pub mod ty;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ rustc_queries! {
desc { "perform lints prior to macro expansion" }
}

query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
query resolutions(_: ()) -> &'tcx crate::resolver_outputs::ResolverGlobalCtxt {
feedable
no_hash
desc { "getting the resolver outputs" }
}

query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
query resolver_for_lowering(_: ()) -> &'tcx Steal<(crate::resolver_outputs::ResolverAstLowering, Lrc<ast::Crate>)> {
eval_always
no_hash
desc { "getting the resolver for lowering" }
Expand Down
92 changes: 92 additions & 0 deletions compiler/rustc_middle/src/resolver_outputs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use rustc_ast as ast;
use rustc_ast::node_id::NodeMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::steal::Steal;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, DocLinkResMap, LifetimeRes, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
use rustc_index::IndexVec;
use rustc_session::lint::LintBuffer;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{ExpnId, Span};

use crate::metadata::ModChild;
use crate::middle::privacy::EffectiveVisibilities;
use crate::ty::Visibility;

pub struct ResolverOutputs {
pub global_ctxt: ResolverGlobalCtxt,
pub ast_lowering: ResolverAstLowering,
}

#[derive(Debug)]
pub struct ResolverGlobalCtxt {
pub visibilities: FxHashMap<LocalDefId, Visibility>,
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
pub has_pub_restricted: bool,
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
pub effective_visibilities: EffectiveVisibilities,
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
pub module_children: LocalDefIdMap<Vec<ModChild>>,
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
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>,
/// Mapping from ident span to path span for paths that don't exist as written, but that
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
pub confused_type_with_std_module: FxHashMap<Span, Span>,
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
}

/// Resolutions that should only be used for lowering.
/// This struct is meant to be consumed by lowering.
#[derive(Debug)]
pub struct ResolverAstLowering {
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,

/// Resolutions for nodes that have a single resolution.
pub partial_res_map: NodeMap<hir::def::PartialRes>,
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
pub label_res_map: NodeMap<ast::NodeId>,
/// Resolutions for lifetimes.
pub lifetimes_res_map: NodeMap<LifetimeRes>,
/// Lifetime parameters that lowering will have to introduce.
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,

pub next_node_id: ast::NodeId,

pub node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
pub def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,

pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
/// the surface (`macro` items in libcore), but are actually attributes or derives.
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
/// List functions and methods for which lifetime elision was successful.
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,

/// Lints that were emitted by the resolver and early lints.
pub lint_buffer: Steal<LintBuffer>,
}

#[derive(Clone, Copy, Debug)]
pub struct MainDefinition {
pub res: Res<ast::NodeId>,
pub is_import: bool,
pub span: Span,
}

impl MainDefinition {
pub fn opt_fn_def_id(self) -> Option<DefId> {
if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None }
}
}
Loading