-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
remove interior mutability of type-flags #42015
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
cc @arielb1 |
src/librustc/ty/mod.rs
Outdated
@@ -507,8 +507,6 @@ bitflags! { | |||
// Caches for type_is_sized, type_moves_by_default | |||
const SIZEDNESS_CACHED = 1 << 16, | |||
const IS_SIZED = 1 << 17, | |||
const MOVENESS_CACHED = 1 << 18, | |||
const MOVES_BY_DEFAULT = 1 << 19, |
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.
Only two flags removed?
617ed25
to
aa511ce
Compare
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.
Just some minor nits, no need to bother if you don't want to.
src/librustc/infer/mod.rs
Outdated
let param_env = param_env.take().unwrap_or_else(|| { | ||
global_tcx.empty_parameter_environment() | ||
}); | ||
let param_env = param_env.take().unwrap_or_else(|| ParameterEnvironment::empty()); |
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.
We could just use ty::ParameterEnvironment
here and avoid adding the import.
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.
Speaking of which, renaming it to ParamEnv
might be a good idea?
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.
I always go back and forth on the importing question. I tend to prefer the import, so as to avoid having to write modules everywhere, and comply more closely with the Rust style guidelines (which suggest importing types, but not fns) -- but it does mean more merge conflicts around use
declarations, which is annoying.
const FREEZENESS_CACHED = 1 << 20, | ||
const IS_FREEZE = 1 << 21, | ||
const NEEDS_DROP_CACHED = 1 << 22, | ||
const NEEDS_DROP = 1 << 23, | ||
} |
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.
I think this is now small enough to be a u16 instead of a u32 bitflags!
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.
It was always wasteful, heh. And I think due to padding it ends up using a lot anyway.
src/librustc_trans/context.rs
Outdated
} | ||
|
||
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool { | ||
ty.is_freeze(self.tcx, &self.empty_param_env, DUMMY_SP) | ||
ty.is_freeze(self.tcx, ParameterEnvironment::empty(), DUMMY_SP) |
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.
Minor, but we could avoid the additional import with ty::ParamEnv
. I think this occurs elsewhere, too.
} | ||
} | ||
|
||
pub struct TyS<'tcx> { | ||
pub sty: TypeVariants<'tcx>, | ||
pub flags: Cell<TypeFlags>, | ||
pub flags: TypeFlags, |
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.
😻
.enter(|infcx| traits::type_known_to_meet_bound(&infcx, ty, trait_def_id, DUMMY_SP)) | ||
} | ||
|
||
fn is_sized_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, |
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.
I see you killed some of the shortcutting?
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.
I figured it'd fall out from the caching anyway.
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.
LGTM, modulo nits.
ok, I made some style changes (s/ParameterEnvironment/ParamEnv/, removed imports) -- I haven't finished building this locally yet though :) |
src/librustc/traits/README.md
Outdated
@@ -418,7 +418,7 @@ before, and hence the cache lookup would succeed, yielding | |||
One subtle interaction is that the results of trait lookup will vary | |||
depending on what where clauses are in scope. Therefore, we actually | |||
have *two* caches, a local and a global cache. The local cache is | |||
attached to the `ParameterEnvironment` and the global cache attached | |||
attached to ParamEnv` and the global cache attached |
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.
This looks wrong, but is minor. Should ideally be "to the ParamEnv
".
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.
fixed.
src/librustc/ty/util.rs
Outdated
@@ -16,7 +16,7 @@ use infer::InferCtxt; | |||
use ich::{StableHashingContext, NodeIdHashingMode}; | |||
use traits::{self, Reveal}; | |||
use ty::{self, Ty, TyCtxt, TypeFoldable}; | |||
use ty::ParameterEnvironment; | |||
use ty::ParamEnv; |
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.
This is again somewhat painful to me since we use both ty::ParamEnv
and ParamEnv
in this file. Don't bother fixing if you don't want to though.
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.
fixed.
4f431a4
to
3977ee7
Compare
☔ The latest upstream changes (presumably #41911) made this pull request unmergeable. Please resolve the merge conflicts. |
@nikomatsakis looks like this is back in your court now, friendly ping! |
Use the trait-environment+type as the key. Note that these are only invoked on types that live for the entire compilation (no inference artifacts). We no longer need the various special-case bits and caches that were in place before.
e3435fb
to
15abc19
Compare
Ideally, we'd have the `Ty` inserted directly in the dep-node, but since we can't do that yet, we extract the characteristic def-id of the type in question.
d9dab46
to
83641a9
Compare
@bors r=eddyb |
📌 Commit 83641a9 has been approved by |
remove interior mutability of type-flags We were previously using the flags on `Ty<'tcx>` instances to do some ad-hoc caching schemes around things like `is_sized()`, `is_freeze()`, and `moves_by_default()`. This PR replaces those schemes with a proper query; the query key is based on the pair of a `(ParameterEnvironment<'tcx>, Ty<'tcx>)` pair. This is also intended to be a preliminary template for what trait-selection and projection will eventually look like. I did some performance measurements. In the past, I observed a noticeable speedup (6%) for building rustc, but since I've rebased, the numbers appear to be more of a wash: | Crate | Before | After | Percentage | | --- | --- | --- | -- | | syntax | 167s | 166s | 0.6% faster | | rustc | 376s | 382s | 1.5% slower | Some advantages of this new scheme: - `is_sized` etc are proper queries - we get caching across generic fns, so long as trait environment is identical - dependency tracking is correct
☀️ Test successful - status-appveyor, status-travis |
We were previously using the flags on
Ty<'tcx>
instances to do some ad-hoc caching schemes around things likeis_sized()
,is_freeze()
, andmoves_by_default()
. This PR replaces those schemes with a proper query; the query key is based on the pair of a(ParameterEnvironment<'tcx>, Ty<'tcx>)
pair. This is also intended to be a preliminary template for what trait-selection and projection will eventually look like.I did some performance measurements. In the past, I observed a noticeable speedup (6%) for building rustc, but since I've rebased, the numbers appear to be more of a wash:
Some advantages of this new scheme:
is_sized
etc are proper queries