about summary refs log tree commit diff
path: root/compiler/rustc_symbol_mangling/src
AgeCommit message (Collapse)AuthorLines
2024-08-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-4/+0
closures
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-1/+2
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-17/+20
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-29Fix FnMut/Fn shim for coroutine-closures that capture referencesMichael Goulet-5/+16
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-2/+2
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-16Rename InstanceDef -> InstanceKindMichael Goulet-15/+15
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-2/+4
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-49/+35
2024-06-05Basic removal of `Ty` from places (boring)Boxy-11/+16
2024-05-17Rename Unsafe to SafetySantiago Pastorino-1/+1
2024-05-14Add v0 symbol mangling for `f16` and `f128`Trevor Gross-3/+2
As discussed at <https://github.com/rust-lang/rust/pull/122106>, use the crate encoding to represent new primitives.
2024-05-09Make builtin_deref just return a TyMichael Goulet-2/+1
2024-05-03Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obkbors-2/+2
Stabilize the size of incr comp object file names The current implementation does not produce stable-length paths, and we create the paths in a way that makes our allocation behavior is nondeterministic. I think `@eddyb` fixed a number of other cases like this in the past, and this PR fixes another one. Whether that actually matters I have no idea, but we still have bimodal behavior in rustc-perf and the non-uniformity in `find` and `ls` was bothering me. I've also removed the truncation of the mangled CGU names. Before this PR incr comp paths look like this: ``` target/debug/incremental/scratch-38izrrq90cex7/s-gux6gz0ow8-1ph76gg-ewe1xj434l26w9up5bedsojpd/261xgo1oqnd90ry5.o ``` And after, they look like this: ``` target/debug/incremental/scratch-035omutqbfkbw/s-gux6borni0-16r3v1j-6n64tmwqzchtgqzwwim5amuga/55v2re42sztc8je9bva6g8ft3.o ``` On the one hand, I'm sure this will break some people's builds because they're on Windows and only a few bytes from the path length limit. But if we're that seriously worried about the length of our file names, I have some other ideas on how to make them smaller. And last time I deleted some hash truncations from the compiler, there was a huge drop in the number if incremental compilation ICEs that were reported: https://github.com/rust-lang/rust/pull/110367https://github.com/rust-lang/rust/pull/110367 --- Upon further reading, this PR actually fixes a bug. This comment says the CGU names are supposed to be a fixed-length hash, and before this PR they aren't: https://github.com/rust-lang/rust/blob/ca7d34efa94afe271accf2bd3d44152a5bd6fff1/compiler/rustc_monomorphize/src/partitioning.rs#L445-L448
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-4/+2
2024-04-29Remove `extern crate rustc_middle` from numerous crates.Nicholas Nethercote-3/+2
2024-04-22Stabilize the size of incr comp object file namesBen Kimock-2/+2
2024-04-16Add simple async drop glue generationzetanumbers-1/+3
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
2024-04-14Update v0.rsTobias Decking-1/+1
2024-04-09Rollup merge of #123649 - maurer:kcfi-v0, r=compiler-errorsMatthias Krüger-2/+2
KCFI: Use legal charset in shim encoding To separate `ReifyReason::FnPtr` from `ReifyReason::VTable`, we hyphenated the shims. Hyphens are not actually legal, but underscores are, so use those instead. r? `@compiler-errors`
2024-04-08KCFI: Use legal charset in shim encodingMatthew Maurer-2/+2
To separate `ReifyReason::FnPtr` from `ReifyReason::VTable`, we hyphenated the shims. Hyphens are not actually legal, but underscores are, so use those instead.
2024-04-08sanitizers: Create the rustc_sanitizers crateRamon de C Valle-1348/+0
Create the rustc_sanitizers crate and move the source code for the CFI and KCFI sanitizers to it. Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+30
2024-04-06Rollup merge of #123525 - maurer:no-id-dyn2, r=compiler-errorsMatthias Krüger-20/+4
CFI: Don't rewrite ty::Dynamic directly Now that we're using a type folder, the arguments in predicates are processed automatically - we don't need to descend manually. We also want to keep projection clauses around, and this does so. r? `@compiler-errors`
2024-04-05CFI: Don't rewrite ty::Dynamic directlyMatthew Maurer-20/+4
Now that we're using a type folder, the arguments in predicates are processed automatically - we don't need to descend manually. We also want to keep projection clauses around, and this does so.
2024-04-04CFI: Restore typeid_for_instance default behaviorRamon de C Valle-7/+25
Restore typeid_for_instance default behavior of performing self type erasure, since it's the most common case and what it does most of the time. Using concrete self (or not performing self type erasure) is for assigning a secondary type id, and secondary type ids are only assigned when they're unique and to methods, and also are only tested for when methods are used as function pointers.
2024-04-04Rollup merge of #123212 - rcvalle:rust-cfi-use-type-folder, r=compiler-errorsMatthias Krüger-251/+177
CFI: Change type transformation to use TypeFolder Change type transformation to use TypeFolder. cc `@compiler-errors` `@maurer`
2024-04-04Auto merge of #123052 - maurer:addr-taken, r=compiler-errorsbors-12/+25
CFI: Support function pointers for trait methods Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions. KCFI does this through generation of a `ReifyShim` on any function pointer for a method that could go into a vtable, and keeping this separate from `ReifyShim`s that are *intended* for vtable us by setting a `ReifyReason` on them. CFI does this by setting both the concrete and abstract type on every instance. This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI. r? `@compiler-errors`
2024-04-02CFI: Support function pointers for trait methodsMatthew Maurer-2/+7
Adds support for both CFI and KCFI for attaching concrete and abstract types to functions. KCFI does this through generation of `ReifyShim` on any function pointer that could go in a vtable, and checking the `ReifyReason` when emitting the instance. CFI does this by attaching both the concrete and abstract type to every instance. TypeID codegen tests are switched to be anchored on the left rather than the right in order to allow emission of additional type attachments. Fixes #115953
2024-04-02Track reason for creating a `ReifyShim`Matthew Maurer-6/+14
KCFI needs to be able to tell which kind of `ReifyShim` it is examining in order to decide whether to use a concrete type (`FnPtr` case) or an abstract case (`Vtable` case). You can *almost* tell this from context, but there is one case where you can't - if a trait has a method which is *not* `#[track_caller]`, with an impl that *is* `#[track_caller]`, both the vtable and a function pointer created from that method will be `ReifyShim(def_id)`. Currently, the reason is optional to ensure no additional unique `ReifyShim`s are added without KCFI on. However, the case in which an extra `ReifyShim` is created is sufficiently rare that this may be worth revisiting to reduce complexity.
2024-04-02CFI: Switch sense of type erasure flagMatthew Maurer-4/+4
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now we have `ERASE_SELF_TYPE`, a positive configuration.
2024-04-02CFI: Support non-general coroutinesMatthew Maurer-10/+23
Previously, we assumed all `ty::Coroutine` were general coroutines and attempted to generalize them through the `Coroutine` trait. Select appropriate traits for each kind of coroutine.
2024-04-01CFI: Change type transformation to use TypeFolderRamon de C Valle-251/+177
Change type transformation to use TypeFolder.
2024-03-30CFI: Rewrite closure and coroutine instances to their trait methodMatthew Maurer-32/+81
Similar to methods on a trait object, the most common way to indirectly call a closure or coroutine is through the vtable on the appropriate trait. This uses the same approach as we use for trait methods, after backing out the trait arguments from the type.
2024-03-30CFI: Only encode Coroutine Parent ArgsMatthew Maurer-3/+13
Fixes #122705
2024-03-30Auto merge of #123012 - maurer:cfi-supertraits, r=compiler-errorsbors-10/+14
CFI: Support calling methods on supertraits Automatically adjust `Virtual` calls to supertrait functions to use the supertrait's trait object type as the receiver rather than the child trait. cc `@compiler-errors` - this is the next usage of `trait_object_ty` I intend to have, so I thought it might be relevant while reviewing the existing one.
2024-03-29CFI: Encode Virtual calls as calls through the defining traitMatthew Maurer-10/+14
For example, if `trait Foo: Bar`, and we try to call a method from `Bar` on `dyn Foo`, encode the callsite as passing a `dyn Bar`, not a `dyn Foo`.
2024-03-29Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, ↵bors-1/+13
r=compiler-errors CFI: Fix methods as function pointer cast Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers. This was split off from #116404. cc `@compiler-errors` `@workingjubilee`
2024-03-27CFI: Fix methods as function pointer castRamon de C Valle-1/+13
Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers.
2024-03-27Rollup merge of #123075 - rcvalle:rust-cfi-fix-drop-drop-in-place, ↵Matthias Krüger-2/+30
r=compiler-errors CFI: Fix drop and drop_in_place Fix drop and drop_in_place by transforming self of drop and drop_in_place methods into a Drop trait objects. This was split off from https://github.com/rust-lang/rust/pull/116404. cc `@compiler-errors` `@workingjubilee`
2024-03-27CFI: Fix drop and drop_in_placeRamon de C Valle-2/+30
Fix drop and drop_in_place by transforming self of drop and drop_in_place methods into Drop trait objects.
2024-03-26Rollup merge of #123066 - maurer:cfi-erased-lifetime-ice, r=compiler-errorsMatthias Krüger-3/+8
CFI: (actually) check that methods are object-safe before projecting their receivers to `dyn Trait` in CFI `trait_object_ty` assumed that associated types would be fully determined by the trait. This is *almost* true - const parameters and type parameters are no longer allowed, but lifetime parameters are. Since we erase all lifetime parameters anyways, instantiate it with as many erased regions as it needs. Fixes: #123053 r? `@compiler-errors`
2024-03-25CFI: Pad out associated type resolution with erased lifetimesMatthew Maurer-3/+8
`trait_object_ty` assumed that associated types would be fully determined by the trait. This is *almost* true - const parameters and type parameters are no longer allowed, but lifetime parameters are. Since we erase all lifetime parameters anyways, instantiate it with as many erased regions as it needs. Fixes: #123053
2024-03-25Instance is CopyMichael Goulet-4/+4
2024-03-25Rollup merge of #123005 - maurer:cfi-arbitrary-receivers, r=compiler-errorsMatthias Krüger-39/+71
CFI: Support complex receivers Right now, we only support rewriting `&self` and `&mut self` into `&dyn MyTrait` and `&mut dyn MyTrait`. This expands it to handle the full gamut of receivers by calculating the receiver based on *substitution* rather than based on a rewrite. This means that, for example, `Arc<Self>` will become `Arc<dyn MyTrait>` appropriately with this change. This approach also allows us to support associated type constraints as well, so we will correctly rewrite `&self` into `&dyn MyTrait<T=i32>`, for example. r? ```@workingjubilee```
2024-03-24CFI: Support arbitrary receiversMatthew Maurer-39/+71
Previously, we only rewrote `&self` and `&mut self` receivers. By instantiating the method from the trait definition, we can make this work work with arbitrary legal receivers instead.
2024-03-24CFI: Handle dyn with no principalMatthew Maurer-13/+14
In user-facing Rust, `dyn` always has at least one predicate following it. Unfortunately, because we filter out marker traits from receivers at callsites and `dyn Sync` is, for example, legal, this results in us having `dyn` types with no predicates on occasion in our alias set encoding. This patch handles cases where there are no predicates in a `dyn` type which are relevant to its alias set. Fixes #122998
2024-03-23Rollup merge of #122879 - maurer:callsite-instances, r=workingjubileeJubilee-4/+28
CFI: Strip auto traits off Virtual calls We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances. This is needed for the "separate machinery" version of my approach to the vtable issues (#122573), because we need to respond differently to a `Virtual` call to the same type as a non-virtual call, specifically [stripping auto traits off the receiver's `Self`](https://github.com/rust-lang/rust/pull/122573/commits/54b15b0c36d4638167732a0542ed0e34ecf17d7c) because there isn't a separate vtable for `Foo` vs `Foo + Send`. This would also make a more general underlying mechanism that could be used by rcvalle's [proposed drop detection / encoding](https://github.com/rust-lang/rust/pull/116404/commits/edcd1e20a1a69a8590d8ca47b31634854a40e3fb) if we end up using his approach, as we could condition out on the `def_id` in the CFI code rather than requiring the generating code to explicitly note whether it was calling drop.
2024-03-23CFI: Strip auto traits off Self for virtual callsMatthew Maurer-4/+28
Additional trait bounds beyond the principal trait and its implications are not possible in the vtable. This means that if a receiver is `&dyn Foo + Send`, the function will only be expecting `&dyn Foo`. This strips those auto traits off before CFI encoding.
2024-03-22CFI: Support self_cell-like recursionMatthew Maurer-25/+45
Current `transform_ty` attempts to avoid cycles when normalizing `#[repr(transparent)]` types to their interior, but runs afoul of this pattern used in `self_cell`: ``` struct X<T> { x: u8, p: PhantomData<T>, } #[repr(transparent)] struct Y(X<Y>); ``` When attempting to normalize Y, it will still cycle indefinitely. By using a types-visited list, this will instead get expanded exactly one layer deep to X<Y>, and then stop, not attempting to normalize `Y` any further.
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-9/+10