-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Make Lazy*<T>
types in rustc_metadata
not care about lifetimes until decode
#97376
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
Merged
+217
−54
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use rustc_hir::def_id::DefId; | ||
use rustc_index::vec::{Idx, IndexVec}; | ||
|
||
use crate::middle::exported_symbols::ExportedSymbol; | ||
use crate::mir::Body; | ||
use crate::thir::abstract_const::Node; | ||
use crate::ty::{ | ||
self, Const, FnSig, GeneratorDiagnosticData, GenericPredicates, Predicate, TraitRef, Ty, | ||
}; | ||
|
||
pub trait ParameterizedOverTcx: 'static { | ||
#[allow(unused_lifetimes)] | ||
type Value<'tcx>; | ||
} | ||
|
||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for &'static [T] { | ||
type Value<'tcx> = &'tcx [T::Value<'tcx>]; | ||
} | ||
|
||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> { | ||
type Value<'tcx> = Option<T::Value<'tcx>>; | ||
} | ||
|
||
impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) { | ||
type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>); | ||
} | ||
|
||
impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> { | ||
type Value<'tcx> = IndexVec<I, T::Value<'tcx>>; | ||
} | ||
|
||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> { | ||
type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! trivially_parameterized_over_tcx { | ||
($($ty:ty),+ $(,)?) => { | ||
$( | ||
impl $crate::ty::ParameterizedOverTcx for $ty { | ||
#[allow(unused_lifetimes)] | ||
type Value<'tcx> = $ty; | ||
} | ||
)* | ||
} | ||
} | ||
|
||
trivially_parameterized_over_tcx! { | ||
usize, | ||
(), | ||
u32, | ||
std::string::String, | ||
crate::metadata::ModChild, | ||
crate::middle::codegen_fn_attrs::CodegenFnAttrs, | ||
crate::middle::exported_symbols::SymbolExportInfo, | ||
crate::mir::ConstQualifs, | ||
ty::Generics, | ||
ty::ImplPolarity, | ||
ty::ReprOptions, | ||
ty::TraitDef, | ||
ty::Visibility, | ||
ty::adjustment::CoerceUnsizedInfo, | ||
ty::fast_reject::SimplifiedTypeGen<DefId>, | ||
rustc_ast::Attribute, | ||
rustc_ast::MacArgs, | ||
rustc_attr::ConstStability, | ||
rustc_attr::Deprecation, | ||
rustc_attr::Stability, | ||
rustc_hir::Constness, | ||
rustc_hir::Defaultness, | ||
rustc_hir::GeneratorKind, | ||
rustc_hir::IsAsync, | ||
rustc_hir::LangItem, | ||
rustc_hir::def::DefKind, | ||
rustc_hir::def_id::DefIndex, | ||
rustc_hir::definitions::DefKey, | ||
rustc_index::bit_set::FiniteBitSet<u32>, | ||
rustc_session::cstore::ForeignModule, | ||
rustc_session::cstore::LinkagePreference, | ||
rustc_session::cstore::NativeLib, | ||
rustc_span::DebuggerVisualizerFile, | ||
rustc_span::ExpnData, | ||
rustc_span::ExpnHash, | ||
rustc_span::ExpnId, | ||
rustc_span::SourceFile, | ||
rustc_span::Span, | ||
rustc_span::Symbol, | ||
rustc_span::def_id::DefPathHash, | ||
rustc_span::hygiene::SyntaxContextData, | ||
rustc_span::symbol::Ident, | ||
rustc_type_ir::Variance, | ||
} | ||
|
||
// HACK(compiler-errors): This macro rule can only take an ident, | ||
// not a path, due to parsing ambiguity reasons. That means we gotta | ||
// import all of these types above. | ||
#[macro_export] | ||
macro_rules! parameterized_over_tcx { | ||
($($ident:ident),+ $(,)?) => { | ||
$( | ||
impl $crate::ty::ParameterizedOverTcx for $ident<'static> { | ||
type Value<'tcx> = $ident<'tcx>; | ||
} | ||
)* | ||
} | ||
} | ||
|
||
parameterized_over_tcx! { | ||
Ty, | ||
FnSig, | ||
GenericPredicates, | ||
TraitRef, | ||
Const, | ||
Predicate, | ||
GeneratorDiagnosticData, | ||
Body, | ||
Node, | ||
ExportedSymbol, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question: Does this really need to be
: 'static
? These impls also could beimpl<'a> ParameterizedOverTcx for Thing<'a> { type Value<'tcx> = Thing<'tcx>; }
, right? Because This is just encoding a higher-kindedlifetime -> type
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's no good reason why we need
Self: 'static
. That is, it's not there for correctness or anything, necessarily.I treat it more like a mnemonic, where the lifetime error you'd get is there to discourage you from constructing
Lazy<Something<'not_static>>
, since there is no guarantee that the'not_static
lifetime is not related to what you get out oflazy.decode(meta)
.