summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-3/+3
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-12-14Rollup merge of #118935 - RalfJung:interpret-downcast, r=saethlinMatthias Krüger-0/+18
interpret: extend comment on the inhabitedness check in downcast Cc https://github.com/rust-lang/rust/issues/115145 r? ``@saethlin``
2023-12-14interpret: extend comment on the inhabitedness check in downcastRalf Jung-0/+18
2023-12-13fix computing the dynamic alignment of packed structs with dyn trait tailsRalf Jung-25/+18
2023-12-13Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkovbors-1/+1
Move some methods from `tcx.hir()` to `tcx` https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834 Renamed: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id
2023-12-13Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkinbors-4/+7
codegen: panic when trying to compute size/align of extern type The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case. Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-12clippy::complexity fixesMatthias Krüger-1/+1
filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-1/+1
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-12reject projecting to fields whose offset we cannot computeRalf Jung-4/+7
2023-12-11Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrumbors-0/+2
guarantee that char and u32 are ABI-compatible In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent. This is a new stable guarantee, so it will need t-lang approval.
2023-12-07Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlinbors-73/+88
compile-time evaluation: detect writes through immutable pointers This has two motivations: - it unblocks https://github.com/rust-lang/rust/pull/116745 (and therefore takes a big step towards `const_mut_refs` stabilization), because we can now detect if the memory that we find in `const` can be interned as "immutable" - it would detect the UB that was uncovered in https://github.com/rust-lang/rust/pull/117905, which was caused by accidental stabilization of `copy` functions in `const` that can only be called with UB When UB is detected, we emit a future-compat warn-by-default lint. This is not a breaking change, so completely in line with [the const-UB RFC](https://rust-lang.github.io/rfcs/3016-const-ub.html), meaning we don't need t-lang FCP here. I made the lint immediately show up for dependencies since it is nearly impossible to even trigger this lint without `const_mut_refs` -- the accidentally stabilized `copy` functions are the only way this can happen, so the crates that popped up in #117905 are the only causes of such UB (in the code that crater covers), and the three cases of UB that we know about have all been fixed in their respective crates already. The way this is implemented is by making use of the fact that our interpreter is already generic over the notion of provenance. For CTFE we now use the new `CtfeProvenance` type which is conceptually an `AllocId` plus a boolean `immutable` flag (but packed for a more efficient representation). This means we can mark a pointer as immutable when it is created as a shared reference. The flag will be propagated to all pointers derived from this one. We can then check the immutable flag on each write to reject writes through immutable pointers. I just hope perf works out.
2023-12-07avoid marking as immutable what is already immutableRalf Jung-5/+12
this has been demonstrated to help performance
2023-12-07compile-time evaluation: emit a lint when a write through an immutable ↵Ralf Jung-14/+15
pointer occurs
2023-12-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-56/+63
is immutable
2023-12-04Rollup merge of #118565 - RalfJung:numeric_intrinsic, r=davidtwcoGuillaume Gomez-46/+36
interpret: make numeric_intrinsic accessible from Miri This will let us share the code of the cttz and simd_cttz intrinsics (and same for ctlz).
2023-12-04Rollup merge of #118573 - petrochenkov:pathdatakind, r=TaKO8KiTakayuki Maeda-4/+2
rustc: Harmonize `DefKind` and `DefPathData` Follow up to https://github.com/rust-lang/rust/pull/118188. `DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-04Rollup merge of #118540 - RalfJung:unsized-packed-offset, r=TaKO8KiTakayuki Maeda-1/+11
codegen, miri: fix computing the offset of an unsized field in a packed struct `#[repr(packed)]` strikes again. Fixes https://github.com/rust-lang/rust/issues/118537 Fixes https://github.com/rust-lang/miri/issues/3200 `@bjorn3` I assume cranelift needs the same fix.
2023-12-03miri: support 'promising' alignment for symbolic alignment checkRalf Jung-16/+22
2023-12-03rustc: Harmonize `DefKind` and `DefPathData`Vadim Petrochenkov-4/+2
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-03interpret: make numeric_intrinsic accessible from MiriRalf Jung-46/+36
2023-12-03codegen, miri: fix computing the offset of an unsized field in a packed structRalf Jung-1/+11
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-10/+10
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Use `Session::diagnostic` in more places.Nicholas Nethercote-1/+1
2023-12-02Rename `Handler::delay_good_path_bug` as `Handler::good_path_delayed_bug`.Nicholas Nethercote-5/+5
In line with the previous commits.
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-4/+4
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-01Auto merge of #118482 - RalfJung:interpret-local-type, r=WaffleLapkinbors-0/+3
explain a good reason for why LocalValue does not store the type of the local As found out by `@lcnr` in https://github.com/rust-lang/rust/pull/112307, storing the type here can lead to subtle bugs when it gets out of sync with the MIR body. That's not the reason why the interpreter does it this way I think, but good thing we dodged that bullet. :)
2023-11-30explain a good reason for why LocalValue does not store the type of the localRalf Jung-0/+3
2023-11-28move write_aggregate into step file, and also extract write_repeat into ↵Ralf Jung-60/+72
separate function
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-1/+1
cleanup
2023-11-23remove unused pub fnklensy-2/+2
2023-11-23Auto merge of #118073 - saethlin:gc-dead-allocs, r=RalfJungbors-0/+11
Miri: GC the dead_alloc_map too dead_alloc_map is the last piece of state in the interpreter I can find that leaks. With this PR, all of the long-term memory growth I can find in Miri with programs that do things like run a big `loop {` or run property tests is attributable to some data structure properties in borrow tracking, and is _extremely_ slow. My only gripe with the commit in this PR is that I don't have a new test for it. I'd like to have a regression test for this, but it would have to be statistical I think because the peak memory of a process that Linux reports is not exactly the same run-to-run. Which means it would have to not be very sensitive to slow leaks (some guesswork suggests for acceptable CI time we would be checking for like 10% memory growth over a minute or two, which is still pretty fast IMO). Unless someone has a better idea for how to detect a regression, I think on balance I'm fine with manually keeping an eye on the memory use situation. r? RalfJung
2023-11-22Miri: GC the dead_alloc_map tooBen Kimock-0/+11
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-13/+13
`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-11-21Rollup merge of #118029 - saethlin:allocid-gc, r=RalfJungNilstrieb-0/+17
Expand Miri's BorTag GC to a Provenance GC As suggested in https://github.com/rust-lang/miri/issues/3080#issuecomment-1732505573 We previously solved memory growth issues associated with the Stacked Borrows and Tree Borrows runtimes with a GC. But of course we also have state accumulation associated with whole allocations elsewhere in the interpreter, and this PR starts tackling those. To do this, we expand the visitor for the GC so that it can visit a BorTag or an AllocId. Instead of collecting all live AllocIds into a single HashSet, we just collect from the Machine itself then go through an accessor `InterpCx::is_alloc_live` which checks a number of allocation data structures in the core interpreter. This avoids the overhead of all the inserts that collecting their keys would require. r? ``@RalfJung``
2023-11-19Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillotMichael Goulet-28/+26
interpret: simplify handling of shifts by no longer trying to handle signed and unsigned shift amounts in the same branch While we're at it, also update comments in codegen and MIR building related to shifts, and fix the overflow error printed by Miri on negative shift amounts.
2023-11-19Expand Miri's BorTag GC to a Provenance GCBen Kimock-0/+17
2023-11-18guarantee that char and u32 are ABI-compatibleRalf Jung-0/+2
2023-11-15Re-format code with new rustfmtMark Rousskov-3/+2
2023-11-14Fix some typoscui fliter-2/+2
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-11-12interpret: simplify handling of shifts by no longer trying to handle signed ↵Ralf Jung-28/+26
and unsigned shift amounts in the same branch
2023-11-01Rollup merge of #117373 - saethlin:avoid-ice-lint, r=compiler-errorsMatthias Krüger-8/+4
Avoid the path trimming ICE lint in error reporting Types or really anything in MIR should never be formatted without path trimming disabled, because its formatting often tries to construct trimmed paths. In this case, the lint turns a nice error report into an irrelevant ICE.
2023-11-01Avoid the path trimming ICE lint in error reportingBen Kimock-8/+4
2023-10-31Support enum variants in offset_of!George Bateman-1/+1
2023-10-30Rollup merge of #117317 - RalfJung:track-caller, r=oli-obkGuillaume Gomez-140/+48
share some track_caller logic between interpret and codegen Also move the code that implements the track_caller intrinsics out of the core interpreter engine -- it's just a helper creating a const-allocation, doesn't need to be part of the interpreter core.
2023-10-28share the track_caller handling within a mir::BodyRalf Jung-29/+11
2023-10-28interpret: call caller_location logic the same way codegen does, and share ↵Ralf Jung-140/+66
some code
2023-10-25Rename has_provance and tweaks comments.Camille GILLOT-1/+4
2023-10-25Take an AllocId in intern_const_alloc_for_constprop.Camille GILLOT-2/+1
2023-10-25Move provenance checks out of interning method.Camille GILLOT-13/+3