about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/codec.rs
AgeCommit message (Collapse)AuthorLines
2023-12-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-0/+17
is immutable
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-1/+1
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-6/+8
2023-10-31Support enum variants in offset_of!George Bateman-1/+11
2023-10-20Uplift ClauseKind and PredicateKindMichael Goulet-2/+2
2023-10-03Optimize some `alloc_from_iter` call sites.Nicholas Nethercote-6/+8
There's no need to collect an iterator into a `Vec`, or to call `into_iter` at the call sites.
2023-09-23Enable drop_tracking_mir by default.Camille GILLOT-1/+0
2023-07-27Remove `constness` from `ParamEnv`Deadbeef-3/+1
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-4/+4
2023-07-04Replace `mk_const` with `Const::new_x` methodsBoxy-1/+1
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-14/+4
2023-06-22migrate inferred_outlives_of to ClauseMichael Goulet-10/+0
2023-06-22Expect clause moreMichael Goulet-1/+1
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-0/+21
2023-06-19s/Clause/ClauseKindMichael Goulet-1/+3
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-1/+1
2023-05-04Remove unneeded encode/decode methods.Nicholas Nethercote-5/+0
In #110927 the encode/decode methods for `i8`, `char`, `bool`, and `str` were made inherent. This commit removes some unnecessary implementations of these methods that were missed in that PR.
2023-05-04Reorder some `MemDecoder` methods.Nicholas Nethercote-6/+6
So they match the order in the `Decoder` trait.
2023-04-26Remove QueryEngine traitJohn Kåre Alsaker-1/+0
2023-04-26Auto merge of #110634 - saethlin:pointy-decoder, r=cjgillotbors-0/+10
Rewrite MemDecoder around pointers not a slice This is basically https://github.com/rust-lang/rust/pull/109910 but I'm being a lot more aggressive. The pointer-based structure means that it makes a lot more sense to absorb more complexity into `MemDecoder`, most of the diff is just complexity moving from one place to another. The primary argument for this structure is that we only incur a single bounds check when doing multi-byte reads from a `MemDecoder`. With the slice-based implementation we need to do those with `data[position..position + len]` , which needs to account for `position + len` wrapping. It would be possible to dodge the first bounds check if we stored a slice that starts at `position`, but that would require updating the pointer and length on every read. This PR also embeds the failure path in a separate function, which means that this PR should subsume all the perf wins observed in https://github.com/rust-lang/rust/pull/109867.
2023-04-23Rewrite MemDecoder around pointers not a sliceBen Kimock-0/+10
2023-04-21intern offsetof fieldsDrMeepster-0/+11
2023-04-06Remove f32 & f64 from MemDecoder/MemEncoderScott McMurray-2/+0
2023-02-24Add `mk_canonical_var_infos_from_iter`.Nicholas Nethercote-3/+3
It's missing, and is useful in two places.
2023-02-24Rename `mk_{ty,region}` as `mk_{ty,region}_from_kind`.Nicholas Nethercote-2/+2
To discourage accidental use -- there are more specific `mk_*` functions for all `Ty` and `Region` kinds.
2023-02-24Rename many interner functions.Nicholas Nethercote-14/+16
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-01-27Impl HashStable/Encodable/Decodable for ObligationCause.Camille GILLOT-2/+31
2022-12-16Rename ConstS to ConstDataOli Scherer-1/+1
2022-11-29Make inferred_outlives_crate return ClauseSantiago Pastorino-0/+8
2022-11-25Add empty ConstKind::Abstractkadmin-19/+8
Initial pass at expr/abstract const/s Address comments Switch to using a list instead of &[ty::Const], rm `AbstractConst` Remove try_unify_abstract_consts Update comments Add edits Recurse more More edits Prevent equating associated consts Move failing test to ui Changes this test from incremental to ui, and mark it as failing and a known bug. Does not cause the compiler to ICE, so should be ok.
2022-11-19drive-by: PolyExistentialPredicateMichael Goulet-2/+2
2022-11-04Refactor tcx mk_const parameters.Mateusz-1/+2
2022-10-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-0/+1
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-07-20add a Vtable kind of symbolic allocationsRalf Jung-0/+1
2022-07-12Move abstract const to rustc_middle::tykadmin-3/+2
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-26/+21
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-05-28Make TyCtxt implement Interner, make HashStable generic and move to ↵Michael Goulet-67/+62
rustc_type_ir
2022-05-28Initial fixes on top of type interner commitMichael Goulet-30/+24
2022-05-28Move things to rustc_type_irWilco Kusee-93/+93
2022-05-13Cache more queries on disk.Camille GILLOT-19/+27
2022-04-18Remove unused macro rulesest31-3/+0
2022-03-11Improve `AdtDef` interning.Nicholas Nethercote-5/+15
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
2022-03-07Introduce `ConstAllocation`.Nicholas Nethercote-4/+9
Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems.
2022-02-22Delete Decoder::read_unitMark Rousskov-2/+0
2022-02-22Provide copy-free access to raw Decoder bytesMark Rousskov-3/+3
2022-02-15Overhaul `Const`.Nicholas Nethercote-2/+8
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Overhaul `RegionKind` and `Region`.Nicholas Nethercote-1/+6
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better.
2022-02-09Ensure that queries only return Copy types.Camille GILLOT-0/+3
2022-01-22Address review comments.Nicholas Nethercote-1/+1
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-96/+84
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.