Skip to content
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

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

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4cb52ff
Move `ty::Visibility` to its own little module (cute)
WaffleLapkin May 3, 2023
febb95e
Move `ty::ImplPolarity` to its own little module (cute)
WaffleLapkin May 3, 2023
7b9ec6c
Move `ty::BoundConstness` to its own little module (cute)
WaffleLapkin May 3, 2023
2066470
Move `ty::{Predicate, PredicateKind}` to their own little module (cute)
WaffleLapkin May 3, 2023
83383d4
Move `ty::InstantiatedPredicates` to its own little module (cute)
WaffleLapkin May 3, 2023
8830e66
Move `ty::{TraitPredicate, PolyTraitPredicate}` to their own little m…
WaffleLapkin May 3, 2023
e5893f4
Move `ty::{OutlivesPredicate, PolyRegionOutlivesPredicate, PolyTypeOu…
WaffleLapkin May 3, 2023
fcfdd0e
Move `ty::{PolyTraitPredicate, TraitPredicate}` to their own little m…
WaffleLapkin May 3, 2023
dde5ea5
Move `ty::{CoercePredicate, PolyCoercePredicate}` to their own little…
WaffleLapkin May 3, 2023
fb2743d
Move `ty::{PolyProjectionPredicate, ProjectionPredicate}` to their ow…
WaffleLapkin May 3, 2023
f0210a1
Move `ty::ToPredicate` to its own little module (cute)
WaffleLapkin May 3, 2023
675b01f
Move `ty::{ParamEnv, ParamEnvAnd}` to their own little module (cute)
WaffleLapkin May 3, 2023
33df1c9
Move `ty::{Term, TermKind}` to their own little module (cute)
WaffleLapkin May 3, 2023
709d355
Move `ty::Ty` to its own little module (cute)
WaffleLapkin May 3, 2023
2306e97
Move `ty::AliasRelationDirection` to its own little module (cute)
WaffleLapkin May 3, 2023
55811e0
Move `ty::OpaqueHiddenType` to its own little module (cute)
WaffleLapkin May 3, 2023
3e53b05
Move `ty::VariantDef` to its own little module (cute)
WaffleLapkin May 3, 2023
9f88bf1
Move `ty::FieldDef` to its own little module (cute)
WaffleLapkin May 3, 2023
55f1d16
Move `ty::{Placeholder, PlaceholderConst, PlaceholderRegion, Placehol…
WaffleLapkin May 3, 2023
9ca749d
Move `ty::SymbolName` to its own little module (cute)
WaffleLapkin May 3, 2023
4a10c11
Move/merge impls out of `ty/mod.rs`
WaffleLapkin May 3, 2023
9303663
Move `ty::{ResolverAstLowering, ResolverGlobalCtxt, ResolverOutputs}`…
WaffleLapkin May 3, 2023
5107cb0
Move `ty::MainDefinition` to its own little module (cute)
WaffleLapkin May 3, 2023
8409f98
Move `ty::Clause` to its own little module (cute)
WaffleLapkin May 3, 2023
9ef3c2f
Move `ty::CratePredicatesMap` to its own little module (cute)
WaffleLapkin May 3, 2023
f9de9fa
Move `ty::ImplTraitInTraitData` to its own little module (cute)
WaffleLapkin May 4, 2023
9d1cfec
Move `ty::{BoundConst, CReaderCacheKey, ClosureSizeProfileData, Crate…
WaffleLapkin May 4, 2023
4ba55d5
Rearange [pub] uses
WaffleLapkin May 4, 2023
9175367
group `ty::coherence` in one file
WaffleLapkin May 5, 2023
14ec3a1
group `ty::opaque` in one file
WaffleLapkin May 5, 2023
d4b6a6a
Move `BoundConst` to `ty::consts`
WaffleLapkin May 5, 2023
181df7a
Group adt adjesent types into `ty::adt`
WaffleLapkin May 5, 2023
33576fa
Move `rustc_middle::{ty=>}::resolver_outputs`
WaffleLapkin May 5, 2023
ca46414
Group `ty::Predicate` internals in one file
WaffleLapkin May 5, 2023
06add87
Move `ParamTerm` to `term.rs`
WaffleLapkin May 5, 2023
65acff8
Destribute placeholders
WaffleLapkin May 5, 2023
8706a19
Move `InferVarInfo` to `ty_.rs`
WaffleLapkin May 5, 2023
a935652
Move `AliasRelationDirection` to `predicate.rs`
WaffleLapkin May 5, 2023
5bb181a
Move `CReaderCacheKey` to `rustc_middle::cache`
WaffleLapkin May 12, 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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make 3 imports of this?

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
3 changes: 2 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
use rustc_hir::diagnostic_items::DiagnosticItems;
use rustc_index::{Idx, IndexVec};
use rustc_middle::cache::CReaderCacheKey;
use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
Expand Down Expand Up @@ -379,7 +380,7 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
{
let tcx = self.tcx();

let key = ty::CReaderCacheKey { cnum: Some(self.cdata().cnum), pos: shorthand };
let key = CReaderCacheKey { cnum: Some(self.cdata().cnum), pos: shorthand };

if let Some(&ty) = tcx.ty_rcache.borrow().get(&key) {
return ty;
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
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use rustc_hir::def_id::CrateNum;

/// Contains information needed to resolve types and (in the future) look up
/// the types of AST nodes.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct CReaderCacheKey {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is should be in ty::context, close to its actual use.

pub cnum: Option<CrateNum>,
pub pos: usize,
}
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ pub mod query;
pub mod arena;
#[macro_use]
pub mod dep_graph;
pub mod cache;
pub(crate) mod error;
pub mod hir;
pub mod infer;
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
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use std::collections::hash_map::Entry;
use std::io;
use std::mem;

use crate::cache::CReaderCacheKey;

const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;

// A normal span encoded with both location information and a `SyntaxContext`
Expand Down Expand Up @@ -551,7 +553,7 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
{
let tcx = self.tcx;

let cache_key = ty::CReaderCacheKey { cnum: None, pos: shorthand };
let cache_key = CReaderCacheKey { cnum: None, pos: shorthand };

if let Some(&ty) = tcx.ty_rcache.borrow().get(&cache_key) {
return ty;
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