about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2021-08-27Auto merge of #88326 - eddyb:inline-ty-layout-methods, r=oli-obkbors-0/+10
`#[inline]` non-generic `pub fn`s in `rustc_target::abi` and `ty::layout`. Mostly doing this as a perf curiosity, having spotted that `#[inline]` usage is a bit spotty.
2021-08-27Introduce `~const`Deadbeef-6/+1
- [x] Removed `?const` and change uses of `?const` - [x] Added `~const` to the AST. It is gated behind const_trait_impl. - [x] Validate `~const` in ast_validation. - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and `ConstIfConst` allowing future extensions) - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`. - [ ] Optional steps (*for this PR, obviously*) - [ ] Fix #88155 - [ ] Do something with constness bounds in chalk
2021-08-26Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakisbors-144/+478
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-26Auto merge of #87194 - eddyb:const-value-mangling, r=michaelwoerister,oli-obkbors-5/+12
rustc_symbol_mangling: support structural constants and &str in v0. This PR should unblock #85530 (except for float `const` generics, which AFAIK should've never worked). (cc `@tmiasko` could the https://github.com/rust-lang/rust/pull/85530#issuecomment-857855379 failures be retried with a quick crater "subset" run of this PR + changing the default to `v0`? Just to make sure I didn't miss anything other than the floats) The encoding is the one suggested before in e.g. https://github.com/rust-lang/rust/issues/61486#issuecomment-878932102, tho this PR won't by itself finish #61486, before closing that we'd likely want to move to `@oli-obk's` "valtrees" (i.e. #83234 and other associated work). <hr> **EDITs**: 1. switched unit/tuple/braced-with-named-fields `<const-fields>` prefixes from `"u"`/`"T"`/`""` to `"U"`/`"T"`/`"S"` to avoid the ambiguity reported by `@tmiasko` in https://github.com/rust-lang/rust/pull/87194#issuecomment-884279921. 2. `rustc-demangle` PR: https://github.com/alexcrichton/rustc-demangle/pull/55 3. RFC amendment PR: https://github.com/rust-lang/rfcs/pull/3161 * also removed the grammar changes included in that PR, from this description 4. added tests (temporarily using my fork of `rustc-demangle`) <hr> r? `@michaelwoerister`
2021-08-26`#[inline]` non-generic `pub fn`s in `rustc_target::abi` and `ty::layout`.Eduard-Mihai Burtescu-0/+10
2021-08-26Auto merge of #88308 - eddyb:cooked-layouts, r=nagisabors-79/+39
Morph `layout_raw` query into `layout_of`. Before this PR, `LayoutCx::layout_of` wrapped the `layout_raw` query, to: * normalize the type, before attempting to compute the layout * pass the layout to `record_layout_for_printing`, for `-Zprint-type-sizes` Moving those two responsibilities into the query may reduce overhead (due to cached calls skipping those steps), but I want to do a perf run to know. One of the changes I had to make was changing the return type of the query, to be able to both get out the type produced by normalizing inside the query *and* to match the signature of the old `TyCtxt::layout_of`. This change may be worse, perf-wise, so that's another reason I want to check. r? `@nagisa` cc `@oli-obk`
2021-08-26Auto merge of #83698 - erikdesjardins:undefconst, r=RalfJung,oli-obkbors-160/+438
Use undef for uninitialized bytes in constants Fixes #83657 This generates good code when the const is fully uninit, e.g. ```rust #[no_mangle] pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> { const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit(); M } ``` generates ```asm fully_uninit: ret ``` as you would expect. There is no improvement, however, when it's partially uninit, e.g. ```rust pub struct PartiallyUninit { x: u64, y: MaybeUninit<[u8; 10]> } #[no_mangle] pub const fn partially_uninit() -> PartiallyUninit { const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeefcafe, y: MaybeUninit::uninit() }; X } ``` generates ```asm partially_uninit: mov rax, rdi mov rcx, qword ptr [rip + .L__unnamed_1+16] mov qword ptr [rdi + 16], rcx movups xmm0, xmmword ptr [rip + .L__unnamed_1] movups xmmword ptr [rdi], xmm0 ret .L__unnamed_1: .asciz "\376\312\357\276\255\336\000" .zero 16 .size .L__unnamed_1, 24 ``` which copies a bunch of zeros in place of the undef bytes, the same as before this change. Edit: generating partially-undef constants isn't viable at the moment anyways due to #84565, so it's disabled
2021-08-26optimize `HasTypeFlagsVisitor`lcnr-33/+81
2021-08-26inline stufflcnr-0/+4
2021-08-26type flagslcnr-8/+9
2021-08-26reviewlcnr-12/+26
2021-08-26shrink `ty::PredicateKind` againlcnr-10/+54
2021-08-26is_polymorphic doesn't matter for testslcnr-8/+3
2021-08-26ignore const substs in `implicit_infer`lcnr-9/+22
2021-08-26use `ty::Unevaluated` instead of def substs pairlcnr-15/+14
2021-08-26don't just compare `ty::Const`lcnr-0/+44
2021-08-26update `TypeFlags` to deal with missing ct substslcnr-48/+135
2021-08-26add `tcx` to `fn walk`lcnr-19/+24
2021-08-26make unevaluated const substs optionallcnr-63/+107
2021-08-26require a `tcx` for `TypeVisitor`lcnr-8/+44
2021-08-26Auto merge of #88066 - LeSeulArtichaut:patterns-cleanups, r=nagisabors-68/+54
Use if-let guards in the codebase and various other pattern cleanups Dogfooding if-let guards as experimentation for the feature. Tracking issue #51114. Conflicts with #87937.
2021-08-25use a peekable iterator to check the first chunkErik Desjardins-3/+14
2021-08-25yet more comment improvementsErik Desjardins-2/+7
2021-08-25improve commentsErik Desjardins-9/+14
2021-08-25put code in a more logical orderErik Desjardins-345/+350
2021-08-25add commentsErik Desjardins-19/+119
2021-08-25implement InitMaskCompressed using InitChunkIter, cleanupErik Desjardins-23/+33
2021-08-25optimize initialization checksErik Desjardins-9/+102
2021-08-25use undef for uninitialized bytes in constantsErik Desjardins-6/+55
2021-08-25Auto merge of #85499 - jackh726:assoc-type-norm-rebase, r=nikomatsakisbors-2/+1
Normalize projections under binders Fixes #70243 Fixes #70120 Fixes #62529 Fixes #87219 Issues to followup on after (probably fixed, but no test added here): #76956 #56556 #79207 #85636 r? `@nikomatsakis`
2021-08-25Various pattern cleanupsLéo Lanteri Thauvin-45/+35
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-23/+19
2021-08-24Normalize associated types with bound varsJack Huey-2/+1
2021-08-25Auto merge of #88242 - bonega:allocation_range, r=oli-obkbors-16/+23
Use custom wrap-around type instead of RangeInclusive Two reasons: 1. More memory is allocated than necessary for `valid_range` in `Scalar`. The range is not used as an iterator and `exhausted` is never used. 2. `contains`, `count` etc. methods in `RangeInclusive` are doing very unhelpful(and dangerous!) things when used as a wrap-around range. - In general this PR wants to limit potentially confusing methods, that have a low probability of working. Doing a local perf run, every metric shows improvement except for instructions. Max-rss seem to have a very consistent improvement. Sorry - newbie here, probably doing something wrong.
2021-08-24Morph `layout_raw` query into `layout_of`.Eduard-Mihai Burtescu-79/+39
2021-08-24Fix typo (variant_id should've been variant_idx).Eduard-Mihai Burtescu-3/+3
2021-08-24Pretty-print uninhabited const values more explicitly.Eduard-Mihai Burtescu-2/+9
2021-08-24Auto merge of #87900 - jackh726:issue-87429, r=nikomatsakisbors-2/+2
Use bound vars for GAT params in param_env in check_type_bounds Fixes #87429
2021-08-24Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiserbors-2/+2
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor` Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-23When checking associated type bounds, use bound vars for GAT params in param_envjackh726-2/+2
2021-08-23Rollup merge of #88230 - steffahn:a_an, r=oli-obkMara Bos-33/+33
Fix typos “a”→“an” Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an. While automation was used to find these, every change was checked manually. Changes in submodules get separate PRs: * https://github.com/rust-lang/stdarch/pull/1201 * https://github.com/rust-lang/cargo/pull/9821 * https://github.com/rust-lang/miri/pull/1874 * https://github.com/rust-lang/rls/pull/1746 * https://github.com/rust-analyzer/rust-analyzer/pull/9984 _folks @ rust-analyzer are fast at merging…_ * https://github.com/rust-analyzer/rust-analyzer/pull/9985 * https://github.com/rust-analyzer/rust-analyzer/pull/9987 * https://github.com/rust-analyzer/rust-analyzer/pull/9989 _For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._ <hr> This has some overlap with #88226, but neither is a strict superset of the other. If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23add `with_start` and `with_end`Andreas Liljeqvist-5/+3
2021-08-23Rename to WrappingRangeAndreas Liljeqvist-8/+8
2021-08-23implement contains_zero methodAndreas Liljeqvist-4/+2
2021-08-23remove commented codeAndreas Liljeqvist-4/+0
2021-08-22Use custom wrap-around type instead of RangeAndreas Liljeqvist-14/+29
2021-08-22Rollup merge of #88211 - petrochenkov:withhilo, r=jyn514Guillaume Gomez-1/+1
cleanup: `Span::new` -> `Span::with_lo` Extracted from https://github.com/rust-lang/rust/pull/84373 as suggested in https://github.com/rust-lang/rust/pull/84373#issuecomment-857773867. It turned out less useful then I expected, but anyway. r? `@cjgillot` `@bors` rollup
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-12/+12
same search
2021-08-22Fix more “a”/“an” typosFrank Steffahn-2/+2
2021-08-22Fix typos “a”→“an”Frank Steffahn-19/+19