summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2024-04-04Don't inherit codegen attrs from parent staticMichael Goulet-1/+7
(cherry picked from commit 4ff8a9bd6b64e32703603cf8bc8cb5cb221d4889)
2024-03-14Move the entire success path into `eval_body_using_ecx`Oli Scherer-1/+1
2024-03-14Move generate_stacktrace_from_stack away from InterpCx to avoid having to ↵Oli Scherer-29/+27
know the `Machine` type
2024-03-14Move InterpCx into eval_in_interpreterOli Scherer-1/+1
2024-03-14Move only usage of `take_static_root_alloc` to its definition and inline itOli Scherer-10/+15
2024-03-14Auto merge of #122243 - RalfJung:local-place-sanity-check, r=oli-obkbors-70/+58
interpret: ensure that Place is never used for a different frame We store the address where the stack frame stores its `locals`. The idea is that even if we pop and push, or switch to a different thread with a larger number of frames, then the `locals` address will most likely change so we'll notice that problem. This is made possible by some recent changes by `@WaffleLapkin,` where we no longer use `Place` across things that change the number of stack frames. I made these debug assertions for now, just to make sure this can't cost us any perf. The first commit is unrelated but it's a one-line comment change so it didn't warrant a separate PR... r? `@oli-obk`
2024-03-13placate tidy.Felix S. Klock II-1/+1
2024-03-13downgrade mutable-ptr-in-final-value from hard-error to future-incompat lint ↵Felix S. Klock II-4/+8
to address issue 121610.
2024-03-13Auto merge of #122240 - RalfJung:miri-addr-reuse, r=oli-obkbors-2/+4
miri: add some chance to reuse addresses of previously freed allocations The hope is that this can help us find ABA issues. Unfortunately this needs rustc changes so I can't easily run the regular benchmark suite. I used `src/tools/miri/tests/pass/float_nan.rs` as a substitute: ``` Before: Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021 Time (mean ± σ): 9.570 s ± 0.013 s [User: 9.279 s, System: 0.290 s] Range (min … max): 9.561 s … 9.579 s 2 runs After: Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021 Time (mean ± σ): 9.698 s ± 0.046 s [User: 9.413 s, System: 0.279 s] Range (min … max): 9.666 s … 9.731 s 2 runs ``` That's a ~1.3% slowdown, which seems fine to me. I have seen a lot of noise in this style of benchmarking so I don't quite trust this anyway; we can make further experiments in the Miri repo after this migrated there. r? `@oli-obk`
2024-03-12Exhaustively match on the mutability and nestednessOli Scherer-7/+9
2024-03-12s/mt/mutability/Oli Scherer-4/+4
2024-03-12Ensure nested allocations in statics do not get deduplicatedOli Scherer-31/+98
2024-03-12Add `nested` bool to `DefKind::Static`.Oli Scherer-1/+1
Will be used in the next commit
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-9/+10
2024-03-11Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obkJubilee-6/+43
interpret: do not call machine read hooks during validation Fixes https://github.com/rust-lang/miri/issues/3347 r? ``@oli-obk``
2024-03-10remove unnecessary frame parameter from after_local_allocatedRalf Jung-4/+4
2024-03-10Auto merge of #121662 - saethlin:precondition-unification, r=RalfJungbors-4/+10
Distinguish between library and lang UB in assert_unsafe_precondition As described in https://github.com/rust-lang/rust/pull/121583#issuecomment-1963168186, `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
2024-03-09interpret: do not call machine read hooks during validationRalf Jung-6/+43
2024-03-09remove some frame parameters that are no longer neededRalf Jung-17/+17
2024-03-09remove a machine hook that is no longer usedRalf Jung-24/+0
2024-03-09interpret: ensure that Place is never used for a different frameRalf Jung-33/+45
2024-03-09Only enable library UB checks in const-eval/Miri when debug_assertions are ↵Ben Kimock-1/+1
enabled Co-authored-by: Ralf Jung <post@ralfj.de>
2024-03-09interpret: pass Size and Align to before_memory_deallocationRalf Jung-2/+4
2024-03-09miri: do not apply aliasing restrictions to Box with custom allocatorRalf Jung-7/+11
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-4/+10
2024-03-08Rollup merge of #122076 - WaffleLapkin:mplace-args, r=RalfJungMatthias Krüger-24/+50
Tweak the way we protect in-place function arguments in interpreters Use `MPlaceTy` instead of `PlaceTy` in `FnArg` and ignore (copy) locals in an earlier step ("Locals that don't have their address taken are as protected as they can ever be"). This seems to be crucial for tail call support (as they can't refer to caller's locals which are killed when replacing the stack frame). r? `@RalfJung` cc `@oli-obk` see https://github.com/rust-lang/rust/pull/121273#issuecomment-1980210690
2024-03-08Tweak the way we protect in-place function arguments in interpretersMaybe Waffle-24/+50
Use `MPlaceTy` instead of `PlaceTy` in `FnArg` and ignore (copy) locals in an earlier step ("Locals that don't have their address taken are as protected as they can ever be"). This seems to be crucial for tail call support (as they can't refer to caller's locals which are killed when replacing the stack frame).
2024-03-08Rollup merge of #122183 - RalfJung:read-discriminant-uninhabited-variant, ↵Matthias Krüger-1/+7
r=tmiasko interpret: update comment about read_discriminant on uninhabited variants
2024-03-08interpret: update comment about read_discriminant on uninhabited variantsRalf Jung-1/+7
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-10/+8
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-07Auto merge of #121985 - RalfJung:interpret-return-place, r=oli-obkbors-26/+22
interpret: avoid a long-lived PlaceTy in stack frames `PlaceTy` uses a representation that's not very stable under changes to the stack. I'd feel better if we didn't have one in the long-term machine state. r? `@oli-obk`
2024-03-06Auto merge of #122045 - matthiaskrgr:rollup-5l3vpn7, r=matthiaskrgrbors-8/+3
Rollup of 9 pull requests Successful merges: - #121065 (Add basic i18n guidance for `Display`) - #121744 (Stop using Bubble in coherence and instead emulate it with an intercrate check) - #121829 (Dummy tweaks (attempt 2)) - #121857 (Implement async closure signature deduction) - #121894 (const_eval_select: make it safe but be careful with what we expose on stable for now) - #122014 (Change some attributes to only_local.) - #122016 (will_wake tests fail on Miri and that is expected) - #122018 (only set noalias on Box with the global allocator) - #122028 (Remove some dead code) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-05Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obkMatthias Krüger-8/+3
only set noalias on Box with the global allocator As discovered in https://github.com/rust-lang/miri/issues/3341, `noalias` and custom allocators don't go well together. rustc can now check whether a Box uses the global allocator. This replaces the previous ad-hoc and rather unprincipled check for a zero-sized allocator. This is the rustc part of fixing that; Miri will also need a patch.
2024-03-05Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult`Jason Newcomb-3/+3
2024-03-05only set noalias on Box with the global allocatorRalf Jung-8/+3
2024-03-04consistently use MPlaceTy for return placesRalf Jung-26/+15
2024-03-04typoRalf Jung-1/+1
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2024-03-04interpret/cast: make more matches on FloatTy properly exhaustiveRalf Jung-23/+35
2024-03-04interpret: avoid a long-lived PlaceTy in stack framesRalf Jung-3/+10
2024-03-01Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compiler-errorsbors-0/+2
Add stubs in IR and ABI for `f16` and `f128` This is the very first step toward the changes in https://github.com/rust-lang/rust/pull/114607 and the [`f16` and `f128` RFC](https://rust-lang.github.io/rfcs/3453-f16-and-f128.html). It adds the types to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`, and just propagates those out as `unimplemented!` stubs where necessary. These types do not parse yet so there is no feature gate, and it should be okay to use `unimplemented!`. The next steps will probably be AST support with parsing and the feature gate. r? `@compiler-errors` cc `@Nilstrieb` suggested breaking the PR up in https://github.com/rust-lang/rust/pull/120645#issuecomment-1925900572
2024-02-29allow statics pointing to mutable staticsRalf Jung-17/+8
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-0/+2
Make changes necessary to support these types in the compiler.
2024-02-24Auto merge of #121549 - matthiaskrgr:rollup-1hvu3lb, r=matthiaskrgrbors-8/+12
Rollup of 7 pull requests Successful merges: - #121435 (Account for RPITIT in E0310 explicit lifetime constraint suggestion) - #121490 (Rustdoc: include crate name in links for local primitives) - #121520 (delay cloning of iterator items) - #121522 (check that simd_insert/extract indices are in-bounds) - #121531 (Ignore less tests in debug builds) - #121539 (compiler/rustc_target/src/spec/base/apple/tests.rs: Avoid unnecessary large move) - #121542 (update stdarch) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-10/+8
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-2/+2
2024-02-23interpret: do no ICE on OOB shuffle/insert/extract indicesRalf Jung-8/+12
2024-02-22Overhaul `Diagnostic` args.Nicholas Nethercote-1/+1
First, introduce a typedef `DiagnosticArgMap`. Second, make the `args` field public, and remove the `args` getter and `replace_args` setter. These were necessary previously because the getter had a `#[allow(rustc::potential_query_instability)]` attribute, but that was removed in #120931 when the args were changed from `FxHashMap` to `FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-16Rollup merge of #121179 - RalfJung:zst-mutable-refs, r=oli-obkGuillaume Gomez-46/+39
allow mutable references in const values when they point to no memory Fixes https://github.com/rust-lang/rust/issues/120450 The second commit is just some drive-by test suite cleanup. r? `@oli-obk`
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-1/+1
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16allow mutable references in const values when they point to no memoryRalf Jung-46/+39