summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2023-12-17Tolerate overaligned MIR constants for codegen.Camille GILLOT-1/+1
2023-12-12reject projecting to fields whose offset we cannot computeRalf Jung-12/+7
2023-12-12codegen: panic when trying to compute size/align of extern typeRalf Jung-18/+14
2023-12-10Auto merge of #118791 - saethlin:use-immediate-type, r=nikicbors-1/+1
Use immediate_backend_type when reading from a const alloc Fixes https://github.com/rust-lang/rust/issues/118047 r? `@nikic`
2023-12-10remove redundant importssurechen-1/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Use immediate_backend_type when reading from a const allocBen Kimock-1/+1
2023-12-08Implement `async gen` blocksMichael Goulet-1/+5
2023-12-07Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlinbors-1/+1
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-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-1/+1
is immutable
2023-12-04Rollup merge of #118551 - RalfJung:extern-types-bugs, r=compiler-errorsTakayuki Maeda-0/+1
more targeted errors when extern types end up in places they should not Cc https://github.com/rust-lang/rust/issues/115709 -- this does not fix that bug but it makes the panics less obscure and makes it more clear that this is a deeper issue than just a little codegen oversight. (In https://github.com/rust-lang/rust/pull/116115 we decided we'd stick to causing ICEs here for now, rather than nicer errors. We can't currently show any errors pre-mono and probably we don't want post-mono checks when this gets stabilized anyway.)
2023-12-03codegen, miri: fix computing the offset of an unsized field in a packed structRalf Jung-10/+12
2023-12-03more targeted errors when extern types end up in places they should notRalf Jung-0/+1
2023-11-22Rollup merge of #118147 - Nilstrieb:no-redundant-casts, r=WaffleLapkinMichael Goulet-7/+5
Fix some unnecessary casts `x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-21Fix some unnecessary castsNilstrieb-7/+5
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-31/+28
`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-14Fix def-use check for call terminatorsTomasz Miąsko-6/+13
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-1/+1
also adds some comments
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-3/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-31Support enum variants in offset_of!George Bateman-1/+1
2023-10-28share the track_caller handling within a mir::BodyRalf Jung-32/+4
2023-10-28interpret: call caller_location logic the same way codegen does, and share ↵Ralf Jung-8/+1
some code
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-20s/Generator/Coroutine/Oli Scherer-2/+2
2023-10-17[RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopesUrgau-1/+2
2023-10-13Format all the let chains in compilerMichael Goulet-25/+70
2023-10-08Auto merge of #116454 - tmiasko:small-dominators, r=cjgillotbors-16/+1
Generalize small dominators optimization * Use small dominators optimization from 640ede7b0a1840415cb6ec881c2210302bfeba18 more generally. * Merge `DefLocation` and `LocationExtended` since they serve the same purpose.
2023-10-06Rollup merge of #116277 - RalfJung:post-mono, r=oli-obkJubilee-11/+6
dont call mir.post_mono_checks in codegen It seems like all tests are still passing when I remove this... let's see what CI says.
2023-10-06add some comments explaining how the required_consts stuff fits togetherRalf Jung-0/+6
2023-10-05Move DefLocation from rustc_codegen_ssa to rustc_middleTomasz Miąsko-16/+1
2023-10-03Auto merge of #115025 - ouz-a:ouz_testing, r=lcnrbors-0/+1
Make subtyping explicit in MIR This adds new mir-opt that pushes new `ProjectionElem` called `ProjectionElem::Subtype(T)` to `Rvalue` of a subtyped assignment so we can unsoundness issues like https://github.com/rust-lang/rust/issues/107205 Addresses https://github.com/rust-lang/rust/issues/112651 r? `@lcnr`
2023-10-02Add docs, remove code, change subtyper codeouz-a-1/+1
2023-10-02subtyping_projectionsouz-a-0/+1
2023-10-02Reapply: Mark drop calls in landing pads cold instead of noinlineErik Desjardins-7/+3
Co-authored-by: Max Fan <git@max.fan> Co-authored-by: Nikita Popov <npopov@redhat.com>
2023-09-30dont call mir.post_mono_checks in codegenRalf Jung-11/+0
2023-09-28Strip `OpaqueCast` during `RevealAll`.Oli Scherer-1/+3
2023-09-26Auto merge of #116144 - lcnr:subst-less, r=oli-obkbors-1/+1
subst -> instantiate continues #110793, there are still quite a few uses of `subst` and `substitute`, but changing them all in the same PR was a bit too much, so I've stopped here for now.
2023-09-26Auto merge of #116102 - cjgillot:indirect-scalar, r=oli-obkbors-12/+11
Correct codegen of `ConstValue::Indirect` scalar and scalar pair This concerns 3 tricky cases with `ConstValue::Indirect`: - if we want a non-pointer scalar; - if we have non-zero offset; - if offset points to uninit memory => generate `poison` instead of an ICE. This case could happen in unreachable code, trying to extract a field from the wrong variant. Those cases are not currently emitted by the compiler, but are exercised by https://github.com/rust-lang/rust/pull/116012.
2023-09-26subst -> instantiatelcnr-1/+1
2023-09-23Use correct offset when codegening mir::Const::Indirect.Camille GILLOT-12/+11
2023-09-23Tolerate non-ptr indirect scalars in codegen.Camille GILLOT-1/+1
2023-09-23Reuse calculate_debuginfo_offset for fragments.Camille GILLOT-33/+10
2023-09-21Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obkGuillaume Gomez-12/+12
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`. Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all. However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish... ``@oli-obk`` any ideas?
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-12/+12
2023-09-19adjust constValue::Slice to work for arbitrary slice typesRalf Jung-6/+3
2023-09-19move ConstValue into mirRalf Jung-5/+5
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-18Auto merge of #115748 - RalfJung:post-mono, r=oli-obkbors-67/+21
move required_consts check to general post-mono-check function This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants. Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized. I didn't expect this to change diagnostics, but it's just cycle errors that change. r? `@oli-obk`
2023-09-15clarify PassMode::Indirect as wellRalf Jung-1/+1
2023-09-15explain PassMode::CastRalf Jung-8/+8
2023-09-14don't point at const usage site for resolution-time errorsRalf Jung-16/+8
also share the code that emits the actual error
2023-09-14move required_consts check to general post-mono-check functionRalf Jung-65/+27