summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/encoder.rs
AgeCommit message (Collapse)AuthorLines
2023-01-21Conditionally encode booleanMichael Goulet-2/+4
2023-01-21Encode whether foreign opaques are TAITs or notMichael Goulet-0/+1
2022-11-26Auto merge of #104730 - petrochenkov:modchild5, r=cjgillotbors-7/+5
rustc_metadata: Switch module children decoding to an iterator Previously https://github.com/rust-lang/rust/pull/103578, https://github.com/rust-lang/rust/pull/103524 and previous PRs simplified it as much as possible. A couple of cleanup commits is also added. r? `@cjgillot`
2022-11-24Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors-1/+1
Use `as_deref` in compiler (but only where it makes sense) This simplifies some code :3 (there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-22rustc_metadata: Do not encode empty reexport listsVadim Petrochenkov-7/+5
This is more a cleanup than optimization
2022-11-21Unreserve braced enum variants in value namespaceVadim Petrochenkov-40/+21
2022-11-21Auto merge of #103491 - cjgillot:self-rpit, r=oli-obkbors-2/+2
Support using `Self` or projections inside an RPIT/async fn I reuse the same idea as https://github.com/rust-lang/rust/pull/103449 to use variances to encode whether a lifetime parameter is captured by impl-trait. The current implementation of async and RPIT replace all lifetimes from the parent generics by `'static`. This PR changes the scheme ```rust impl<'a> Foo<'a> { fn foo<'b, T>() -> impl Into<Self> + 'b { ... } } opaque Foo::<'_a>::foo::<'_b, T>::opaque<'b>: Into<Foo<'_a>> + 'b; impl<'a> Foo<'a> { // OLD fn foo<'b, T>() -> Foo::<'static>::foo::<'static, T>::opaque::<'b> { ... } ^^^^^^^ the `Self` becomes `Foo<'static>` // NEW fn foo<'b, T>() -> Foo::<'a>::foo::<'b, T>::opaque::<'b> { ... } ^^ the `Self` stays `Foo<'a>` } ``` There is the same issue with projections. In the example, substitute `Self` by `<T as Trait<'b>>::Assoc` in the sugared version, and `Foo<'_a>` by `<T as Trait<'_b>>::Assoc` in the desugared one. This allows to support `Self` in impl-trait, since we do not replace lifetimes by `'static` any more. The same trick allows to use projections like `T::Assoc` where `Self` is allowed. The feature is gated behind a `impl_trait_projections` feature gate. The implementation relies on 2 tweaking rules for opaques in 2 places: - we only relate substs that correspond to captured lifetimes during TypeRelation; - we only list captured lifetimes in choice region computation. For simplicity, I encoded the "capturedness" of lifetimes as a variance, `Bivariant` vs `Invariant` for unused vs captured lifetimes. The `variances_of` query used to ICE for opaques. Impl-trait that do not reference `Self` or projections will have their variances as: - `o` (invariant) for each parent type or const; - `*` (bivariant) for each parent lifetime --> will not participate in borrowck; - `o` (invariant) for each own lifetime. Impl-trait that does reference `Self` and/or projections will have some parent lifetimes marked as `o` (as the example above), and participate in type relation and borrowck. In the example above, `variances_of(opaque) = ['_a: o, '_b: *, T: o, 'b: o]`. r? types cc `@compiler-errors` , as you asked about the issue with `Self` and projections.
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-1/+1
2022-11-13Store a LocalDefId in hir::Variant & hir::Field.Camille GILLOT-5/+2
2022-11-13Store a LocalDefId in hir::GenericParam.Camille GILLOT-2/+1
2022-11-13Store LocalDefId in hir::Closure.Camille GILLOT-5/+5
2022-11-12Compute variance for opaques too.Camille GILLOT-2/+2
2022-11-01Auto merge of #103496 - petrochenkov:effvisdoc2, r=lqdbors-2/+1
rustc_metadata: Encode even less doc comments The fact that `def_id` is in the `tcx.privacy_access_levels(())` table is not very meaningful, especially after https://github.com/rust-lang/rust/pull/102026, `is_exported` (or `is_reachable` in the worst case) is what you need. Follow up to https://github.com/rust-lang/rust/pull/98450. r? `@GuillaumeGomez` `@lqd`
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-0/+1
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-29Encode LangItem directlyCameron Steffen-13/+6
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-29rustc_metadata: Encode even less doc commentsVadim Petrochenkov-2/+1
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