about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/decoder
AgeCommit message (Collapse)AuthorLines
2021-09-12Auto merge of #88759 - Amanieu:panic_in_drop, r=nagisa,eddybbors-0/+1
Add -Z panic-in-drop={unwind,abort} command-line option This PR changes `Drop` to abort if an unwinding panic attempts to escape it, making the process abort instead. This has several benefits: - The current behavior when unwinding out of `Drop` is very unintuitive and easy to miss: unwinding continues, but the remaining drops in scope are simply leaked. - A lot of unsafe code doesn't expect drops to unwind, which can lead to unsoundness: - https://github.com/servo/rust-smallvec/issues/14 - https://github.com/bluss/arrayvec/issues/3 - There is a code size and compilation time cost to this: LLVM needs to generate extra landing pads out of all calls in a drop implementation. This can compound when functions are inlined since unwinding will then continue on to process drops in the callee, which can itself unwind, etc. - Initial measurements show a 3% size reduction and up to 10% compilation time reduction on some crates (`syn`). One thing to note about `-Z panic-in-drop=abort` is that *all* crates must be built with this option for it to be sound since it makes the compiler assume that dropping `Box<dyn Any>` will never unwind. cc https://github.com/rust-lang/lang-team/issues/97
2021-09-12Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnrManish Goregaokar-1/+1
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-11Ensure that crates are linked with compatible panic-in-drop settingsAmanieu d'Antras-0/+1
2021-09-10rustc: Remove local variable IDs from `Export`sVadim Petrochenkov-23/+17
Local variables can never be exported.
2021-09-09rename mir -> thir around abstract constsEllen-1/+1
2021-07-17Encode ExpnId using ExpnHash for incr. comp.Camille GILLOT-18/+5
2021-07-17Make the CrateNum part of the ExpnId.Camille GILLOT-1/+18
2021-07-14Shrink the CrateStore dynamic interface.Camille GILLOT-17/+13
2021-07-13Auto merge of #86857 - fee1-dead:add-attr, r=oli-obkbors-0/+1
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-1/+1
This information is already available from `ExpnData`
2021-07-10Add impl_constness queryDeadbeef-0/+1
2021-07-06Revert "Revert "Merge CrateDisambiguator into StableCrateId""bjorn3-4/+3
This reverts commit 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.
2021-07-01Rename all_crate_nums query to crates and remove useless wrapperbjorn3-1/+1
2021-06-20Implement the query in cstore_impl.Camille GILLOT-5/+1
2021-06-10Auto merge of #85910 - cjgillot:no-meta-version, r=Aaron1011bors-5/+1
Drop metadata_encoding_version. Part of #85153 r? `@Aaron1011`
2021-06-07Revert "Merge CrateDisambiguator into StableCrateId"bjorn3-3/+4
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
2021-06-04Rollup merge of #85889 - denismerigoux:master, r=petrochenkovYuki Okushi-0/+7
Restoring the `num_def_ids` function in the CStore API ## The context I am the maintainer of https://github.com/hacspec/hacspec, an embedded Rust DSL aimed at cryptographic specifications. As it is normal for an embedded DSL, Hacspec's compiler relies on being plugged to the internal API of the Rust compiler, which is unstable and subject to changes. ## The problem The Hacspec compiler features its own typechecker, that performs an additional, more restrictive typechecking pass over the Rust code of a crate. To complete this typechecking, the Hacspec compiler needs to retrieve the signature of functions defined in non-local imported crates. Rather than retrieving these signatures on-demand, the Hacspec compiler pre-populates its typechecking context with all the Hacspec-compatible symbols defined in non-local crates first. This requires having a way to iterate over all the definitions in a non-local crate. I used to do this with `CrateMetadata::all_def_path_hashes_and_def_ids`, but this function was deleted in 908bf5a310b7265a3e. Then, I fellback on `CStore::num_def_ids`, exploiting the fact that all the `DefIds` for a crate have the same `krate_num` and range from `0` to `num_def_ids(krate_num)`. But `num_def_ids` was deleted in b6120bfb354c1c1c9fdf. I looked to the `Cstore::item_children_untracked` function to replicate the feature of traversing through all the `DefId` for a crate, using `CRATE_DEF_INDEX` as the root, but this does not work as recursive `Cstore::item_children_untracked` calls do not reach all the symbols I was able to reach using the two previous methods. ## Description of this PR This PR simply restores in the public API of `CStore` the `num_def_ids` function, giving the size of the definition table for a given crate.
2021-06-03Restore the num_def_ids_untracked public function giving the total number of ↵Denis Merigoux-0/+7
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-02Restrict access to crate_name.Camille GILLOT-2/+1
Also remove original_crate_name, which had the exact same implementation
2021-06-01Drop metadata_encoding_version.Camille GILLOT-5/+1
2021-06-01Make is_private_dep a query.Camille GILLOT-4/+5
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-3/+11
2021-05-30Drop metadata_encoding_version.Camille GILLOT-5/+1
2021-05-30Make is_private_dep a query.Camille GILLOT-4/+1
2021-05-30Restrict access to crate_name.Camille GILLOT-2/+1
Also remove original_crate_name, which had the exact same implementation
2021-05-30Merge CrateDisambiguator into StableCrateIdbjorn3-4/+3
2021-05-17Auto merge of #85178 - cjgillot:local-crate, r=oli-obkbors-23/+6
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-13Rollup merge of #85068 - luqmana:78708-xcrate-diag, r=estebankGuillaume Gomez-2/+16
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-12Use () for analysis.Camille GILLOT-3/+3
2021-05-12Use () for visible_parent_map.Camille GILLOT-3/+2
2021-05-12Use () for proc_macro_decls_static.Camille GILLOT-8/+0
2021-05-12Use () for plugin_registrar_fn.Camille GILLOT-5/+0
2021-05-12Use () in dependency_formats.Camille GILLOT-4/+1
2021-05-12Implement span quoting for proc-macrosAaron Hill-1/+10
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-2/+16
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-05Implement RFC 2951: Native link modifiersLuqman Aden-7/+4
This commit implements both the native linking modifiers infrastructure as well as an initial attempt at the individual modifiers from the RFC. It also introduces a feature flag for the general syntax along with individual feature flags for each modifier.
2021-05-04Add type to differentiate between fake and real DefId'sJustus K-4/+0
2021-04-03Remove attribute `#[link_args]`Vadim Petrochenkov-5/+0
2021-03-23Update with commentskadmin-1/+1
A bunch of nits fixed, and a new test for pretty printing the AST.
2021-03-23Add query for const_param_defaultkadmin-0/+1
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-0/+4
2021-01-23Iterate to encode def_kind.Camille GILLOT-1/+1
2021-01-15Auto merge of #80602 - tgnottingham:cratemetadata_you_aint_special, ↵bors-5/+8
r=michaelwoerister Remove DepKind::CrateMetadata and pre-allocation of DepNodes Remove much of the special-case handling around crate metadata dependency tracking by replacing `DepKind::CrateMetadata` and the pre-allocation of corresponding `DepNodes` with on-demand invocation of the `crate_hash` query.
2021-01-13Auto merge of #77524 - Patryk27:fixes/66228, r=estebankbors-0/+3
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924) This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-12Prevent potential bug resulting from changing crate_hash query nameTyson Nottingham-1/+2
2021-01-12Return to defining crate_hash similarly to other query providersTyson Nottingham-17/+5
2021-01-12Remove DepKind::CrateMetadata and pre-allocation of DepNodesTyson Nottingham-5/+19
Remove much of the special-case handling around crate metadata dependency tracking by replacing `DepKind::CrateMetadata` and the pre-allocation of corresponding `DepNodes` with on-demand invocation of the `crate_hash` query.
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-0/+3
2021-01-04Differentiate between the availability of ctfe MIR and runtime MIRoli-0/+1
2021-01-04Keep an unoptimized duplicate of `const fn` aroundoli-0/+1
This allows CTFE to reliably detect UB, as otherwise optimizations may hide UB.