about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta
AgeCommit message (Collapse)AuthorLines
2022-10-23Rollup merge of #103192 - petrochenkov:noalltraits, r=jyn514Dylan DPC-5/+0
rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits` Another step to https://github.com/rust-lang/rust/pull/94857.
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-2/+19
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-2/+19
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-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-19rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits`Vadim Petrochenkov-5/+0
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-1/+8
2022-09-30Auto merge of #102164 - compiler-errors:rpitit-foreign, r=TaKO8Kibors-0/+45
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/+45
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-14make `mk_attr_id` part of `ParseSess`SparrowLii-0/+7
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/+6
2022-09-07rustc: Parameterize `ty::Visibility` over used IDVadim Petrochenkov-9/+21
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-354/+250
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-3/+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-16/+15
2022-08-30Separate macro_rules and macro_definition.Camille GILLOT-10/+12
2022-08-30Remove EntryKind.Camille GILLOT-148/+32
2022-08-30Create a module-reexports table.Camille GILLOT-18/+11
2022-08-30Fix the panic message.Camille GILLOT-1/+1
2022-08-30Create a table for fn_has_self_parameter.Camille GILLOT-15/+17
2022-08-30Use tables for macros.Camille GILLOT-11/+27
2022-08-30Move AssocContainer to a metadata table.Camille GILLOT-17/+24
2022-08-30Move VariantData to a metadata table.Camille GILLOT-24/+25
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/+8
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-26Implementation of import_name_typeDaniel Paoliello-2/+2
2022-08-25Auto merge of #100436 - jyn514:macro-query-system, r=cjgillotbors-12/+12
try and simplify some things in the query system
2022-08-23get rid of another unnecessary lifetime macro argumentJoshua Nelson-12/+12
2022-08-20rmeta/query cache: don't write string values of preinterned symbolsklensy-11/+23
2022-08-19Auto merge of #100209 - cjgillot:source-file-index, r=estebankbors-211/+194
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)>`.