about summary refs log tree commit diff
path: root/compiler/stable_mir
AgeCommit message (Collapse)AuthorLines
2024-04-09Rollup merge of #123655 - celinval:smir-fix-binop-ty, r=compiler-errorsMatthias Krüger-37/+6
Remove unimplemented!() from BinOp::ty() function To reduce redundancy, we now internalize the BinOp instead of duplicating the `ty()` function body.
2024-04-08Add support to intrinsics fallback bodyCelina G. Val-1/+10
Before this fix, the call to `body()` would crash, since `has_body()` would return true, but we would try to retrieve the body of an intrinsic which is not allowed. Instead, the `Instance::body()` function will now convert an Intrinsic into an Item before retrieving its body.
2024-04-08Remove unimplemented!() from BinOp::ty() functionCelina G. Val-37/+6
To reduce redundancy, we now internalize the BinOp instead of duplicating the `ty()` function body.
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+8
2024-04-06Put checks that detect UB under their own flag below debug_assertionsBen Kimock-1/+1
2024-04-03rename `expose_addr` to `expose_provenance`joboet-0/+1
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-1/+1
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+4
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-03-28Normalize the result of Fields::ty_with_argsCelina G. Val-2/+2
We were only instantiating before, which would leak an AliasTy. I added a test case that reproduce the issue seen here: https://github.com/model-checking/kani/issues/3113
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+4
2024-03-23Rollup merge of #122762 - RoboSchmied:RoboSchmied-typo, r=workingjubileeJubilee-3/+3
fix typo of endianness fix typo endianess -> endianness
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-8/+2
library
2024-03-23rename MIR int2ptr casts to match library nameRalf Jung-1/+1
2024-03-22Split out ImplPolarity and PredicatePolarityMichael Goulet-1/+7
2024-03-21Rollup merge of #122801 - celinval:smir-pretty, r=compiler-errorsMatthias Krüger-341/+232
Fix misc printing issues in emit=stable_mir Trying to continue the work that ````@ouz-a```` started here: https://github.com/rust-lang/rust/pull/118364 Few modifications beyond fixes: 1. I made the `pretty_*` functions private. 2. I added a function to print the instance body 3. Changed a bunch of signatures to write to the writer directly. 4. Added a function to translate the place to its internal representation, so we could use the internal debug implementation. 5. Also removed `pretty_ty`, replaced by Display implementation of Ty which uses the internal display.
2024-03-20s/place_debug/place_pretty in SMIRCelina G. Val-2/+2
2024-03-20Enable users to dump the body of an instanceCelina G. Val-1/+8
2024-03-20Improve emit stable mir bodyCelina G. Val-341/+225
2024-03-20Update target.rs alloc.rs event.rs simd.rsRoboSchmied-3/+3
fix typos
2024-03-20resolve clippy errorsonur-ozkan-4/+4
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-14Rollup merge of #122405 - celinval:smir-new-const, r=oli-obkMatthias Krüger-5/+39
Add methods to create StableMIR constant I've been experimenting with transforming the StableMIR to instrument the code with potential UB checks. The modified body will only be used by our analysis tool, however, constants in StableMIR must be backed by rustc constants. Thus, I'm adding a few functions to build constants, such as building string and other primitives. One question I have is whether we should create a global allocation instead for strings. r? ``````@oli-obk``````
2024-03-13Rollup merge of #122426 - celinval:smir-fix-full, r=oli-obkMatthias Krüger-1/+1
Fix StableMIR `WrappingRange::is_full` computation `WrappingRange::is_full` computation assumed that to be full the range couldn't wrap, which is not necessarily true. For example, a range of 1..=0 is a valid representation of a full wrapping range.
2024-03-13Fix StableMIR is_full computationCelina G. Val-1/+1
`WrappingRange::is_full` computation assumed that to be full the range couldn't wrap, which is not necessarily true. For example, a range of 1..=0 is a valid representation of a full wrapping range.
2024-03-13Rollup merge of #122203 - adpaco-aws:smir-intrinsic-name, r=celinvalMatthias Krüger-0/+12
Add `intrinsic_name` to get plain intrinsic name Add an `intrinsic_name` API to retrieve the plain intrinsic name. The plain name does not include type arguments (as `trimmed_name` does), which is more convenient to match with intrinsic symbols.
2024-03-12Add `intrinsic_name` to get plain intrinsic nameAdrian Palacios-0/+12
2024-03-12Add methods to create constantsCelina G. Val-5/+39
I've been experimenting with transforming the StableMIR to instrument the code with potential UB checks. The modified body will only be used by our analysis tool, however, constants in StableMIR must be backed by rustc constants. Thus, I'm adding a few functions to build constants, such as building string and other primitives.
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-2/+8
2024-03-01Add support to new float typesCelina G. Val-4/+24
2024-03-01Implement missing ABI structures in StableMIRCelina G. Val-10/+177
2024-02-25remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsicsRalf Jung-1/+0
2024-02-24compiler: use `addr_of!`Pavel Grigorenko-1/+1
2024-02-17Merge `CompilerError::CompilationFailed` and `CompilerError::ICE`.Nicholas Nethercote-8/+4
`CompilerError` has `CompilationFailed` and `ICE` variants, which seems reasonable at first. But the way it identifies them is flawed: - If compilation errors out, i.e. `RunCompiler::run` returns an `Err`, it uses `CompilationFailed`, which is reasonable. - If compilation panics with `FatalError`, it catches the panic and uses `ICE`. This is sometimes right, because ICEs do cause `FatalError` panics, but sometimes wrong, because certain compiler errors also cause `FatalError` panics. (The compiler/rustdoc/clippy/whatever just catches the `FatalError` with `catch_with_exit_code` in `main`.) In other words, certain non-ICE compilation failures get miscategorized as ICEs. It's not possible to reliably distinguish the two cases, so this commit merges them. It also renames the combined variant as just `Failed`, to better match the existing `Interrupted` and `Skipped` variants. Here is an example of a non-ICE failure that causes a `FatalError` panic, from `tests/ui/recursion_limit/issue-105700.rs`: ``` #![recursion_limit="4"] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] //~^ERROR recursion limit reached while expanding fn main() {{}} ```
2024-02-15Rollup merge of #120982 - momvart:smir-61-foreign_kind, r=oli-obkMatthias Krüger-5/+51
Add APIs for fetching foreign items Closes https://github.com/rust-lang/project-stable-mir/issues/61
2024-02-14Rewrite foreign item kind query using `DefKind`Mohammad Omidvar-2/+2
2024-02-12Add APIs for fetching foreign items including foreign modules, their ABIs, ↵Mohammad Omidvar-5/+51
and their items
2024-02-12Dejargnonize substShoyu Vanilla-2/+2
2024-02-08Add a new debug_assertions instrinsic (compiler)Ben Kimock-0/+3
And in clippy
2024-01-30Remove the `abi_amdgpu_kernel` featureclubby789-2/+0
2024-01-25Remove unused featuresclubby789-1/+0
2024-01-19Make the remaining "private" fields actually privateOli Scherer-2/+2
2024-01-12Rollup merge of #119877 - celinval:smir-visit-projection, r=oli-obkGuillaume Gomez-19/+38
Add more information to `visit_projection_elem` Without the starting place, it's hard to retrieve any useful information from visiting a projection. Note: I still need to add a test.
2024-01-11Add more information to `visit_projection_elem`Celina G. Val-19/+38
Without the starting place, it's hard to retrieve any useful information from visiting a projection.
2024-01-09Fix all_trait* methods to return all trait availableCelina G. Val-11/+32
Also provide a mechanism to retrieve traits and implementations for a given crate.
2023-12-28Restore movability to SMIRMichael Goulet-8/+13
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-11/+8
2023-12-25Only regular coroutines have movabilityMichael Goulet-3/+3
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-21/+34
2023-12-20Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errorsMatthias Krüger-0/+9
Add method to get instance instantiation arguments Add a method to get the instance instantiation arguments, and include that information in the instance debug.
2023-12-20Add method to get instance instantiation argumentsCelina G. Val-0/+9
2023-12-20Add `ItemKind::Ctor` to stable mirCelina G. Val-0/+7