about summary refs log tree commit diff
path: root/compiler/rustc_query_system
AgeCommit message (Collapse)AuthorLines
2022-06-10Revert dc08bc51f2c58a0f5f815a07f9bb3d671153b5a1.Nicholas Nethercote-1/+1
2022-06-10Revert b983e42936feab29f6333e9835913afc6b4a394e.Nicholas Nethercote-3/+3
2022-06-08Rename `rustc_serialize::opaque::Encoder` as `MemEncoder`.Nicholas Nethercote-3/+3
This avoids the name clash with `rustc_serialize::Encoder` (a trait), and allows lots qualifiers to be removed and imports to be simplified (e.g. fewer `as` imports).
2022-06-08Move `finish` out of the `Encoder` trait.Nicholas Nethercote-1/+1
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-15/+12
There are two impls of the `Encoder` trait: `opaque::Encoder` and `opaque::FileEncoder`. The former encodes into memory and is infallible, the latter writes to file and is fallible. Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a bit verbose and has non-trivial cost, which is annoying given how rare failures are (especially in the infallible `opaque::Encoder` case). This commit changes how `Encoder` fallibility is handled. All the `emit_*` methods are now infallible. `opaque::Encoder` requires no great changes for this. `opaque::FileEncoder` now implements a delayed error handling strategy. If a failure occurs, it records this via the `res` field, and all subsequent encoding operations are skipped if `res` indicates an error has occurred. Once encoding is complete, the new `finish` method is called, which returns a `Result`. In other words, there is now a single `Result`-producing method instead of many of them. This has very little effect on how any file errors are reported if `opaque::FileEncoder` has any failures. Much of this commit is boring mechanical changes, removing `Result` return values and `?` or `unwrap` from expressions. The more interesting parts are as follows. - serialize.rs: The `Encoder` trait gains an `Ok` associated type. The `into_inner` method is changed into `finish`, which returns `Result<Vec<u8>, !>`. - opaque.rs: The `FileEncoder` adopts the delayed error handling strategy. Its `Ok` type is a `usize`, returning the number of bytes written, replacing previous uses of `FileEncoder::position`. - Various methods that take an encoder now consume it, rather than being passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-06Make saved_file field of WorkProduct non-optionalbjorn3-1/+1
A WorkProduct without a saved file is useless
2022-06-06Remove unnecessary cgu name length hashbjorn3-1/+0
This is a tiny optimization
2022-06-02Address review comments.Nicholas Nethercote-14/+11
2022-06-01Lazify `SourceFile::lines`.Nicholas Nethercote-5/+12
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form (a difference list) to save disk space. Decoding it is a big fraction of compile time for very small crates/programs. This commit introduces a new type `SourceFileLines` which has a `Lines` form and a `Diffs` form. The latter is used when the metadata is first read, and it is only decoded into the `Lines` form when line data is actually needed. This avoids the decoding cost for many files, especially in `std`. It's a performance win of up to 15% for tiny crates/programs where metadata decoding is a high part of compilation costs. A `Lock` is needed because the methods that access lines data (which can trigger decoding) take `&self` rather than `&mut self`. To allow for this, `SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather than returning the lines slice.
2022-05-29Auto merge of #97287 - compiler-errors:type-interner, r=jackh726,oli-obkbors-0/+1
Move things to `rustc_type_ir` Finishes some work proposed in https://github.com/rust-lang/compiler-team/issues/341. r? `@ghost`
2022-05-28Make TyCtxt implement Interner, make HashStable generic and move to ↵Michael Goulet-122/+0
rustc_type_ir
2022-05-28Move things to rustc_type_irWilco Kusee-0/+123
2022-05-27Update to rebased rustc-rayon 0.4Josh Stone-1/+1
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-3/+3
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-05Rollup merge of #96697 - oli-obk:trace_queries, r=michaelwoeristerYuki Okushi-1/+1
Enable tracing for all queries This allows you to log everything within a specific query, e.g. ``` env RUSTC_LOG=[mir_borrowck] ``` dumping all borrowck queries may be a bit verbose, so you can also restrict it to just an item of your choice: ``` env RUSTC_LOG=[mir_borrowck{key=\.\*name_of_item\.\*}] ``` the regex `.*` in the key name are because the key is a debug printed DefId, so you'd get all kinds of things like hashes in there. The tracing logs will show you the key, so you can restrict it further if you want.
2022-05-04Enable tracing for all queryiesOli Scherer-1/+1
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-05-02fix most compiler/ doctestsElliot Roberts-3/+3
2022-04-12Remove NodeIdHashingMode.Camille GILLOT-107/+8
2022-04-09Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercotebors-0/+8
Cached stable hash cleanups r? `@nnethercote` Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time. Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures
2022-04-05errors: implement fallback diagnostic translationDavid Wood-2/+2
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-03-31Move stable hash from TyS into a datastructure that can be shared with other ↵Oli Scherer-0/+8
interned types.
2022-03-30Spellchecking compiler commentsYuri Astrakhan-1/+1
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakisbors-2/+0
Lazy type-alias-impl-trait take two ### user visible change 1: RPIT inference from recursive call sites Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned. ```rust fn bar(b: bool) -> impl std::fmt::Debug { if b { return 42 } let x: u32 = bar(false); // this errors on stable 99 } ``` The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type. ### user visible change 2: divergence between RPIT and TAIT in return statements Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So ```rust #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![42]; } std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![42] } std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended) } ``` But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same: ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![]; } let mut x = foo(false); x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator vec![] } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![]; } let mut x = bar(false); x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator vec![] } ``` ### user visible change 3: TAIT does not merge types across branches In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile. ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { vec![42_i32] } else { std::iter::empty().collect() //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } ``` It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this). ### PR formalities previous attempt: #92007 This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893 fixes #93411 fixes #88236 fixes #89312 fixes #87340 fixes #86800 fixes #86719 fixes #84073 fixes #83919 fixes #82139 fixes #77987 fixes #74282 fixes #67830 fixes #62742 fixes #54895
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-2/+0
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-28Propagate `parallel_compiler` feature through rustc crates. Turned off ↵klensy-1/+4
feature gives change of builded crates: 238 -> 224.
2022-03-20Take &mut Diagnostic in emit_diagnostic.Camille GILLOT-2/+2
Taking a Diagnostic by move would break the usual pattern `diag.label(..).emit()`.
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-6/+8
2022-02-27Auto merge of #94084 - Mark-Simulacrum:drop-sharded, r=cjgillotbors-184/+149
Avoid query cache sharding code in single-threaded mode In non-parallel compilers, this is just adding needless overhead at compilation time (since there is only one shard statically anyway). This amounts to roughly ~10 seconds reduction in bootstrap time, with overall neutral (some wins, some losses) performance results. Parallel compiler performance should be largely unaffected by this PR; sharding is kept there.
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-6/+6
2022-02-22Auto merge of #93839 - Mark-Simulacrum:delete-json-rust-deserialization, ↵bors-23/+18
r=nnethercote Simplify rustc_serialize by dropping support for decoding into JSON This PR currently bundles two (somewhat separate) tasks. First, it removes the JSON Decoder trait impl, which permitted going from JSON to Rust structs. For now, we keep supporting JSON deserialization, but only to `Json` (an equivalent of serde_json::Value). The primary hard to remove user there is for custom targets -- which need some form of JSON deserialization -- but they already have a custom ad-hoc pass for moving from Json to a Rust struct. A [comment](https://github.com/rust-lang/rust/blob/e7aca895980f25f6d2d3c48e10fd04656764d1e4/compiler/rustc_target/src/spec/mod.rs#L1653) there suggests that it would be impractical to move them to a Decodable-based impl, at least without backwards compatibility concerns. I suspect that if we were widely breaking compat there, it would make sense to use serde_json at this point which would produce better error messages; the types in rustc_target are relatively isolated so we would not particularly suffer from using serde_derive. The second part of the PR (all but the first commit) is to simplify the Decoder API by removing the non-primitive `read_*` functions. These primarily add indirection (through a closure), which doesn't directly cause a performance issue (the unique closure types essentially guarantee monomorphization), but does increase the amount of work rustc and LLVM need to do. This could be split out to a separate PR, but is included here in part to help motivate the first part. Future work might consist of: * Specializing enum discriminant encoding to avoid leb128 for small enums (since we know the variant count, we can directly use read/write u8 in almost all cases) * Adding new methods to support faster deserialization (e.g., access to the underlying byte stream) * Currently these are somewhat ad-hoc supported by specializations for e.g. `Vec<u8>`, but other types which could benefit don't today. * Removing the Decoder trait entirely in favor of a concrete type -- today, we only really have one impl of it modulo wrappers used for specialization-based dispatch. Highly recommend review with whitespace changes off, as the removal of closures frequently causes things to be de-indented.
2022-02-20Delete Decoder::read_seqMark Rousskov-10/+10
2022-02-20Delete Decoder::read_seq_eltMark Rousskov-1/+1
2022-02-20Delete Decoder::read_struct_fieldMark Rousskov-13/+11
2022-02-20Delete Decoder::read_structMark Rousskov-22/+19
2022-02-20Refactor Sharded out of non-parallel active query mapMark Rousskov-27/+51
2022-02-20Avoid sharding query caches entirely in single-threaded modeMark Rousskov-20/+59
2022-02-20Inline QueryStateShard into QueryStateMark Rousskov-17/+7
2022-02-20Delete QueryLookupMark Rousskov-34/+15
This was largely just caching the shard value at this point, which is not particularly useful -- in the use sites the key was being hashed nearby anyway.
2022-02-20Move Sharded maps into each QueryCache implMark Rousskov-113/+44
2022-02-17Remove SimpleDefKindMark Rousskov-36/+10
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-0/+2
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-09Auto merge of #93741 - Mark-Simulacrum:global-job-id, r=cjgillotbors-163/+91
Refactor query system to maintain a global job id counter This replaces the per-shard counters with a single global counter, simplifying the JobId struct down to just a u64 and removing the need to pipe a DepKind generic through a bunch of code. The performance implications on non-parallel compilers are likely minimal (this switches to `Cell<u64>` as the backing storage over a `u64`, but the latter was already inside a `RefCell` so it's not really a significance divergence). On parallel compilers, the cost of a single global u64 counter may be more significant: it adds a serialization point in theory. On the other hand, we can imagine changing the counter to have a thread-local component if it becomes worrisome or some similar structure. The new design is sufficiently simpler that it warrants the potential for slight changes down the line if/when we get parallel compilation to be more of a default. A u64 counter, instead of u32 (the old per-shard width), is chosen to avoid possibly overflowing it and causing problems; it is effectively impossible that we would overflow a u64 counter in this context.
2022-02-08Switch QueryJobId to a single global counterMark Rousskov-163/+91
This replaces the per-shard counters with a single global counter, simplifying the JobId struct down to just a u64 and removing the need to pipe a DepKind generic through a bunch of code. The performance implications on non-parallel compilers are likely minimal (this switches to `Cell<u64>` as the backing storage over a `u64`, but the latter was already inside a `RefCell` so it's not really a significance divergence). On parallel compilers, the cost of a single global u64 counter may be more significant: it adds a serialization point in theory. On the other hand, we can imagine changing the counter to have a thread-local component if it becomes worrisome or some similar structure. The new design is sufficiently simpler that it warrants the potential for slight changes down the line if/when we get parallel compilation to be more of a default. A u64 counter, instead of u32 (the old per-shard width), is chosen to avoid possibly overflowing it and causing problems; it is effectively impossible that we would overflow a u64 counter in this context.
2022-02-07Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakisbors-2/+0
Lazy type-alias-impl-trait Previously opaque types were processed by 1. replacing all mentions of them with inference variables 2. memorizing these inference variables in a side-table 3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing. This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around. Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing * https://github.com/rust-lang/rfcs/pull/2515 much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities). r? `@nikomatsakis` fixes #93411 fixes #88236
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-2/+0
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-02Use Option::then in two placesest31-1/+1
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-01-22Address review comments.Nicholas Nethercote-1/+0