internal: A bunch of cleanups and micro-optimizations - #23197
internal: A bunch of cleanups and micro-optimizations#23197ChayimFriedman2 wants to merge 5 commits into
Conversation
Instead conjure it only when we initialize. This makes caller cleaner and also a micro-optimization since the initialization closure does not capture anything now.
…n_args_for_alias()` It's not an optimization yet, but in the in-tree solver this function reuses the `GenericArgs` if the assoc has no args of its own.
And since `Projection::project()` does not require `DbInterner`, also remove this requirement from any slice's `new_from_iter()`, which is probably better anyway.
|
|
||
| let interner = DbInterner::new_no_crate(db); | ||
| TYPES.get_or_init(|| { | ||
| let interner = DbInterner::conjure(); |
There was a problem hiding this comment.
DbInterner::conjure has the comment // FIXME(next-solver): remove this method and I see changes like #22119 which went the other way. Is this really desirable?
There was a problem hiding this comment.
I... don't know. It would be nice if we could remove it, but I doubt that. I believe it's the lesser evil.
| } | ||
|
|
||
| #[inline] | ||
| pub(crate) fn new_from_slice_no_empty(slice: &[$ty_db]) -> Self { |
There was a problem hiding this comment.
I'd expect an assert!(slice.is_empty());, or when is it okay to call new_from_slice_no_empty with an actually empty slice?
There was a problem hiding this comment.
This method is intended specifically for empty ranges (mostly), since we need to intern them somewhere (see its callers).
There was a problem hiding this comment.
Its closest caller just above calls it in the non-empty case and it's called no_empty. The logic looks right but the name is super confusing. I think something like new_from_slice_force_interned is clearer?
| }; | ||
| let create_generic_args = |slice| { | ||
| let ty = GenericArgs::new_from_slice(slice); | ||
| let ty = GenericArgs::new_from_slice_no_empty(slice); |
There was a problem hiding this comment.
The create_* functions are explicitly called with the empty slice below to pre-intern it. This is confusing.
There was a problem hiding this comment.
If we call new_from_slice() here, it's deadlock since it accesses what we're interning here.
Details in individual commits.
Reviewing commit-by-commit is recommended; the commits are fully separate.