about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
AgeCommit message (Collapse)AuthorLines
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-38/+20
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-12Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelixbors-33/+105
Make CTFE able to check for UB... ... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions. This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-11Serialize incr comp structures to file via fixed-size bufferTyson Nottingham-1/+1
Reduce a large memory spike that happens during serialization by writing the incr comp structures to file by way of a fixed-size buffer, rather than an unbounded vector. Effort was made to keep the instruction count close to that of the previous implementation. However, buffered writing to a file inherently has more overhead than writing to a vector, because each write may result in a handleable error. To reduce this overhead, arrangements are made so that each LEB128-encoded integer can be written to the buffer with only one capacity and error check. Higher-level optimizations in which entire composite structures can be written with one capacity and error check are possible, but would require much more work. The performance is mostly on par with the previous implementation, with small to moderate instruction count regressions. The memory reduction is significant, however, so it seems like a worth-while trade-off.
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-5/+12
2021-01-05Rollup merge of #80643 - LingMan:unwrap, r=oli-obkYuki Okushi-8/+7
Move variable into the only branch where it is relevant At the `if` branch `filter` (the `let` binding) is `None` iff `filter` (the parameter) was `None`. We can branch on the parameter, move the binding into the `if`, and the complexity of handling `Option<Option<_>` largely dissolves. `@rustbot` modify labels +C-cleanup +T-compiler Note: I have no idea how hot this code is. If this method frequently gets called with a `None` filter, there might be a small perf improvement.
2021-01-04Differentiate between the availability of ctfe MIR and runtime MIRoli-1/+5
2021-01-04Keep an unoptimized duplicate of `const fn` aroundoli-18/+83
This allows CTFE to reliably detect UB, as otherwise optimizations may hide UB.
2021-01-04Require the `encode_promoted_mir` caller to know whether MIR for this item ↵oli-3/+1
actually exists
2021-01-04Limit trait item mir encoding to items with default bodiesoli-2/+9
2021-01-04Remove mir encode calls that didn't actually encode anythingoli-2/+0
2021-01-04Make `encode_optimized_mir` always perform its action and instead require ↵oli-11/+11
the callers to know whether they actually want this
2021-01-04Auto merge of #80610 - Aaron1011:unhash-def-path-hash, r=varkorbors-2/+3
Use `UnhashMap` whenever we have a key of `DefPathHash`
2021-01-03Rollup merge of #80646 - bugadani:meta, r=petrochenkovGuillaume Gomez-17/+12
Clean up in `each_child_of_item` This PR hopes to eliminate some of the surprising elements I encountered while reading the function. - `macros_only` is checked against inside the loop body, but if it is `true`, the loop is skipped anyway - only query `span` when relevant - no need to allocate attribute vector
2021-01-03Rollup merge of #80628 - matthiaskrgr:match_ref_pats, r=varkorGuillaume Gomez-4/+4
reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats)
2021-01-03Move variable into condition where it's usedDániel Buga-1/+1
2021-01-03No need to collect result of get_item_attrsDániel Buga-3/+2
2021-01-03Clean up convoluted macros_only logicDániel Buga-13/+9
2021-01-03Auto merge of #80247 - tmiasko:indent, r=bjorn3bors-1/+1
Fix indentation of -Z meta-stats output
2021-01-03Move variable into the only branch where it is relevantLingMan-8/+7
At the `if` branch `filter` (the `let` binding) is `None` iff `filter` (the parameter) was `None`. We can branch on the parameter, move the binding into the `if`, and the complexity of handling `Option<Option<_>` largely dissolves.
2021-01-02reduce borrowing and (de)referencing around match patterns ↵Matthias Krüger-4/+4
(clippy::match_ref_pats)
2021-01-01Use `UnhashMap` whenever we have a key of `DefPathHash`Aaron Hill-2/+3
2021-01-01adjust const generics defaults FIXMEs to the new feature gateRémy Rakic-1/+1
2020-12-30Rename kw::Invalid -> kw::EmptyJoshua Nelson-1/+1
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context.
2020-12-20Fix indentation of -Z meta-stats outputTomasz Miąsko-1/+1
2020-12-17Rollup merge of #80039 - LeSeulArtichaut:rm-tyencoder-tcx, r=matthewjasperYuki Okushi-4/+0
Remove unused `TyEncoder::tcx` required method Unsure if this is helpful or not... r? ``@ghost`` cc ``@matthewjasper`` ``@jackh726``
2020-12-14Convenience funcs for `some_option.unwrap_or(...)`Rich Kadel-6/+1
This ensures consistent handling of default values for options that are None if not specified on the command line.
2020-12-14Remove unused `TyEncoder::tcx` required methodLeSeulArtichaut-4/+0
2020-12-14Improve warnings on incompatible options involving -Zinstrument-coverageRich Kadel-3/+15
Adds checks for: * `no_core` attribute * explicitly-enabled `legacy` symbol mangling * mir_opt_level > 1 (which enables inlining) I removed code from the `Inline` MIR pass that forcibly disabled inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level` does not enable inlining anyway. But if the level is explicitly set and is greater than 1, I issue a warning. The new warnings show up in tests, which is much better for diagnosing potential option conflicts in these cases.
2020-12-08Account for gaps in def path table during decodingAaron Hill-3/+8
When encoding a proc-macro crate, there may be gaps in the table (since we only encode the crate root and proc-macro items). Account for this by checking if the entry is present, rather than using `unwrap()`
2020-12-03rustc_metadata: Remove some dead codeVadim Petrochenkov-25/+4
2020-12-01Auto merge of #74967 - Aaron1011:feature/incr-def-path-table, r=pnkfelixbors-0/+62
Implement lazy decoding of DefPathTable during incremental compilation PR https://github.com/rust-lang/rust/pull/75813 implemented lazy decoding of the `DefPathTable` from crate metadata. However, it requires decoding the entire `DefPathTable` when incremental compilation is active, so that we can map a decoded `DefPathHash` to a `DefId` from an arbitrary crate. This PR adds support for lazy decoding of dependency `DefPathTable`s when incremental compilation si active. When we load the incremental cache and dep graph, we need the ability to map a `DefPathHash` to a `DefId` in the current compilation session (if the corresponding definition still exists). This is accomplished by storing the old `DefId` (that is, the `DefId` from the previous compilation session) for each `DefPathHash` we need to remap. Since a `DefPathHash` includes the owning crate, the old crate is guaranteed to be the right one (if the definition still exists). We then use the old `DefIndex` as an initial guess, which we validate by comparing the expected and actual `DefPathHash`es. In most cases, foreign crates will be completely unchanged, which means that we our guess will be correct. If our guess is wrong, we fall back to decoding the entire `DefPathTable` for the foreign crate. This still represents an improvement over the status quo, since we can skip decoding the entire `DefPathTable` for other crates (where all of our guesses were correct).
2020-11-27Encode proc_macro directly.Camille GILLOT-67/+62
Encode proc_macro name directly. Do not store None values.
2020-11-26Formatting.Camille GILLOT-1/+1
2020-11-26Remove ForeignMod struct.Camille GILLOT-17/+14
2020-11-26Store ForeignItem in a side table.Camille GILLOT-3/+16
2020-11-25Lazy DefPath decoding for incremental compilationAaron Hill-0/+62
2020-11-22Stabilise `then`varkor-1/+0
2020-11-18Improve error message when we try to get_type on something that does not ↵Hannah McLaughlin-1/+6
have a type
2020-11-13Push to result vector instead of allocatingDániel Buga-1/+1
Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-11-13Eliminate some temporary vectors & Remove unnecessary mark_attr_usedDániel Buga-13/+14
2020-11-10Changed unwrap_or to unwrap_or_else in some places.Nicholas-Baron-8/+8
The discussion seems to have resolved that this lint is a bit "noisy" in that applying it in all places would result in a reduction in readability. A few of the trivial functions (like `Path::new`) are fine to leave outside of closures. The general rule seems to be that anything that is obviously an allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it is a 0-sized allocation.
2020-11-08Collapse all uses of `target.options.foo` into `target.foo`Vadim Petrochenkov-15/+11
with an eye on merging `TargetOptions` into `Target`. `TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-03Auto merge of #78448 - rylev:cache-foreign_modules, r=wesleywiserbors-8/+13
foreign_modules query hash table lookups When compiling a large monolithic crate we're seeing huge times in the `foreign_modules` query due to repeated iteration over foreign modules (in order to find a module by its id). This implements hash table lookups so that which massively reduces time spent in that query in this particular case. We'll need to see if the overhead of creating the hash table has a negative impact on performance in more normal compilation scenarios. I'm working with `@wesleywiser` on this.
2020-10-30Fix some more clippy warningsJoshua Nelson-16/+10
2020-10-29Avoid BorrowMutError with RUSTC_LOG=debugTomasz Miąsko-3/+6
$ touch empty.rs $ env RUSTC_LOG=debug rustc +stage1 --crate-type=lib empty.rs Fails with a `BorrowMutError` because source map files are already borrowed while `features_query` attempts to format a log message containing a span. Release the borrow before the query to avoid the issue.
2020-10-27Remove some cruft from foreign_modules refactorRyan Levick-3/+4
2020-10-27Cache foreign_modules queryRyan Levick-11/+15
2020-10-24Compute proper module parent during resolutionAaron Hill-0/+5
Fixes #75982 The direct parent of a module may not be a module (e.g. `const _: () = { #[path = "foo.rs"] mod foo; };`). To find the parent of a module for purposes of resolution, we need to walk up the tree until we hit a module or a crate root.
2020-10-19Calculate visibilities once in resolveVadim Petrochenkov-56/+13
Then use them through a query based on resolver outputs