summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2022-12-11Bump the const eval step limitOli Scherer-1/+1
2022-10-29Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errorsGuillaume Gomez-15/+10
Accept `TyCtxt` instead of `TyCtxtAt` in `Ty::is_*` functions Functions in answer: - `Ty::is_freeze` - `Ty::is_sized` - `Ty::is_unpin` - `Ty::is_copy_modulo_regions` This allows to remove a lot of useless `.at(DUMMY_SP)`, making the code a bit nicer :3 r? `@compiler-errors`
2022-10-29Rollup merge of #103618 - nnethercote:rename-OwnerId-fields, r=compiler-errorsGuillaume Gomez-20/+20
Rename some `OwnerId` fields. `@spastorino` noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone. r? `@compiler-errors`
2022-10-29Rename some `OwnerId` fields.Nicholas Nethercote-20/+20
spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.
2022-10-29Auto merge of #102698 - michaelwoerister:unord-collections, r=lncrbors-3/+5
Introduce UnordMap, UnordSet, and UnordBag (MCP 533) This is the start of implementing [MCP 533](https://github.com/rust-lang/compiler-team/issues/533). I followed `@eddyb's` suggestion of naming the collection types `Unord(Map/Set/Bag)` which is a bit easier to type than `Unordered(Map/Set/Bag)` r? `@eddyb`
2022-10-29Auto merge of #102233 - petrochenkov:effvis, r=jackh726bors-87/+86
privacy: Rename "accessibility levels" to "effective visibilities" And a couple of other naming and comment tweaks. Related to https://github.com/rust-lang/rust/issues/48054 For `enum Level` I initially used naming `enum EffectiveVisibilityLevel`, but it was too long and inconvenient because it's used pretty often. So I shortened it to just `Level`, if it needs to be used from some context where this name would be ambiguous, then it can be imported with renaming like `use rustc_middle::privacy::Level as EffVisLevel` or something.
2022-10-28Auto merge of #103071 - wesleywiser:fix_inlined_line_numbers, r=davidtwcobors-1/+3
Fix line numbers for MIR inlined code `should_collapse_debuginfo` detects if the specified span is part of a macro expansion however it does this by checking if the span is anything other than a normal (non-expanded) kind, then the span sequence is walked backwards to the root span. This doesn't work when the MIR inliner inlines code as it creates spans with expansion information set to `ExprKind::Inlined` and results in the line number being attributed to the inline callsite rather than the normal line number of the inlined code. Fixes #103068
2022-10-27Revert "Make ClosureOutlivesRequirement not rely on an unresolved type"Michael Goulet-14/+12
This reverts commit a6b5f95fb028f9feb4a2957c06b35035be2c6155.
2022-10-27Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)Michael Woerister-3/+5
MCP 533: https://github.com/rust-lang/compiler-team/issues/533 Also, as an example, substitute UnordMap for FxHashMap in used_trait_imports query result.
2022-10-27Accept `TyCtxt` instead of `TyCtxtAt` in `Ty::is_*` functionsMaybe Waffle-15/+10
Functions in answer: - `Ty::is_freeze` - `Ty::is_sized` - `Ty::is_unpin` - `Ty::is_copy_modulo_regions`
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-87/+86
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26Rollup merge of #103428 - SarthakSingh31:issue-94187, r=compiler-errorsDylan DPC-3/+7
Removed verbose printing from the `PrettyPrinter` when printing constants Partially solves #94187 by completing the first step described in [this comment](https://github.com/rust-lang/rust/issues/94187#issuecomment-1282339909).
2022-10-26Auto merge of #103562 - Dylan-DPC:rollup-sheepp5, r=Dylan-DPCbors-22/+32
Rollup of 10 pull requests Successful merges: - #102951 (suggest type annotation for local statement initialed by ref expression) - #103209 (Diagnostic derives: allow specifying multiple alternative suggestions) - #103287 (Use a faster allocation size check in slice::from_raw_parts) - #103416 (Name the `impl Trait` in region bound suggestions) - #103430 (Workaround unstable stmt_expr_attributes for method receiver expressions) - #103444 (Remove extra type error after missing semicolon error) - #103520 (rustc_middle: Rearrange resolver outputs structures slightly) - #103533 (Use &self instead of &mut self for cast methods) - #103536 (Remove `rustc_driver::set_sigpipe_handler()`) - #103542 (Pinning tests for some `macro_rules!` errors discussed in the lang meeting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-10-26Rollup merge of #103520 - petrochenkov:resout, r=cjgillotDylan DPC-22/+32
rustc_middle: Rearrange resolver outputs structures slightly Addresses https://github.com/rust-lang/rust/pull/98106#discussion_r898427061. I also haven't seen the motivation for moving `cstore` from its old place, so I moved it back in this PR. r? ```@cjgillot```
2022-10-26Auto merge of #103279 - compiler-errors:normalize-hack-back, r=lcnrbors-2/+13
Add eval hack in `super_relate_consts` back Partially reverts 01adb7e98d5656c06497f33dd2747df144e78356. This extra eval call *still* needs to happen, for example, in `normalize_param_env_or_error` when a param-env predicate has an unnormalized constant, since the param-env candidates never get normalized during candidate assembly (everywhere else we can assume that they are normalized fully). r? `@lcnr,` though I feel like I've assigned quite a few PRs to you in the last few days, so feel free to reassign to someone else familiar with this code if you're busy! cc #103243 (fixes the issue, but don't want to auto-close that until a backport is performed).
2022-10-26Auto merge of #103158 - Bryanskiy:resolve_perf, r=petrochenkovbors-33/+35
Perf improvements for effective visibility calculating related to https://github.com/rust-lang/rust/pull/102026 r? `@petrochenkov`
2022-10-25Auto merge of #102340 - JakobDegen:pass-manager-simplification, r=oli-obkbors-5/+34
Split phase change from `MirPass` The main goal here is to simplify the pass manager logic. `MirPass` no longer contains the `phase_change` method, and `run_passes` instead accepts an `Option<PhaseChange>`. The hope is that this addresses the comments (and maybe perf regression) from #99102 . r? `@oli-obk` cc `@RalfJung`
2022-10-25Perf improvements for effective visibility calculatingBryanskiy-33/+35
2022-10-25rustc_middle: Rearrange resolver outputs structures slightlyVadim Petrochenkov-22/+32
2022-10-25Added helper to prevent verbose printing from the `PrettyPrinter` when ↵Sarthak Singh-3/+7
printing constants
2022-10-23Rollup merge of #103414 - compiler-errors:rpit-print-lt, r=cjgillotMichael Howell-0/+10
Pretty print lifetimes captured by RPIT This specifically makes the output in #103409 change from: ```diff error: `impl` item signature doesn't match `trait` item signature --> $DIR/signature-mismatch.rs:15:5 | LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>; | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` ... LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` - found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` + found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output error: aborting due to previous error ``` Along with the UI tests in this PR, which I think are all improvements! r? `@oli-obk` though feel free to re-roll
2022-10-23Split phase change from `MirPass`Jakob Degen-5/+34
2022-10-23Add normalize hack backMichael Goulet-2/+13
2022-10-23Annotate static lifetimes tooMichael Goulet-9/+3
2022-10-23Auto merge of #103345 - Nilstrieb:diag-flat, r=compiler-errorsbors-10/+10
Flatten diagnostic slug modules This makes it easier to grep for the slugs in the code. See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Localization.20infra.20interferes.20with.20grepping.20for.20error for more discussion about it. This was mostly done with a few regexes and a bunch of manual work. This also exposes a pretty annoying inconsistency for the extra labels. Some of the extra labels are defined as additional properties in the fluent message (which makes them not prefixed with the crate name) and some of them are new fluent messages themselves (which makes them prefixed with the crate name). I don't know whether we want to clean this up at some point but it's useful to know. r? `@davidtwco`
2022-10-23Migrate all diagnosticsNilstrieb-10/+10
2022-10-23Auto merge of #103426 - matthiaskrgr:rollup-n6dqdy8, r=matthiaskrgrbors-2/+24
Rollup of 9 pull requests Successful merges: - #103123 (Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder` ) - #103328 (Do not suggest trivially false const predicates) - #103354 (Escape string literals when fixing overlong char literal) - #103355 (Handle return-position `impl Trait` in traits properly in `register_hidden_type`) - #103368 (Delay ambiguity span bug in normalize query iff not rustdoc) - #103388 (rustdoc: remove unused CSS class `.result-description`) - #103399 (Change `unknown_lint` applicability to `MaybeIncorrect`) - #103401 (Use functions for headings rustdoc GUI test) - #103412 (Fix typo in docs of `String::leak`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-10-23Rollup merge of #103123 - compiler-errors:early-binder-iter, r=cjgillotMatthias Krüger-2/+24
Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder` Makes working with bounds lists a bit easier, which I seem to do a lot. Specifically, means that we don't need to do `.transpose_iter().map(|(pred, _)| *pred)` every time we want to iterate through an `EarlyBinder<&'tcx [(Predicate, Span)]>` (and even then, still have to call `subst` later), which was a very awkward idiom imo.
2022-10-23Auto merge of #102660 - camsteffen:uninhabited-perf, r=oli-obkbors-301/+323
Remove ParamEnv from uninhabited query
2022-10-22Pretty print lifetimes captured by RPITMichael Goulet-0/+16
2022-10-22Introduce InhabitedPredicateCameron Steffen-301/+323
2022-10-22Auto merge of #103227 - lcnr:bye-bye-unevaluated-const, r=oli-obkbors-84/+65
stop using `ty::UnevaluatedConst` directly best reviewed commit by commit. simplifies #99798 because we now don't have to expand `ty::UnevaluatedConst` to `ty::Const`. I also remember some other places where using `ty::UnevaluatedConst` directly was annoying and caused issues, though I don't quite remember what they were rn '^^ r? `@oli-obk` cc `@JulianKnodt`
2022-10-22Introduce subst_iter and subst_iter_copied on EarlyBinderMichael Goulet-2/+24
2022-10-22Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillotbors-11/+0
Get rid of native_library projection queries They don't seem particularly useful as I don't expect native libraries to change frequently. Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2022-10-22Auto merge of #103172 - pcwalton:deduced-param-attrs, r=oli-obkbors-1/+23
Introduce deduced parameter attributes, and use them for deducing `readonly` on indirect immutable freeze by-value function parameters. Introduce deduced parameter attributes, and use them for deducing `readonly` on indirect immutable freeze by-value function parameters. Right now, `rustc` only examines function signatures and the platform ABI when determining the LLVM attributes to apply to parameters. This results in missed optimizations, because there are some attributes that can be determined via analysis of the MIR making up the function body. In particular, `readonly` could be applied to most indirectly-passed by-value function arguments (specifically, those that are freeze and are observed not to be mutated), but it currently is not. This patch introduces the machinery that allows `rustc` to determine those attributes. It consists of a query, `deduced_param_attrs`, that, when evaluated, analyzes the MIR of the function to determine supplementary attributes. The results of this query for each function are written into the crate metadata so that the deduced parameter attributes can be applied to cross-crate functions. In this patch, we simply check the parameter for mutations to determine whether the `readonly` attribute should be applied to parameters that are indirect immutable freeze by-value. More attributes could conceivably be deduced in the future: `nocapture` and `noalias` come to mind. Adding `readonly` to indirect function parameters where applicable enables some potential optimizations in LLVM that are discussed in [issue 103103] and [PR 103070] around avoiding stack-to-stack memory copies that appear in functions like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These functions pass a large structure unchanged by value to a subfunction that also doesn't mutate it. Since the structure in this case is passed as an indirect parameter, it's a pointer from LLVM's perspective. As a result, the intermediate copy of the structure that our codegen emits could be optimized away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly nocapture noalias` in both the caller and callee. We already pass `nocapture noalias`, but we're missing `readonly`, as we can't determine whether a by-value parameter is mutated by examining the signature in Rust. I didn't have much success with having LLVM infer the `readonly` attribute, even with fat LTO; it seems that deducing it at the MIR level is necessary. No large benefits should be expected from this optimization *now*; LLVM needs some changes (discussed in [PR 103070]) to more aggressively use the `noalias nocapture readonly` combination in its alias analysis. I have some LLVM patches for these optimizations and have had them looked over. With all the patches applied locally, I enabled LLVM to remove all the `memcpy`s from the following code: ```rust fn main() { println!("Hello {}", 3); } ``` which is a significant codegen improvement over the status quo. I expect that if this optimization kicks in in multiple places even for such a simple program, then it will apply to Rust code all over the place. [issue 103103]: https://github.com/rust-lang/rust/issues/103103 [PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-21fix some typosRageking8-1/+1
2022-10-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-1/+23
indirect immutable freeze by-value function parameters. Right now, `rustc` only examines function signatures and the platform ABI when determining the LLVM attributes to apply to parameters. This results in missed optimizations, because there are some attributes that can be determined via analysis of the MIR making up the function body. In particular, `readonly` could be applied to most indirectly-passed by-value function arguments (specifically, those that are freeze and are observed not to be mutated), but it currently is not. This patch introduces the machinery that allows `rustc` to determine those attributes. It consists of a query, `deduced_param_attrs`, that, when evaluated, analyzes the MIR of the function to determine supplementary attributes. The results of this query for each function are written into the crate metadata so that the deduced parameter attributes can be applied to cross-crate functions. In this patch, we simply check the parameter for mutations to determine whether the `readonly` attribute should be applied to parameters that are indirect immutable freeze by-value. More attributes could conceivably be deduced in the future: `nocapture` and `noalias` come to mind. Adding `readonly` to indirect function parameters where applicable enables some potential optimizations in LLVM that are discussed in [issue 103103] and [PR 103070] around avoiding stack-to-stack memory copies that appear in functions like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These functions pass a large structure unchanged by value to a subfunction that also doesn't mutate it. Since the structure in this case is passed as an indirect parameter, it's a pointer from LLVM's perspective. As a result, the intermediate copy of the structure that our codegen emits could be optimized away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly nocapture noalias` in both the caller and callee. We already pass `nocapture noalias`, but we're missing `readonly`, as we can't determine whether a by-value parameter is mutated by examining the signature in Rust. I didn't have much success with having LLVM infer the `readonly` attribute, even with fat LTO; it seems that deducing it at the MIR level is necessary. No large benefits should be expected from this optimization *now*; LLVM needs some changes (discussed in [PR 103070]) to more aggressively use the `noalias nocapture readonly` combination in its alias analysis. I have some LLVM patches for these optimizations and have had them looked over. With all the patches applied locally, I enabled LLVM to remove all the `memcpy`s from the following code: ```rust fn main() { println!("Hello {}", 3); } ``` which is a significant codegen improvement over the status quo. I expect that if this optimization kicks in in multiple places even for such a simple program, then it will apply to Rust code all over the place. [issue 103103]: https://github.com/rust-lang/rust/issues/103103 [PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-20Auto merge of #103220 - compiler-errors:deny-infers, r=lcnrbors-17/+28
Deny hashing ty/re/ct inference variables cc `@cjgillot` and https://github.com/rust-lang/rust/pull/102695#issuecomment-1275706528 r? `@lcnr` best reviewed one commit at a time, mostly because the second commit that fixes `ClosureOutlivesRequirement` is mostly noise because of losing its `<'tcx>` lifetime parameter.
2022-10-20Auto merge of #102417 - oli-obk:opaque_lifetimes2, r=jackh726bors-2/+75
Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes fixes #96996 cc `@aliemjay`
2022-10-19Deny const variables as wellMichael Goulet-4/+11
2022-10-19Don't call `own_existential_vtable_entries` on unresolved trait refMichael Goulet-2/+2
2022-10-19Make ClosureOutlivesRequirement not rely on an unresolved typeMichael Goulet-12/+14
2022-10-19Don't hash non-fresh Ty::Infer or RegionKind::InferMichael Goulet-2/+4
2022-10-19Get rid of native_library projection queriesnils-11/+0
They don't seem particularly useful as I don't expect native libraries to change frequently.
2022-10-19stop folding `UnevaluatedConst`lcnr-77/+5
2022-10-18Clean up query descriptionsnils-89/+92
Use the same tense everywhere and prefer display over debug, as these descriptions are user facing.
2022-10-18`const_evaluatable_unchecked` to const evallcnr-1/+26
2022-10-18change `ConstEvaluatable` to use `ty::Const`lcnr-6/+34
2022-10-17Auto merge of #102355 - lcnr:bye-bye-type-traversal, r=oli-obkbors-185/+21
remove type traversal for mir constants r? `@oli-obk` cc `@b-naber`
2022-10-17add inline to `TrivialTypeTraversalImpls`lcnr-14/+17