rust/src
bors 517c28e421 Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakis
lazily "compute" anon const default substs

Continuing the work of #83086, this implements the discussed solution for the [unused substs problem](https://github.com/rust-lang/project-const-generics/blob/master/design-docs/anon-const-substs.md#unused-substs). As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in `fn foo<T, const N: usize>() -> [T; N + 1]`, the array length has `T` as a generic parameter even though it doesn't use it. These *unused substs* cause some backwards incompatible, and imo incorrect behavior, e.g. #78369.

---
We do not actually filter any generic parameters here and the `default_anon_const_substs` query still a dummy which only checks that
- we now prevent the previously existing query cycles and are able to call `predicates_of(parent)` when computing the substs of anonymous constants
- the default anon consts substs only include the typeflags we assume it does.

Implementing that filtering will be left as future work.

---

The idea of this PR is to delay the creation of the anon const substs until after we've computed `predicates_of` for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create a `ty::Const` for it.

We do this by changing the substs field of `ty::Unevaluated` to an option and modifying accesses to instead call the method `unevaluated.substs(tcx)` which returns the substs as before. If the substs - now `substs_` -  of `ty::Unevaluated` are `None`, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to call `unevaluated.substs(tcx)` in a `TypeVisitor`, we add the non-defaulted method `fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>`. In case `tcx_for_anon_const_substs` returns `None`, unknown anon const default substs are skipped entirely.

Even when `substs_` is `None` we still have to treat the constant as if it has its default substs. To do this, `TypeFlags` are modified so that it is clear whether they can still change when *exposing* any anon const default substs. A new flag, `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS`, is added in case some default flags are missing.

The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the `tcx` in previously unused locations.

cc `@rust-lang/project-const-generics`
r? `@nikomatsakis`
2021-08-26 22:26:23 +00:00
..
bootstrap Auto merge of #88069 - Mark-Simulacrum:llvm-pgo, r=pietroalbini 2021-08-26 01:14:16 +00:00
build_helper rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
ci Bump sccache used in CI to v0.2.15 2021-08-25 16:26:45 -04:00
doc Rollup merge of #88277 - ehuss:update-books, r=ehuss 2021-08-25 15:48:57 +02:00
etc set the executable bit on pre-commit.sh 2021-08-11 15:06:33 -04:00
librustdoc Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakis 2021-08-26 22:26:23 +00:00
llvm-project@e6c5dd473b Update to LLVM 13 2021-08-16 20:24:02 +02:00
rustdoc-json-types rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
test Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakis 2021-08-26 22:26:23 +00:00
tools Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakis 2021-08-26 22:26:23 +00:00
README.md
stage0.txt bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04:00
version Bump to 1.56 2021-07-23 17:04:59 -04:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.