Skip to content

Support Result<T, E> across FFI when niche optimization can be used (v2) #124747

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 9 commits into from
May 6, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented May 5, 2024

This PR is identical to #122253, which was approved and merged but then removed from master by a force-push due to a CI bug.

r? ghost

Original PR description:


Allow allow enums like Result<T, E> to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of rust-lang/rfcs#3391
Tracking issue: #110503

Additional ABI and codegen tests were added in #115372

Allow allow enums like `Result<T, E>` to be used across FFI if the
T/E can be niche optimized and the non-niche-optimized type is FFI safe.
Fields are disallowed so checking the top attribute is enough.
Tests both `T` and `E` for niche variant optimization lints
Couldn't find documentation supporting that single-variant
`#[repr(Rust)]` enums with RHS assigned work as expected with this
change.

```rust
enum Variants {
  A = 17,
} // Would this be zero sized optimized guaranteed?
```
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2024
@dtolnay
Copy link
Member Author

dtolnay commented May 5, 2024

@bors r=davidtwco

@bors
Copy link
Collaborator

bors commented May 5, 2024

📌 Commit ed532cc has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2024
fmease added a commit to fmease/rust that referenced this pull request May 5, 2024
Support Result<T, E> across FFI when niche optimization can be used (v2)

This PR is identical to rust-lang#122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of rust-lang/rfcs#3391
Tracking issue: rust-lang#110503

Additional ABI and codegen tests were added in rust-lang#115372
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#124146 (Triagebot: Rename `macos` ping group to `apple`)
 - rust-lang#124742 (Add `rustfmt` cfg to well known cfgs list)
 - rust-lang#124745 (Implement lldb formattter for "clang encoded" enums (LLDB 18.1+) (v2))
 - rust-lang#124747 (Support Result<T, E> across FFI when niche optimization can be used (v2))
 - rust-lang#124765 ([rustdoc] Fix bad color for setting cog in ayu theme)
 - rust-lang#124768 ([resubmission] Meta: Enable the brand new triagebot transfer command)

r? `@ghost`
`@rustbot` modify labels: rollup
fmease added a commit to fmease/rust that referenced this pull request May 5, 2024
Support Result<T, E> across FFI when niche optimization can be used (v2)

This PR is identical to rust-lang#122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of rust-lang/rfcs#3391
Tracking issue: rust-lang#110503

Additional ABI and codegen tests were added in rust-lang#115372
bors added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2024
Rollup of 5 pull requests

Successful merges:

 - rust-lang#124742 (Add `rustfmt` cfg to well known cfgs list)
 - rust-lang#124747 (Support Result<T, E> across FFI when niche optimization can be used (v2))
 - rust-lang#124753 (Migrate `run-make/rustdoc-error-lines` to new `rmake.rs`)
 - rust-lang#124765 ([rustdoc] Fix bad color for setting cog in ayu theme)
 - rust-lang#124768 ([resubmission] Meta: Enable the brand new triagebot transfer command)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Collaborator

bors commented May 6, 2024

⌛ Testing commit ed532cc with merge 80420a6...

@bors
Copy link
Collaborator

bors commented May 6, 2024

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 80420a6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 6, 2024
@bors bors merged commit 80420a6 into rust-lang:master May 6, 2024
19 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 6, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (80420a6): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.9% [4.9%, 4.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.0%, 2.2%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 675.885s -> 676.339s (0.07%)
Artifact size: 315.88 MiB -> 315.76 MiB (-0.04%)

@dtolnay dtolnay removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 14, 2025
@dtolnay dtolnay added the A-FFI Area: Foreign function interface (FFI) label Jan 14, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-FFI Area: Foreign function interface (FFI) merged-by-bors This PR was explicitly merged by bors. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants