summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/encoder.rs
AgeCommit message (Collapse)AuthorLines
2022-10-29Rename some `OwnerId` fields.Nicholas Nethercote-16/+17
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 #102233 - petrochenkov:effvis, r=jackh726bors-3/+2
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-27Rollup merge of #103524 - petrochenkov:modchild4, r=cjgillotMatthias Krüger-6/+18
rustc_metadata: Add struct and variant constructors to module children at encoding time instead of decoding time. Continuation of https://github.com/rust-lang/rust/pull/95899. The last time it caused some ICEs from generator use, but not everything seems ok.
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-3/+2
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26Auto merge of #103284 - compiler-errors:const-sad, r=oli-obkbors-41/+15
Revert "Unify tcx.constness and param env constness checks" Too much of a perf regression https://github.com/rust-lang/rust/pull/102975#issuecomment-1282702513, and an attempt in #103263 didn't fix it except for just a tiny bit. This change isn't really needed (see https://github.com/rust-lang/rust/pull/102830#issuecomment-1272514096), so this should be an easy revert.
2022-10-25rustc_metadata: Add constructors to module children at encoding timeVadim Petrochenkov-6/+18
instead of decoding time.
2022-10-22Auto merge of #103172 - pcwalton:deduced-param-attrs, r=oli-obkbors-1/+16
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-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-1/+16
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-20Add code comments and documentationGuillaume Gomez-0/+14
2022-10-20Remove doc comments only for private items or some specific doc commentsGuillaume Gomez-4/+27
2022-10-20Revert "Unify tcx.constness and param env constness checks"Michael Goulet-41/+15
This reverts commit bef8681a1837790f2745c1f6a7f8214af2fd7f5d. This reverts commit c646c4d403d8c88cd3450f859fbdc34ec26d5bb5.
2022-10-12TyAlias needs encoded constness too, for layout computation in rustdocMichael Goulet-2/+2
2022-10-12Unify tcx.constness and param env constness checksMichael Goulet-15/+41
2022-10-07Rewrite representabilityCameron Steffen-0/+4
2022-09-30Auto merge of #102164 - compiler-errors:rpitit-foreign, r=TaKO8Kibors-0/+33
Serialize return-position `impl Trait` in trait hidden values in foreign libraries Fixes #101630
2022-09-24separate definitions and `HIR` ownersTakayuki Maeda-5/+5
fix a ui test use `into` fix clippy ui test fix a run-make-fulldeps test implement `IntoQueryParam<DefId>` for `OwnerId` use `OwnerId` for more queries change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-23Serialize RPITIT values in libsMichael Goulet-0/+33
2022-09-21Overhaul `-Zmeta-stats` output.Nicholas Nethercote-202/+142
It's now much more like the `-Zhir-stats` output. - Each line is preceded with `meta-stats`, which makes the provenance clearer and allows filtering of the output. - Sections are now sorted in reverse order of size. - Column headings avoid the need to repeat the word "bytes" on every line. - Long numbers now have `_` separators for easier reading. - Consistent use of '-' within section labels, rather than a mix of '-', '_', and ' '. The code itself is shorter and easier to read thanks to: - the `stat` macro, which encapsulates each section's encoding, avoids some boilerplate, and removes the need for some low-value comments; - the `stats` vector, which replaces dozens of local variables.
2022-09-21Wrap some long comment lines.Nicholas Nethercote-10/+9
2022-09-11Only encode RPITIT when trait method has default bodyMichael Goulet-1/+13
2022-09-09Handle generic parameters.Camille GILLOT-3/+0
2022-09-09Address rebase issues, make async fn in trait workMichael Goulet-1/+5
2022-09-09RPITIT placeholder itemsMichael Goulet-0/+5
2022-09-07rustc: Parameterize `ty::Visibility` over used IDVadim Petrochenkov-2/+5
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-05Rollup merge of #101391 - matthiaskrgr:perf0309, r=oli-obkDylan DPC-13/+5
more clippy::perf fixes
2022-09-03more clippy::perf fixesMatthias Krüger-13/+5
2022-09-03Do not call object_lifetime_default on lifetime params.Camille GILLOT-4/+3
2022-09-03Rollup merge of #100928 - CleanCut:rustc_metadata_diagnostics, r=davidtwcoDylan DPC-3/+4
Migrate rustc_metadata to SessionDiagnostics Migrate rustc_metadata to SessionDiagnostics. Part of https://github.com/rust-lang/rust/issues/100717
2022-09-01Auto merge of #98960 - cjgillot:entry-kind, r=estebankbors-247/+174
Remove EntryKind from metadata. This PR continues the refactor of metadata emission to be more systematic, iterating on definitions and filtering based on each definition's `DefKind`. This allows to remove the large `EntryKind` enum, replaced by linear tables in metadata.
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-31respond to review feedback: mainly eliminate as many conversions as possible...Nathan Stocks-3/+3
- ... when creating diagnostics in rustc_metadata - use the error_code! macro - pass macro output to diag.code() - use fluent from within manual implementation of SessionDiagnostic - emit the untested errors in case they occur in the wild - stop panicking in the probably-not-dead code, add fixme to write test
2022-08-31port encoder.rs to SessionDiagnosticsNathan Stocks-3/+4
2022-08-30Handle MIR in a single place.Camille GILLOT-17/+19
2022-08-30Remove fn_has_self_parameter table.Camille GILLOT-6/+0
2022-08-30Separate macro_rules and macro_definition.Camille GILLOT-1/+4
2022-08-30Remove EntryKind.Camille GILLOT-78/+11
2022-08-30Create a module-reexports table.Camille GILLOT-6/+4
2022-08-30Create a table for fn_has_self_parameter.Camille GILLOT-6/+8
2022-08-30Use tables for macros.Camille GILLOT-2/+4
2022-08-30Move AssocContainer to a metadata table.Camille GILLOT-8/+6
2022-08-30Move VariantData to a metadata table.Camille GILLOT-7/+12
2022-08-30Simplify recursion scheme.Camille GILLOT-79/+51
2022-08-30Encode consts in metadata main loop.Camille GILLOT-32/+51
2022-08-30Encode type in the main loop.Camille GILLOT-56/+55
2022-08-29Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errorsDylan DPC-0/+5
Remove separate indexing of early-bound regions ~Based on https://github.com/rust-lang/rust/pull/99728.~ This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults. These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
2022-08-20rmeta/query cache: don't write string values of preinterned symbolsklensy-11/+18
2022-08-19Auto merge of #100209 - cjgillot:source-file-index, r=estebankbors-83/+87
Lazily decode SourceFile from metadata Currently, source files from foreign crates are decoded up-front from metadata. Spans from those crates were matched with the corresponding source using binary search among those files. This PR changes the strategy by matching spans to files during encoding. This allows to decode source files on-demand, instead of up-front. The on-disk format for spans becomes: `<tag> <position from start of file> <length> <file index> <crate (if foreign file)>`.
2022-08-15cache strings while encoding/decoding to compiler artifactsklensy-0/+21
2022-08-09Rollup merge of #96478 - WaffleLapkin:rustc_default_body_unstable, r=Aaron1011Dylan DPC-0/+13
Implement `#[rustc_default_body_unstable]` This PR implements a new stability attribute — `#[rustc_default_body_unstable]`. `#[rustc_default_body_unstable]` controls the stability of default bodies in traits. For example: ```rust pub trait Trait { #[rustc_default_body_unstable(feature = "feat", isssue = "none")] fn item() {} } ``` In order to implement `Trait` user needs to either - implement `item` (even though it has a default implementation) - enable `#![feature(feat)]` This is useful in conjunction with [`#[rustc_must_implement_one_of]`](https://github.com/rust-lang/rust/pull/92164), we may want to relax requirements for a trait, for example allowing implementing either of `PartialEq::{eq, ne}`, but do so in a safe way — making implementation of only `PartialEq::ne` unstable. r? `@Aaron1011` cc `@nrc` (iirc you were interested in this wrt `read_buf`), `@danielhenrymantilla` (you were interested in the related `#[rustc_must_implement_one_of]`) P.S. This is my first time working with stability attributes, so I'm not sure if I did everything right 😅
2022-08-07Only encode position from start of file.Camille GILLOT-13/+13