summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/decoder.rs
AgeCommit message (Collapse)AuthorLines
2021-10-07Rollup merge of #89476 - cjgillot:expn-id, r=petrochenkovJubilee-4/+2
Correct decoding of foreign expansions during incr. comp. Fixes https://github.com/rust-lang/rust/issues/74946 The original issue was due to a wrong assertion in `expn_hash_to_expn_id`. The secondary issue was due to a mismatch between the encoding and decoding paths for expansions that are created after the TyCtxt is created.
2021-10-06Do not ICE if some foreign expansions were not encoded.Camille GILLOT-2/+0
The metadata encoder does not necessarily encode all expansions, only those which are referenced in other metadata fields.
2021-10-06Access Session while decoding expn_id.Camille GILLOT-2/+2
2021-10-06Introduce get_diagnostic_nameCameron Steffen-4/+12
2021-10-03Move rustc_middle::middle::cstore to rustc_session.Camille GILLOT-2/+3
2021-09-14rustc_metadata: Remove Metadata::raw_bytes() and use Metadata::blob() ↵Michael Woerister-7/+4
directly instead.
2021-09-14Rename DefPathHashMap in rustc_metadata so its name does not clash with ↵Michael Woerister-2/+2
DefPathHashMap in rustc_hir.
2021-09-14Make DefPathHash->DefId panic for if the mapping fails.Michael Woerister-1/+1
We only use this mapping for cases where we know that it must succeed. Letting it panic otherwise makes it harder to use the API in unsupported ways.
2021-09-14Store DefPathHash->DefIndex map in on-disk-hash-table format in crate metadata.Michael Woerister-57/+18
This encoding allows for random access without an expensive upfront decoding state which in turn allows simplifying the DefPathIndex lookup logic without regressing performance.
2021-09-14Allow taking an OwningRef of the crate metadata blob.Michael Woerister-17/+61
2021-09-12Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnrManish Goregaokar-4/+5
generic_const_exprs: use thir for abstract consts instead of mir Changes `AbstractConst` building to use `thir` instead of `mir` so that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (see `abstract-consts-as-cast-5.rs` test) r? `@lcnr`
2021-09-12Rollup merge of #88677 - petrochenkov:exportid, r=davidtwcoManish Goregaokar-4/+1
rustc: Remove local variable IDs from `Export`s Local variables can never be exported.
2021-09-10rustc: Remove local variable IDs from `Export`sVadim Petrochenkov-4/+1
Local variables can never be exported.
2021-09-10Keep a parent LocalDefId in SpanData.Camille GILLOT-1/+2
2021-09-09rename mir -> thir around abstract constsEllen-4/+5
2021-08-28Treat macros as HIR itemsinquisitivecrystal-1/+7
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-07-17Drop ExpnData::krate.Camille GILLOT-1/+1
2021-07-17Drop orig_id.Camille GILLOT-1/+1
2021-07-17Encode ExpnId using ExpnHash for incr. comp.Camille GILLOT-0/+38
2021-07-17Choose encoding format in caller code.Camille GILLOT-2/+7
2021-07-17Make the CrateNum part of the ExpnId.Camille GILLOT-1/+8
2021-07-15Simplify metadata decoding.Camille GILLOT-14/+4
2021-07-15Separate encoding paths.Camille GILLOT-28/+23
The two paths will be modified independently in the next few commits.
2021-07-13Auto merge of #87044 - cjgillot:expnhash, r=petrochenkovbors-2/+9
Cache expansion hash globally ... instead of computing it multiple times. Split from #86676 r? `@petrochenkov`
2021-07-13Cache expansion hash.Camille GILLOT-2/+9
2021-07-13Auto merge of #86857 - fee1-dead:add-attr, r=oli-obkbors-0/+4
Add #[default_method_body_is_const] `@rustbot` label F-const_trait_impl
2021-07-10rustc_expand: Remove redundant field from proc macro expander structuresVadim Petrochenkov-18/+11
This information is already available from `ExpnData`
2021-07-10Add impl_constness queryDeadbeef-0/+4
2021-07-06Revert "Revert "Merge CrateDisambiguator into StableCrateId""bjorn3-6/+2
This reverts commit 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.
2021-06-21Print more crate details in -ZlsJeremy Fitzhardinge-2/+15
Useful for debugging crate hash and resolution issues.
2021-06-09Encode CrateNum using the StableCrateId for incr. comp.Camille GILLOT-4/+4
2021-06-07Revert "Merge CrateDisambiguator into StableCrateId"bjorn3-2/+6
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
2021-06-03Restore the num_def_ids_untracked public function giving the total number of ↵Denis Merigoux-0/+4
exported symbols for each crate Restored underlying num_def_ids_method Update compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs Changed name to fit with naming convention Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com> Update compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs Replace regular doc with Rustdoc comment Co-authored-by: Joshua Nelson <jyn514@gmail.com> Clarifies third-party use of num_def_ids_untracked
2021-06-01Auto merge of #85829 - bjorn3:simplify_crate_num, r=jackh726bors-1/+1
Remove CrateNum::ReservedForIncrCompCache It's only use is easily replaceable with `Option<CrateNum>`.
2021-05-30Remove CrateNum::ReservedForIncrCompCachebjorn3-1/+1
2021-05-30Merge CrateDisambiguator into StableCrateIdbjorn3-6/+2
2021-05-14Auto merge of #85211 - Aaron1011:metadata-invalid-span, r=michaelwoeristerbors-3/+3
Preserve `SyntaxContext` for invalid/dummy spans in crate metadata Fixes #85197 We already preserved the `SyntaxContext` for invalid/dummy spans in the incremental cache, but we weren't doing the same for crate metadata. If an invalid (lo/hi from different files) span is written to the incremental cache, we will decode it with a 'dummy' location, but keep the original `SyntaxContext`. Since the crate metadata encoder was only checking for `DUMMY_SP` (dummy location + root `SyntaxContext`), the metadata encoder would treat it as a normal span, encoding the `SyntaxContext`. As a result, the final span encoded to the metadata would change across sessions, even if the crate itself was unchanged. This could lead to an 'unstable fingerprint' ICE under the following conditions: 1. We compile a crate with an invalid span using incremental compilation. The metadata encoder discards the `SyntaxContext` since the span is invalid, while the incremental cache encoder preserves the `SyntaxContext` 2. From another crate, we execute a foreign query, decoding the invalid span from the metadata as `DUMMY_SP` (e.g. with `SyntaxContext::root()`). This span gets hashed into the query fingerprint. So far, this has always happened through the `optimized_mir` query. 3. We recompile the first crate using our populated incremental cache, without changing anything. We load the (previously) invalid span from our incremental cache - it gets converted to a span with a dummy (but valid) location, along with the original `SyntaxContext`. This span gets written out to the crate metadata - since it now has a valid location, we preserve its `SyntaxContext`. 4. We recompile the second crate, again using a populated incremental cache. We now re-run the foreign query `optimized_mir` - the foreign crate hash is unchanged, but we end up decoding a different span (it now ha a non-root `SyntaxContext`). This results in the fingerprint changing, resulting in an ICE. This PR updates our encoding of spans in the crate metadata to mirror the encoding of spans into the incremental cache. We now always encode a `SyntaxContext`, and encode location information for spans with a non-dummy location.
2021-05-13Rollup merge of #85068 - luqmana:78708-xcrate-diag, r=estebankGuillaume Gomez-1/+12
Fix diagnostic for cross crate private tuple struct constructors Fixes #78708. There was already some limited support for certain cross-crate scenarios but that didn't handle a tuple struct rexported from an inner module for example (e.g. the NonZero* types as seen in #85049). ```Rust ➜ cat bug.rs fn main() { let _x = std::num::NonZeroU32(12); let n = std::num::NonZeroU32::new(1).unwrap(); match n { std::num::NonZeroU32(i) => {}, } } ``` **Before:** <details> ```Rust ➜ rustc +nightly bug.rs error[E0423]: expected function, tuple struct or tuple variant, found struct `std::num::NonZeroU32` --> bug.rs:2:14 | 2 | let _x = std::num::NonZeroU32(12); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `std::num::NonZeroU32 { 0: val }` | ::: /home/luqman/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/nonzero.rs:148:1 [snip] error[E0532]: expected tuple struct or tuple variant, found struct `std::num::NonZeroU32` --> bug.rs:5:9 | 5 | std::num::NonZeroU32(i) => {}, | ^^^^^^^^^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `std::num::NonZeroU32 { 0 }` | ::: /home/luqman/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/nonzero.rs:148:1 [snip] error: aborting due to 2 previous errors Some errors have detailed explanations: E0423, E0532. For more information about an error, try `rustc --explain E0423`. ``` </details> **After:** <details> ```Rust ➜ /rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc bug.rs error[E0423]: cannot initialize a tuple struct which contains private fields --> bug.rs:2:14 | 2 | let _x = std::num::NonZeroU32(12); | ^^^^^^^^^^^^^^^^^^^^ | note: constructor is not visible here due to private fields --> /rust/library/core/src/num/nonzero.rs:148:1 [snip] error[E0532]: cannot match against a tuple struct which contains private fields --> bug.rs:5:9 | 5 | std::num::NonZeroU32(i) => {}, | ^^^^^^^^^^^^^^^^^^^^ | note: constructor is not visible here due to private fields --> bug.rs:5:30 | 5 | std::num::NonZeroU32(i) => {}, | ^ private field error: aborting due to 2 previous errors Some errors have detailed explanations: E0423, E0532. For more information about an error, try `rustc --explain E0423`. ``` </details> One question is if we should only collect the needed info for the cross-crate case after encountering an error instead of always doing it. Perf run perhaps to gauge the impact.
2021-05-12Preserve `SyntaxContext` for invalid/dummy spans in crate metadataAaron Hill-3/+3
Fixes #85197 We already preserved the `SyntaxContext` for invalid/dummy spans in the incremental cache, but we weren't doing the same for crate metadata. If an invalid (lo/hi from different files) span is written to the incremental cache, we will decode it with a 'dummy' location, but keep the original `SyntaxContext`. Since the crate metadata encoder was only checking for `DUMMY_SP` (dummy location + root `SyntaxContext`), the metadata encoder would treat it as a normal span, encoding the `SyntaxContext`. As a result, the final span encoded to the metadata would change across sessions, even if the crate itself was unchanged. This PR updates our encoding of spans in the crate metadata to mirror the encoding of spans into the incremental cache. We now always encode a `SyntaxContext`, and encode location information for spans with a non-dummy location.
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-9/+32
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12Implement span quoting for proc-macrosAaron Hill-11/+27
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2021-05-08Fix diagnostic for matching/creating x-crate re-exported tuple structs with ↵Luqman Aden-1/+12
private fields. The more helpful diagnostic already existed but wasn't working if the struct in question was a re-export from a different crate.
2021-05-05Add -Z simulate-remapped-rust-src-base option to simulate path ↵Andy Wang-0/+25
virutalisation during bootstrapping
2021-05-05Make local_path in RealFileName::Remapped Option to be removed in exported ↵Andy Wang-1/+1
metadata
2021-05-05Rename RealFileName::Named to LocalPath and Devirtualized to RemappedAndy Wang-8/+6
2021-05-04Add type to differentiate between fake and real DefId'sJustus K-4/+0
2021-04-27Make `real_rust_path_dir` a TRACKED_NO_CRATE_HASH optionJoshua Nelson-3/+3
This also adds support for doc-comments to Options.
2021-04-16Implement #[rustc_skip_array_during_method_dispatch]Josh Stone-0/+2
2021-03-23Add query for const_param_defaultkadmin-0/+8