summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/sty.rs
AgeCommit message (Collapse)AuthorLines
2022-06-19Move RegionKind to rustc_type_irJack Huey-149/+13
2022-06-08Folding revamp.Nicholas Nethercote-1/+2
This commit makes type folding more like the way chalk does it. Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods. - `fold_with` is the standard entry point, and defaults to calling `super_fold_with`. - `super_fold_with` does the actual work of traversing a type. - For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead calls into a `TypeFolder`, which can then call back into `super_fold_with`. With the new approach, `TypeFoldable` has `fold_with` and `TypeSuperFoldable` has `super_fold_with`. - `fold_with` is still the standard entry point, *and* it does the actual work of traversing a type, for all types except types of interest. - `super_fold_with` is only implemented for the types of interest. Benefits of the new model. - I find it easier to understand. The distinction between types of interest and other types is clearer, and `super_fold_with` doesn't exist for most types. - With the current model is easy to get confused and implement a `super_fold_with` method that should be left defaulted. (Some of the precursor commits fixed such cases.) - With the current model it's easy to call `super_fold_with` within `TypeFolder` impls where `fold_with` should be called. The new approach makes this mistake impossible, and this commit fixes a number of such cases. - It's potentially faster, because it avoids the `fold_with` -> `super_fold_with` call in all cases except types of interest. A lot of the time the compile would inline those away, but not necessarily always.
2022-06-03Replace `&Vec<_>`s with `&[_]`sMaybe Waffle-0/+7
2022-05-28Make TyCtxt implement Interner, make HashStable generic and move to ↵Michael Goulet-1/+1
rustc_type_ir
2022-05-28Fix TyKind lint, make consts no longer fn, etcMichael Goulet-200/+4
2022-05-28Initial fixes on top of type interner commitMichael Goulet-3/+1
2022-05-28Move things to rustc_type_irWilco Kusee-5/+31
2022-05-27fix commentlcnr-1/+1
2022-05-14Add bound_explicit_item_bounds and bound_item_boundsJack Huey-0/+24
2022-05-13Add bound_fn_sigJack Huey-1/+1
2022-05-13Add bound_type_ofJack Huey-1/+1
2022-05-10Introduce EarlyBinderJack Huey-3/+44
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-32/+34
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-02fix most compiler/ doctestsElliot Roberts-32/+34
2022-05-02rustc: Panic by default in `DefIdTree::parent`Vadim Petrochenkov-1/+1
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`.
2022-04-26add hacky closure to struct_tail_with_normalize in order to allow us to walk ↵b-naber-1/+1
valtrees in lockstep with the type
2022-03-30get clippy to compile againlcnr-4/+1
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-0/+7
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-26Fix perf issue for auto trait selectionGuillaume Gomez-0/+9
2022-03-20fix two comments referring to moved code (rustc_mir_transform::generator)Audun Halland-1/+1
2022-03-15Auto merge of #94928 - lcnr:inline-as_substs, r=michaelwoeristerbors-0/+1
inline `tuple_fields` more https://github.com/rust-lang/rust/pull/93505 fun, after this i have no idea what might be causing the perf impact.
2022-03-14Rollup merge of #93977 - compiler-errors:sized-generic-metadata, r=wesleywiserMatthias Krüger-10/+13
Type params and assoc types have unit metadata if they are sized Extend the logic in `Pointee` projection to ensure that we can satisfy `<T as Pointee>::Metadata = ()` if `T: Sized`. cc: `@SimonSapin` and #93959
2022-03-14inline `tuple_fields`lcnr-0/+1
2022-03-12Auto merge of #94733 - nnethercote:fix-AdtDef-interning, r=fee1-deadbors-7/+7
Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much of the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. r? `@fee1-dead`
2022-03-11Improve `AdtDef` interning.Nicholas Nethercote-7/+7
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
2022-03-11Auto merge of #94276 - scottmcm:primitive-clone, r=oli-obkbors-0/+51
mir-opt: Replace clone on primitives with copy We can't do it for everything, but it would be nice to at least stop making calls to clone methods in debug from things like derived-clones. r? `@ghost`
2022-03-10Rollup merge of #94746 - notriddle:notriddle/method-rustc-on-unimplemented, ↵Matthias Krüger-0/+9
r=davidtwco diagnostics: use rustc_on_unimplemented to recommend `[].iter()` To make this work, the `#[rustc_on_unimplemented]` data needs to be used to report method resolution errors, which is most of what this commit does. Fixes #94581
2022-03-10Move `is_trivially_pure_clone_copy` onto `Ty` insteadScott McMurray-0/+51
2022-03-09diagnostics: use rustc_on_unimplemented to recommend `[].iter()`Michael Howell-0/+9
To make this work, the `#[rustc_on_unimplemented]` data needs to be used to report method resolution errors, which is most of what this commit does. Fixes #94581
2022-03-06use impl substs in on_unimplementedMichael Goulet-1/+0
2022-03-03opaque types may also be sizedMichael Goulet-5/+4
2022-03-03type parameters have unit metadata if they are sizedMichael Goulet-9/+13
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-21use `List<Ty<'tcx>>` for tupleslcnr-14/+4
2022-02-18Suggest `impl Trait` return typeNilstrieb-2/+22
Address #85991 Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option<T>: Send`), it is not suggested. This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere
2022-02-15Overhaul `Const`.Nicholas Nethercote-1/+1
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Remove unnecessary `RegionKind::` quals.Nicholas Nethercote-8/+8
The variant names are exported, so we can use them directly (possibly with a `ty::` qualifier). Lots of places already do this, this commit just increases consistency.
2022-02-15Overhaul `RegionKind` and `Region`.Nicholas Nethercote-10/+51
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-66/+66
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-7/+0
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-08Update compiler/rustc_middle/src/ty/sty.rslcnr-0/+2
2022-02-08Update compiler/rustc_middle/src/ty/sty.rslcnr-1/+1
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-02-08update `ty::TyKind` documentationlcnr-19/+67
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-0/+7
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-02Update some commentsOli Scherer-0/+1
2022-01-31Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726Matthias Krüger-2/+2
Improve terminology around "after typeck" Closes #70258.
2022-01-28fix nitlcnr-1/+1
2022-01-17Add term to ExistentialProjectionkadmin-7/+3
Also prevent ICE when adding a const in associated const equality.
2022-01-17Update w/ commentskadmin-4/+3
Removes uses of ty() where a method is implemented on TypeFoldable, and also directly formats a Term.
2022-01-17Update term for use in more placeskadmin-1/+1
Replace use of `ty()` on term and use it in more places. This will allow more flexibility in the future, but slightly worried it allows items which are consts which only accept types.