about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/fold.rs
AgeCommit message (Collapse)AuthorLines
2023-03-20drive-by: Fix a comment in TyCtxt::fold_regions and remove an unused methodMichael Goulet-14/+1
2023-02-24Rename many interner functions.Nicholas Nethercote-1/+1
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-02-22Remove type-traversal trait aliasesAlan Egerton-29/+20
2023-02-15Add specialized variants of `mk_region`.Nicholas Nethercote-11/+7
Much like there are specialized variants of `mk_ty`. This will enable some optimization in the next commit. Also rename the existing `re_error*` functions as `mk_re_error*`, for consistency.
2023-02-15Remove `reuse_or_mk_region`.Nicholas Nethercote-1/+1
It's not used on any hot paths, and so has little perf benefit, and it interferes with the optimizations in the following commits.
2023-02-13Rename folder traits' `tcx` method to `interner`Alan Egerton-4/+4
2023-02-13Move folding and visiting traits into type libraryAlan Egerton-239/+3
2023-02-13Make folding traits generic over the InternerAlan Egerton-49/+79
2023-02-13Make visiting traits generic over the InternerAlan Egerton-1/+1
2023-02-13Alias folding/visiting traits instead of re-exportAlan Egerton-5/+8
2023-02-13Move folding & visiting traits to ir submodulesAlan Egerton-130/+142
2023-02-13Reduce direct `mk_ty` usage.Nicholas Nethercote-6/+3
We use more specific `mk_*` functions in most places, might as well use them as much as possible.
2023-02-03Make const/fn return params more suggestableMichael Goulet-1/+1
2023-01-30Track bound types like bound regionsMichael Goulet-1/+3
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-1/+1
2022-12-14always use anonymize_bound_varsMichael Goulet-30/+0
2022-11-26simplify some binder shifting logicMichael Goulet-23/+24
2022-11-07Add an optional Span to BrAnon and use it to print better error for HRTB ↵Jack Huey-3/+5
error from generator interior
2022-11-04Refactor tcx mk_const parameters.Mateusz-9/+3
2022-10-19stop folding `UnevaluatedConst`lcnr-21/+0
2022-10-17mir constants: type traversing bye byelcnr-40/+0
2022-10-14more dupe word typosRageking8-2/+1
2022-09-23rename Unevaluated to UnevaluatedConstb-naber-10/+16
2022-09-22introduce mir::Unevaluatedb-naber-4/+22
2022-09-17Auto merge of #101857 - lcnr:make-dyn-again, r=jackh726bors-17/+13
change `FnMutDelegate` to trait objects cc #100016 as mentioned in the last t-compiler meeting r? `@jackh726`
2022-09-15change `FnMutDelegate` to trait objectslcnr-17/+13
2022-09-14address review againb-naber-0/+11
2022-09-01tracing::instrument cleanupOli Scherer-1/+1
2022-07-29optimize bound vars replacement :3lcnr-18/+22
2022-07-28anonymize all bound vars, not just regionslcnr-6/+51
2022-07-28`BoundVarReplacer`: trait object instead of 3 fnslcnr-66/+68
2022-07-14eagerly check for bound vars of predicateslcnr-0/+4
2022-07-14remove `ct.has_vars_bound_at_or_above` callslcnr-2/+1
`ty::Const` doesn't have precomputed type flags, so computing `has_vars_bound_at_or_above` for constants requires us to visit the const and its contained types and constants. A noop fold should be pretty much equally as fast so removing it prevents us from walking the constant twice in case it contains bound vars.
2022-07-05Split TypeVisitable from TypeFoldableAlan Egerton-733/+35
2022-06-27fold_region: remove unused parameterlcnr-6/+2
2022-06-21Remove unecessary references to TypeFolder::ErrorAlan Egerton-21/+15
2022-06-21Reverse folder hierarchyAlan Egerton-30/+19
#91318 introduced a trait for infallible folders distinct from the fallible version. For some reason (completely unfathomable to me now that I look at it with fresh eyes), the infallible trait was a supertrait of the fallible one: that is, all fallible folders were required to also be infallible. Moreover the `Error` associated type was defined on the infallible trait! It's so absurd that it has me questioning whether I was entirely sane. This trait reverses the hierarchy, so that the fallible trait is a supertrait of the infallible one: all infallible folders are required to also be fallible (which is a trivial blanket implementation). This of course makes much more sense! It also enables the `Error` associated type to sit on the fallible trait, where it sensibly belongs. There is one downside however: folders expose a `tcx` accessor method. Since the blanket fallible implementation for infallible folders only has access to a generic `F: TypeFolder`, we need that trait to expose such an accessor to which we can delegate. Alternatively it's possible to extract that accessor into a separate `HasTcx` trait (or similar) that would then be a supertrait of both the fallible and infallible folder traits: this would ensure that there's only one unambiguous `tcx` method, at the cost of a little additional boilerplate. If desired, I can submit that as a separate PR. r? @jackh726
2022-06-20`try_fold_unevaluated` for infallible foldersAlan Egerton-0/+7
#97447 added folding of unevaluated constants, but did not include an override of the default (fallible) operation in the blanket impl of `FallibleTypeFolder` for infallible folders. Here we provide that missing override. r? @nnethercote
2022-06-14Rename the `ConstS::val` field as `kind`.Nicholas Nethercote-7/+7
And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant.
2022-06-10don't always cache bound ltslcnr-9/+18
2022-06-10replace bound vars: make caching explicitlcnr-9/+6
2022-06-10`BoundVarReplacer` remove `Option`lcnr-45/+36
2022-06-08Folding revamp.Nicholas Nethercote-60/+72
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-08Add `try_fold_uenevaluted`.Nicholas Nethercote-0/+14
We already have `visit_unevaluated`, so this improves consistency. Also, define `TypeFoldable for Unevaluated<'tcx, ()>` in terms of `TypeFoldable for Unevaluated<'tcx>`, which is neater.
2022-06-08Add `TypeVisitor::visit_mir_const`.Nicholas Nethercote-0/+4
Because `TypeFoldable::try_fold_mir_const` exists, and even though `visit_mir_const` isn't needed right now, the consistency makes the code easier to understand.
2022-06-08Use `super_visit_with` in a couple of `visit_binder` methods.Nicholas Nethercote-1/+1
Because it's equivalent but simpler to what's currently there.
2022-06-08Rename `TypeVisitor::visit_unevaluated_const`.Nicholas Nethercote-2/+2
To match the corresponding type name.
2022-05-10Use lifetimes on type-alias-impl-trait used in function signatures to infer ↵Oli Scherer-1/+1
output type lifetimes
2022-05-02fix most compiler/ doctestsElliot Roberts-8/+8
2022-03-31Rollup merge of #94869 - jackh726:gats_extended, r=compiler-errorsDylan DPC-0/+47
Add the generic_associated_types_extended feature Right now, this only ignore obligations that reference new placeholders in `poly_project_and_unify_type`. In the future, this might do other things, like allowing object-safe GATs. **This feature is *incomplete* and quite likely unsound. This is mostly just for testing out potential future APIs using a "relaxed" set of rules until we figure out *proper* rules.** Also drive by cleanup of adding a `ProjectAndUnifyResult` enum instead of using a `Result<Result<Option>>`. r? `@nikomatsakis`