Move symbol hiding code to a new file
Move the symbol visibility editing code (`apply_hide` and helpers) from
`archive.rs` into a new `symbol_edit.rs` module.
This is a pure code move with no functional changes — extracted to reduce
the size of `archive.rs` and to provide a natural home for future symbol
editing logic (e.g. renaming, rust-lang/rust#156950).
Requested in https://github.com/rust-lang/rust/pull/156950#discussion_r3382313460.
r? @petrochenkov
Set !captures metadata for store of &Freeze
When a `&Freeze` reference is stored (with retag), emit `!captures !{!"address", !"read_provenance"}` metadata to indicate that it's UB to write through the stored pointer.
Related to https://github.com/rust-lang/rust/issues/146844.
r? @ghost
When a `&Freeze` reference is stored (with retag), emit
`!captures !{!"address", !"read_provenance"}` metadata to indicate
that it's UB to write through the stored pointer.
Use `mul nuw nsw` in `intrinsics::copy`
Essentially the same as rust-lang/rust#157560, just for `copy` instead of `copy_nonoverlapping`.
> Yeah, in fact both copy and copy_nonoverlapping could use this since we know the result must be at most isize::MAX else it cannot be inbounds.
> ~ https://github.com/rust-lang/rust/pull/157560#issuecomment-4642072687
r? saethlin
In `copy_nonoverlapping`, use `mul nuw nsw` to compute the byte size
Seems like we might as well? Adding these flags means the optimizer can tell the limited range on the count of items -- like how we use these flags (rust-lang/rust#136575) when calculating `size_of_val` for a slice.
Today we use a wrapping multiplication, which mean that `copy_nonoverlapping::<u32>(src, dst, 0x40000000_00000001)` appears like 4 bytes -- a perfectly reasonable size! -- once it gets to the `memcpy` call.
If I'm understanding <https://doc.rust-lang.org/std/ptr/fn.copy_nonoverlapping.html#safety> properly, this is just exploiting existing UB, since `src` and `dst` must each be inside an allocation, and those allocations can be at most `isize::MAX` bytes. (Plus, fundamentally, to be non-overlapping there's not enough space in the address space to be bigger than `isize::MAX`.)
cc @RalfJung to make sure this is ok, as requested last he found out I was newly exploiting some UB in codegen 🙃
r? codegen
This is an UnordMap internally. Iteration order for the work product map
should not matter aside from the place it is serialized where sorting by
WorkProductId is sufficient.
This disables caching of compiled objects by the codegen backend during
incremental compilation. This is useful for iterating on a codegen
backend without having to run the entire rustc frontend from scratch
every time when recompiling the standard library. Currently cg_clif has
the CG_CLIF_DISABLE_INCR_CACHE env var that does this, but once cg_clif
switches to the codegen coordinator of cg_ssa, it will no longer be
possible for cg_clif to implement this. It has to be implemented in
cg_ssa.
Emit retags in codegen to support BorrowSanitizer (part 2)
Tracking issue: rust-lang/rust#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/593004012)
This is one of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in rust-lang/rust#155965.
This PR adds a new unstable flag `-Zcodegen-emit-retag`, which will enable experimental retag calls in generated code. This flag is a nop for now, but the relevant methods have been added to codegen_ssa, and they are called wherever retags are necessary. Subsequent PRs will complete this implementation.
This does not depend on rust-lang/rust#156208.
r? @RalfJung
Enable `clippy::mem_replace_with_default`
Enables `clippy::mem_replace_with_default` and fixes the errors that occur as a result.
Closesrust-lang/rust#157245.
Remove -Zemscripten-wasm-eh
This was necessary when transitioning from JS to wasm exception handling on Emscripten. Enough time has probably passed that we no longer need to support JS exception handling on Emscripten. This enables cleaning up a fair bit of code.
This is the final step of https://github.com/rust-lang/rust/issues/112195.
Use weak linkage for EII defaults
hard to find a test for this, but weak seems more correct (after private discussion with @bjorn3)
Also changes a log statement to make it a lil easier to see what's going on.
r? @bjorn3
This was necessary when transitioning from JS to wasm exception handling
on Emscripten. Enough time has probably passed that we no longer need to
support JS exception handling on Emscripten. This enables cleaning up a
fair bit of code.
Use a `ArrayVec` in `CastTarget`
This commit switches a fixed-size list of `[Option<Reg>; 8]` to instead
holding `ArrayVec<Reg, 8>` in the `CastTarget` type used when
calculating ABIs. This is inspired by [discussion on Zulip][link] where
I'm hoping to in the near future extend the usage of this to possibly
beyond 8 elements for a new WebAssembly ABI taking advantage of
multi-value. For now though this mostly just switches to
array/slice-like idioms of accessors rather than dealing with
`Option<Reg>` as the unit.
[link]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20.60ArgAbi.3A.3Amake_direct_deprecated.60/with/598607139
introduce UnevaluatedConstKind
(no rush on this, boxy, if you get this notif, I know you're on break after rustweek)
Partially fixes https://github.com/rust-lang/project-const-generics/issues/98
- does not unify GCE `ConstKind::Expr` into Unevaluated, which is part of that issue
- does not do more advanced refactoring to take advantage of the new kind repr, only refactoring when things are very obviously able to take advantage
- does not change MIR's UnevaluatedConst to use UnevaluatedConstKind, as there's currently no benefit, and doing so instead overcomplicates many places. Possibly could be done in a followup, or I can do it here if desired.
- more advanced potentially behavior-changing changes can be done in a followup, as this diff is big enough as it is, IMO. same with merging GCE Exprs into Unevaluated.
- (... but if this takes a while to get reviewed, I might plop some more stuff into this PR)
- I think it would be cute to rename UnevaluatedConst to AliasConst or something, to better reflect the parallels to AliasTy, but shrug, haha
r? @BoxyUwU
cg_ssa: a bit less `immediate_or_packed_pair`
This is one of the things that made cg_clif not use cg_ssa, IIRC, so let's take the opportunities to avoid it where we can.
r? codegen
This commit switches a fixed-size list of `[Option<Reg>; 8]` to instead
holding `ArrayVec<Reg, 8>` in the `CastTarget` type used when
calculating ABIs. This is inspired by [discussion on Zulip][link] where
I'm hoping to in the near future extend the usage of this to possibly
beyond 8 elements for a new WebAssembly ABI taking advantage of
multi-value. For now though this mostly just switches to
array/slice-like idioms of accessors rather than dealing with
`Option<Reg>` as the unit.
[link]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20.60ArgAbi.3A.3Amake_direct_deprecated.60/with/598607139
compiler: `ops::RangeInclusive` → `range::RangeInclusive`
The type's been stable for over 6 weeks now, so let's use it! It's better for cases like this one where it's stored in a data structure.
Probably won't be materially faster, but does make the variant slightly smaller and lets some more things be `Copy`. And deletes a whole bunch of parens from things being fields instead of methods 😄
r? compiler
Allow two object files for a single CGU in CompiledModule
cg_clif needs this as it passes inline assembly to an external assembler, producing a separate object file. Currently it emits multiple CompiledModules, but this is not compatible with using the codegen coordinator of cg_ssa.
The type's been stable for over 6 weeks now, so let's use it! It's better for cases like this one where it's stored in a data structure.
Probably won't be materially faster, but does make the variant slightly smaller and lets some more things be `Copy`.
cg_clif needs this as it passes inline assembly to an external assembler,
producing a separate object file. Currently it emits multiple
CompiledModules, but this is not compatible with using the codegen
coordinator of cg_ssa.
MIR inlining: allow backends to opt-in to inlining intrinsics
This is the same as https://github.com/rust-lang/rust/pull/156398. Github stopped processing updates on that other branch.
r? @oli-obk
Extend macOS deployment target mismatch filter to cover dylib and new ld formats
The `deployment_mismatch` filter in `report_linker_output` only matched the old ld64 format for object files. With linker-messages promoted to warn-by-default in rust-lang/rust#153968, unfiltered deployment target warnings from dylibs and the new Apple linker (ld_prime) now surface as noise for users who never set `MACOSX_DEPLOYMENT_TARGET`.
Fixesrust-lang/rust#156714.
At present, the filter works only covered the specific format:
`ld: warning: object file (...) was built for newer 'macOS' version (...) than being linked (...)`
This was fine because linker-messages was `Allow-by-default` — nobody saw the other formats anyway. Then rust-lang/rust#153968 promoted it to Warn, and the gaps became visible.
Broadens the filter to cover all known ld deployment target version mismatch formats:
`ld: warning: object file (...)` — old ld64, already handled
`ld: warning: dylib (...)` — old ld64, was missing
All Apple platforms (`iOS`, `tvOS`, `watchOS`, `xrOS`, etc.), not just `macOS`
`ld: building for <platform>-A.B, but linking with dylib '...' which was built for newer version C.D` — new linker (ld_prime, Xcode 15+), the exact format from rust-lang/rust#156714
All matched messages are downgraded to `linker_info` (Allow-by-default), consistent with the existing behavior for the object file case.
Stop needing materialized places for most intrinsics
Today even to return a constant from `size_of_val` it takes an `alloca`. That's wasteful.
This updates the cg_ssa traits to allow returning an `OperandValue` instead, which is possible for the vast majority of intrinsics -- this PR moves all but 5 over to doing that in LLVM.
The first commit adds a test to help show the difference here.
cc https://github.com/rust-lang/compiler-team/issues/970https://github.com/rust-lang/rust/issues/153250