Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Unsafe extern blocks #124482

Merged
merged 12 commits into from
Jun 6, 2024
Merged

Unsafe extern blocks #124482

merged 12 commits into from
Jun 6, 2024

Conversation

spastorino
Copy link
Member

@spastorino spastorino commented Apr 28, 2024

This implements RFC 3484.

Tracking issue #123743 and RFC rust-lang/rfcs#3484

This is better reviewed commit by commit.

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

⚠️ Warning ⚠️

  • These commits modify submodules.

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 28, 2024
@rust-log-analyzer

This comment has been minimized.

@spastorino
Copy link
Member Author

⚠️ Warning ⚠️

* These commits modify **submodules**.

Ohh I forgot to mention this. I'd need to land some PRs, at least to stdarch so it doesn't warn for the usages of extern blocks without unsafe.
I was planning to do ![allow(unknown_lints)] + #![allow(missing_unsafe_on_extern)], so this doesn't warn in new versions and doesn't error in old versions for the usage of missing_unsafe_on_extern which is unknown.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from eff0aa5 to 4db4aac Compare April 29, 2024 19:10
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from 4db4aac to 109be86 Compare April 29, 2024 19:50
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from 109be86 to 429a626 Compare April 29, 2024 21:14
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from 429a626 to b4828d8 Compare April 29, 2024 21:23
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from b4828d8 to e7d5d4e Compare April 29, 2024 21:55
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from e7d5d4e to cc91d7f Compare April 29, 2024 22:32
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from cc91d7f to 542a307 Compare April 29, 2024 22:58
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from 542a307 to 7b82197 Compare April 30, 2024 01:39
@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the unsafe-extern-blocks branch from 7b82197 to 8f0c075 Compare April 30, 2024 02:06
@rust-log-analyzer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2d28b63): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.4%] 32
Regressions ❌
(secondary)
0.2% [0.2%, 0.3%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.4%] 32

Max RSS (memory usage)

Results (primary 0.7%)

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)
4.3% [4.3%, 4.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [-2.9%, 4.3%] 2

Cycles

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

Binary size

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

Bootstrap: 672.766s -> 672.761s (-0.00%)
Artifact size: 319.44 MiB -> 319.40 MiB (-0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Jun 6, 2024
@Kobzol
Copy link
Contributor

Kobzol commented Jun 11, 2024

This adds a new feature, so a small regression is probably to be expected. Marking as triaged.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 11, 2024
@oli-obk oli-obk deleted the unsafe-extern-blocks branch June 11, 2024 07:09
@spastorino
Copy link
Member Author

spastorino commented Jun 11, 2024

This adds a new feature, so a small regression is probably to be expected. Marking as triaged.

@rustbot label: +perf-regression-triaged

👍, anyway there's a pre-existing issue in the way we use ItemKind and convert to ForeignItemKind for the sake of code reuse that this PR made slightly worser and may cause such small perf regression. I have this in my todo list to address.
Basically due to these conversions, we have data in ItemKind that we shouldn't.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 13, 2024
…li-obk

Unsafe extern blocks

This implements RFC 3484.

Tracking issue rust-lang#123743 and RFC rust-lang/rfcs#3484

This is better reviewed commit by commit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 20, 2024
Properly gate `safe` keyword in pre-expansion

This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of rust-lang#126755, which is that `safe` is now usable on beta lol.

r? `@spastorino` or `@oli-obk`

cc rust-lang#124482 tracking rust-lang#123743
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 21, 2024
Properly gate `safe` keyword in pre-expansion

This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of rust-lang#126755, which is that `safe` is now usable on beta lol.

r? ``@spastorino`` or ``@oli-obk``

cc rust-lang#124482 tracking rust-lang#123743
ytmimi added a commit to rust-lang/rustfmt that referenced this pull request Jun 21, 2024
This includes both `ast::StaticItem` and `ast::StaticForeignItem`.
`safety` was added to both `ast::StaticItem` and `ast::SaticForeignItem`
in rust-lang/rust#124482.
ytmimi added a commit to ytmimi/rustfmt that referenced this pull request Jun 21, 2024
This includes both `ast::StaticItem` and `ast::StaticForeignItem`.
`safety` was added to both `ast::StaticItem` and `ast::SaticForeignItem`
in rust-lang/rust#124482.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 21, 2024
Properly gate `safe` keyword in pre-expansion

This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of rust-lang#126755, which is that `safe` is now usable on beta lol.

r? `@spastorino` or `@oli-obk`

cc rust-lang#124482 tracking rust-lang#123743
calebcartwright pushed a commit to rust-lang/rustfmt that referenced this pull request Jun 21, 2024
This includes both `ast::StaticItem` and `ast::StaticForeignItem`.
`safety` was added to both `ast::StaticItem` and `ast::SaticForeignItem`
in rust-lang/rust#124482.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 22, 2024
… r=spastorino

rustdoc: Add support for `missing_unsafe_on_extern` feature

Follow-up of rust-lang#124482.

Not sure if the `safe` keyword is supposed to be displayed or not though? For now I didn't add it in the generated doc, only `unsafe` as usual.

cc `@spastorino`
r? `@fmease`
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 22, 2024
…li-obk

Unsafe extern blocks

This implements RFC 3484.

Tracking issue rust-lang#123743 and RFC rust-lang/rfcs#3484

This is better reviewed commit by commit.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 23, 2024
…rino

rustdoc: Add support for `missing_unsafe_on_extern` feature

Follow-up of rust-lang/rust#124482.

Not sure if the `safe` keyword is supposed to be displayed or not though? For now I didn't add it in the generated doc, only `unsafe` as usual.

cc `@spastorino`
r? `@fmease`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jun 28, 2024
…rino

rustdoc: Add support for `missing_unsafe_on_extern` feature

Follow-up of rust-lang/rust#124482.

Not sure if the `safe` keyword is supposed to be displayed or not though? For now I didn't add it in the generated doc, only `unsafe` as usual.

cc `@spastorino`
r? `@fmease`
tgross35 added a commit to tgross35/rust that referenced this pull request Aug 3, 2024
…-blocks, r=compiler-errors

Stabilize unsafe extern blocks (RFC 3484)

# Stabilization report

## Summary

This is a tracking issue for the RFC 3484: Unsafe Extern Blocks

We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use.

RFC: rust-lang/rfcs#3484
Tracking issue: rust-lang#123743

## What is stabilized

### Summary of stabilization

We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results.

```rust
unsafe extern {
    // sqrt (from libm) may be called with any `f64`
    pub safe fn sqrt(x: f64) -> f64;

    // strlen (from libc) requires a valid pointer,
    // so we mark it as being an unsafe fn
    pub unsafe fn strlen(p: *const c_char) -> usize;

    // this function doesn't say safe or unsafe, so it defaults to unsafe
    pub fn free(p: *mut core::ffi::c_void);

    pub safe static IMPORTANT_BYTES: [u8; 256];

    pub safe static LINES: SyncUnsafeCell<i32>;
}
```

## Tests

The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`.

## History

- rust-lang#124482
- rust-lang#124455
- rust-lang#125077
- rust-lang#125522
- rust-lang#126738
- rust-lang#126749
- rust-lang#126755
- rust-lang#126757
- rust-lang#126758
- rust-lang#126756
- rust-lang#126973
- rust-lang#127535
- rust-lang/rustfmt#6204

## Unresolved questions

I am not aware of any unresolved questions.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 3, 2024
…-blocks, r=compiler-errors

Stabilize unsafe extern blocks (RFC 3484)

# Stabilization report

## Summary

This is a tracking issue for the RFC 3484: Unsafe Extern Blocks

We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use.

RFC: rust-lang/rfcs#3484
Tracking issue: rust-lang#123743

## What is stabilized

### Summary of stabilization

We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results.

```rust
unsafe extern {
    // sqrt (from libm) may be called with any `f64`
    pub safe fn sqrt(x: f64) -> f64;

    // strlen (from libc) requires a valid pointer,
    // so we mark it as being an unsafe fn
    pub unsafe fn strlen(p: *const c_char) -> usize;

    // this function doesn't say safe or unsafe, so it defaults to unsafe
    pub fn free(p: *mut core::ffi::c_void);

    pub safe static IMPORTANT_BYTES: [u8; 256];

    pub safe static LINES: SyncUnsafeCell<i32>;
}
```

## Tests

The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`.

## History

- rust-lang#124482
- rust-lang#124455
- rust-lang#125077
- rust-lang#125522
- rust-lang#126738
- rust-lang#126749
- rust-lang#126755
- rust-lang#126757
- rust-lang#126758
- rust-lang#126756
- rust-lang#126973
- rust-lang#127535
- rust-lang/rustfmt#6204

## Unresolved questions

I am not aware of any unresolved questions.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 3, 2024
Rollup merge of rust-lang#127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors

Stabilize unsafe extern blocks (RFC 3484)

# Stabilization report

## Summary

This is a tracking issue for the RFC 3484: Unsafe Extern Blocks

We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use.

RFC: rust-lang/rfcs#3484
Tracking issue: rust-lang#123743

## What is stabilized

### Summary of stabilization

We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results.

```rust
unsafe extern {
    // sqrt (from libm) may be called with any `f64`
    pub safe fn sqrt(x: f64) -> f64;

    // strlen (from libc) requires a valid pointer,
    // so we mark it as being an unsafe fn
    pub unsafe fn strlen(p: *const c_char) -> usize;

    // this function doesn't say safe or unsafe, so it defaults to unsafe
    pub fn free(p: *mut core::ffi::c_void);

    pub safe static IMPORTANT_BYTES: [u8; 256];

    pub safe static LINES: SyncUnsafeCell<i32>;
}
```

## Tests

The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`.

## History

- rust-lang#124482
- rust-lang#124455
- rust-lang#125077
- rust-lang#125522
- rust-lang#126738
- rust-lang#126749
- rust-lang#126755
- rust-lang#126757
- rust-lang#126758
- rust-lang#126756
- rust-lang#126973
- rust-lang#127535
- rust-lang/rustfmt#6204

## Unresolved questions

I am not aware of any unresolved questions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.