summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/consts
AgeCommit message (Collapse)AuthorLines
2022-07-26Allow try_to_raw_bytes on u8 arrayMichael Goulet-20/+14
2022-07-20clippy::perf fixesMatthias Krüger-6/+4
2022-07-09don't allow ZST in ScalarIntRalf Jung-26/+20
There are several indications that we should not ZST as a ScalarInt: - We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it. `ValTree::zst()` used the former, but the latter could possibly arise as well. - Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`. - LLVM codegen already had to special-case ZST ScalarInt. So instead add new ZST variants to those types that did not have other variants which could be used for this purpose.
2022-07-06Update TypeVisitor pathsAlan Egerton-1/+1
2022-07-02add AllocRange Debug impl; remove redundant AllocId Display implRalf Jung-0/+4
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-13/+129
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-3/+3
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-04-21implement valtree -> constvalue conversionb-naber-0/+3
2022-04-21add helper methods on ValTreeb-naber-0/+16
2022-04-21add some helper methods to ScalarIntb-naber-0/+92
2022-04-16Rollup merge of #95426 - b-naber:valtrees-slice, r=RalfJung,oli-obkDylan DPC-1/+1
Include Refs in Valtree Creation This adds references to `const_to_valtree`, which isn't used in the compiler yet, but after the previous changes we made to the thir and mir representations and this change we should be able to finally introduce them in the next PR. I wasn't able to properly test this code, except indirectly by including a call of `const_to_valtree` in the code that currently creates constants (`turn_into_const_value`). r? `@lcnr` cc `@oli-obk` `@RalfJung`
2022-04-08create leafs for slicesb-naber-28/+0
2022-04-02rebase and use ty::Const in patterns againb-naber-5/+1
2022-04-02do use ty::Const in patterns and abstract constsb-naber-1/+6
2022-04-02change thir to use mir::ConstantKind instead of ty::Constb-naber-1/+1
2022-03-29Add type for slices in ValTreesb-naber-1/+29
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-20Rollup merge of #94091 - GuillaumeGomez:rustdoc-const-computed-value, r=oli-obkMatthias Krüger-0/+7
Fix rustdoc const computed value Fixes #85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? ````@oli-obk````
2022-02-19Don't render Const computed values in hexadecimal for DisplayGuillaume Gomez-0/+7
2022-02-17Fix ScalarInt to char conversionTomasz Miąsko-4/+14
to avoid panic for invalid Unicode scalar values
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-2/+2
`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.
2022-01-15nyahggdshjjghsdfhgsfEllen-0/+3
2022-01-15attempt to re-add `ty::Unevaluated` visitor and friendsEllen-13/+35
2022-01-15initial revertEllen-59/+14
2021-12-15Remove `in_band_lifetimes` from `rustc_middle`Aaron Hill-2/+2
See #91867 This was mostly straightforward. In several places, I take advantage of the fact that lifetimes are non-hygenic: a macro declares the 'tcx' lifetime, which is then used in types passed in as macro arguments.
2021-08-26inline stufflcnr-0/+4
2021-08-26shrink `ty::PredicateKind` againlcnr-5/+24
2021-08-26use `ty::Unevaluated` instead of def substs pairlcnr-1/+1
2021-08-26update `TypeFlags` to deal with missing ct substslcnr-0/+6
2021-08-26make unevaluated const substs optionallcnr-11/+27
2021-07-15adjustions and cleanup to make Miri build againRalf Jung-10/+1
2021-07-14CTFE/Miri engine Pointer type overhaul: make Scalar-to-Pointer conversion ↵Ralf Jung-3/+2
infallible This resolves all the problems we had around "normalizing" the representation of a Scalar in case it carries a Pointer value: we can just use Pointer if we want to have a value taht we are sure is already normalized.
2021-03-20update `const_eval_resolve`lcnr-1/+2
2021-03-20extract `ConstKind::Unevaluated` into a structlcnr-4/+12
2021-03-16Update compiler/rustc_middle/src/ty/consts/valtree.rsOli Scherer-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-03-16Update compiler/rustc_middle/src/ty/consts/valtree.rsOli Scherer-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-03-15Pacify tidyOli Scherer-1/+1
2021-03-15Do not expose fallible `to_int` operation on `Scalar`.Oli Scherer-1/+1
Any use of it has been shown to be a bug in the past.
2021-03-15Document valtreeOli Scherer-0/+18
2021-03-12Add convenience conversion methods for ScalarIntOli Scherer-2/+30
2021-03-12Intern valtree field vectorOli Scherer-5/+5
2021-03-12Implement valtreeOli Scherer-0/+15
valtree is a version of constants that is inherently safe to be used within types. This is in contrast to ty::Const which can have different representations of the same value. These representation differences can show up in hashing or equality comparisons, breaking type equality of otherwise equal types. valtrees do not have this problem.
2021-03-06Change x64 size checks to not apply to x32.Harald van Dijk-1/+1
Rust contains various size checks conditional on target_arch = "x86_64", but these checks were never intended to apply to x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the conditions.
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-1/+1
2020-11-16compiler: fold by valueBastian Kauschke-2/+2
2020-11-13Rollup merge of #78463 - varkor:placeholder-const, r=nikomatsakisGuillaume Gomez-1/+1
Add type to `ConstKind::Placeholder` I simply threaded `<'tcx>` through everything that required it. I'm not sure whether this is the correct thing to do, but it seems to work. r? `@nikomatsakis`
2020-11-12Add type to `ConstKind::Placeholder`varkor-1/+1
2020-11-09comment attribution fixo752d-1/+1
comment means to refer to the macro in its direct scope
2020-11-04Make `ScalarInt` entirely independent of MIR interpretationoli-4/+3
2020-11-04Document an `unwrap`oli-1/+4