summary refs log tree commit diff
path: root/compiler/rustc_smir/src
AgeCommit message (Collapse)AuthorLines
2024-01-30Remove the `abi_amdgpu_kernel` featureclubby789-3/+0
2024-01-22Do not normalize closure signature when building FnOnce shimMichael Goulet-1/+4
2024-01-19Use the new `with_tables` everywhereOli Scherer-145/+127
2024-01-19Ensure internal function is safeCelina G. Val-198/+294
The internal function was unsound, it could cause UB in rare cases where the user inadvertly stored the returned object in a location that could outlive the TyCtxt. In order to make it safe, we now take a type context as an argument to the internal fn, and we ensure that interned items are lifted using the provided context. Thus, this change ensures that the compiler can properly enforce that the object does not outlive the type context it was lifted to.
2024-01-19Fix `Stable` trait and its impls to work with the new `with_tables`Oli Scherer-129/+136
2024-01-19Fix a soundness bug in `with_tables`.Oli Scherer-2/+2
We were able to uplift any value from `Tables` to `'static`, which is unsound.
2024-01-18Rollup merge of #119833 - celinval:smir-accept-closures, r=oli-obkMatthias Krüger-16/+106
Make tcx optional from StableMIR run macro and extend it to accept closures Change `run` macro to avoid sometimes unnecessary dependency on `TyCtxt`, and introduce `run_with_tcx` to capture use cases where `tcx` is required. Additionally, extend both macros to accept closures that may capture variables. I've also modified the `internal()` method to make it safer, by accepting the type context to force the `'tcx` lifetime to match the context lifetime. These are non-backward compatible changes, but they only affect internal APIs which are provided today as helper functions until we have a stable API to start the compiler.
2024-01-17Revert changes to internal method for nowCelina G. Val-29/+4
- Move fix to a separate PR
2024-01-16Remove tcx function and make `internal` fn saferCelina G. Val-28/+55
I added `tcx` argument to `internal` to force 'tcx to be the same lifetime as TyCtxt. The only other solution I could think is to change this function to be `unsafe`.
2024-01-16Remove tcx from SMIR run macro and accept closuresCelina G. Val-17/+105
Simplify the `run` macro to avoid sometimes unnecessary dependency on `TyCtxt`. Instead, users can use the new internal method `tcx()`. Additionally, extend the macro to accept closures that may capture variables. These are non-backward compatible changes, but they only affect internal APIs which are provided today as helper functions until we have a stable API to start the compiler.
2024-01-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-1/+1
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-11Rollup merge of #119790 - celinval:smir-all-traits, r=oli-obkMatthias Krüger-4/+27
Fix all_trait* methods to return all traits available in StableMIR Also provide a mechanism to retrieve traits and implementations for a given crate. This fixes https://github.com/rust-lang/project-stable-mir/issues/37
2024-01-10Simplify some redundant namesMichael Goulet-8/+6
2024-01-09Fix all_trait* methods to return all trait availableCelina G. Val-4/+27
Also provide a mechanism to retrieve traits and implementations for a given crate.
2023-12-28Movability doesn't need to be a query anymoreMichael Goulet-2/+2
2023-12-28Restore movability to SMIRMichael Goulet-1/+3
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-9/+5
2023-12-25Only regular coroutines have movabilityMichael Goulet-2/+4
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-7/+16
2023-12-20Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errorsMatthias Krüger-0/+6
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/+6
2023-12-20Add `ItemKind::Ctor` to stable mirCelina G. Val-9/+7
2023-12-20Fix crash for `CrateItem::kind()` with constructorsCelina G. Val-5/+8
Change how we classify item kind for DefKind::Ctor
2023-12-20Rollup merge of #119094 - celinval:smir-layout, r=compiler-errorsMatthias Krüger-21/+344
Add function ABI and type layout to StableMIR This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits. r? ```@compiler-errors```
2023-12-19Fix c_variadic flag and add opaque info to PassModeCelina G. Val-4/+17
We should expand the information in PassMode later.
2023-12-18Add the function body span to StableMIRCelina G. Val-0/+1
2023-12-18Add function ABI and type layout to StableMIRCelina G. Val-21/+331
This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits.
2023-12-17Auto merge of #119000 - celinval:smir-cstr, r=ouz-abors-0/+6
Add a method to StableMIR to check if a type is a CStr Also add a check that StableMIR works properly with C string literal.
2023-12-15NFC don't convert types to identical typesMatthias Krüger-1/+0
2023-12-15Add a method to check if type is a CStrCelina G. Val-0/+6
2023-12-14Address PR commentsCelina G. Val-12/+6
- Remove `fn_sig()` from Instance. - Change return value of `AssertMessage::description` to `Cow<>`. - Add assert to instance `ty()`. - Generalize uint / int type creation.
2023-12-13Add spread arg and missing CoroutineKindCelina G. Val-1/+4
2023-12-13Erase late bound regions from instance `fn_sig()`Celina G. Val-3/+12
Late bound regions were still part of the signature.
2023-12-12Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkinJubilee-1/+1
more clippy::complexity fixes redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-12more clippy::complexity fixesMatthias Krüger-1/+1
redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
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-12Rollup merge of #118846 - celinval:smir-ty-methods, r=compiler-errorsMatthias Krüger-0/+12
Fix BinOp `ty()` assertion and `fn_sig()` for closures `BinOp::ty()` was asserting that the argument types were primitives. However, the primitive check doesn't include pointers, which can be used in a `BinaryOperation`. Thus extend the arguments to include them. Since I had to add methods to check for pointers in TyKind, I just went ahead and added a bunch more utility checks that can be handy for our users and fixed the `fn_sig()` method to also include closures. `@compiler-errors` just wanted to confirm that today no `BinaryOperation` accept SIMD types. Is that correct? r? `@compiler-errors`
2023-12-11Fix BinOp ty assertion and `fn_sig` for closuresCelina G. Val-0/+12
Also added a few more util methods to TyKind to check for specific types.
2023-12-11Monomorphize args while building Instance bodyCelina G. Val-1/+5
2023-12-10remove redundant importssurechen-2/+2
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-08Rollup merge of #118694 - celinval:smir-alloc-methods, r=ouz-aMatthias Krüger-13/+88
Add instance evaluation and methods to read an allocation in StableMIR The instance evaluation is needed to handle intrinsics such as `type_id` and `type_name`. Since we now use Allocation to represent all evaluated constants, provide a few methods to help process the data inside an allocation. I've also started to add a structured way to get information about the compilation target machine. For now, I've only added information needed to process an allocation. r? ``````@ouz-a``````
2023-12-08Implement `async gen` blocksMichael Goulet-0/+1
2023-12-08Auto merge of #118725 - lcnr:normalizes-to-projection-split-3, r=BoxyUwUbors-0/+1
split `NormalizesTo` out of `Projection` 3 third attempt at #112658. Rebasing #116262 is very annoying, so I am doing it again from scratch. We should now be able to merge it without regressing anything as we handle occurs check failures involving aliases correctly since #117088. see https://hackmd.io/ktEL8knTSYmtdfrMMnA-Hg fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/1 r? `@compiler-errors`
2023-12-07Add instance evaluation and methods to read allocCelina G. Val-13/+88
The instance evaluation is needed to handle intrinsics such as `type_id` and `type_name`. Since we now use Allocation to represent all evaluated constants, provide a few methods to help process the data inside an allocation.
2023-12-07Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errorsMatthias Krüger-2/+16
Add method to get type of an Rvalue in StableMIR Provide a method to StableMIR users to retrieve the type of an Rvalue operation. There were two possible implementation: 1. Create the logic inside stable_mir to process the type according to the Rvalue semantics, which duplicates the logic of `rustc_middle::mir::Rvalue::ty()`. 2. Implement the Rvalue translation from StableMIR back to internal representation, invoke the `rustc_middle::mir::Rvalue::ty()`, and translate the return value to StableMIR. I chose the first one for now since the duplication was fairly small, and the option 2 would require way more work to translate everything back to rustc internal representation. If we eventually add those translations, we could easily swap to the option 2. ```@compiler-errors``` / ```@ouz-a``` Please let me know if you have any strong opinion here. r? ```@compiler-errors```
2023-12-07Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlinbors-2/+5
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-07add unused `NormalizesTo` predicatelcnr-0/+1
2023-12-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-2/+5
is immutable
2023-12-06Simplify StaticDef to Instance conversionCelina G. Val-2/+2
2023-12-06Add method to get type of an Rvalue in StableMIRCelina G. Val-0/+14