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

Add new safety enum for inner extern items #124455

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

spastorino
Copy link
Member

This is in preparation for unsafe extern blocks that adds a safe variant for functions inside extern blocks.

r? @compiler-errors

@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 Apr 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 27, 2024

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in need_type_info.rs

cc @lcnr

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

HIR ty lowering was modified

cc @fmease

@spastorino spastorino force-pushed the add-new-fnsafety-enum branch 2 times, most recently from a01142f to 0a2dee6 Compare April 27, 2024 23:28
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 27, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Apr 28, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@oli-obk
Copy link
Contributor

oli-obk commented Apr 28, 2024

Why aren't we expanding the Unsafe enum instead? Is that too annoying for the places where Safe can't occur?

@spastorino
Copy link
Member Author

Why aren't we expanding the Unsafe enum instead? Is that too annoying for the places where Safe can't occur?

My reasoning was not only this but also so things can be a bit safer as we won't need to handle safe when it basically can't happen.

@spastorino spastorino mentioned this pull request Apr 28, 2024
5 tasks
@spastorino
Copy link
Member Author

I'm having second thoughts about naming this FnSafety maybe just Safety is better as this is going to be applied to fns and statics.

#[derive(HashStable_Generic)]
pub enum FnSafety {
Unsafe(Span),
Default,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name this Inherited or FromContext. Without an explanation it's not obvious what this is supposed to be

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've used Default as a way of saying no safety explicitly written means is going to take a default value.
Another possible name could be Implicit.
Out of all the values mentioned I slightly prefer Default but I don't mind changing it neither.
Another name we are using is Normal which I also think is not great, but it is another option.
Let's see if somebody else have some thought about this.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 29, 2024

I'm having second thoughts about naming this FnSafety maybe just Safety is better as this is going to be applied to fns and statics.

Yea, just naming it Safety is fine as long as there's an explanation why it's different from Unsafe

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the add-new-fnsafety-enum branch 2 times, most recently from fdee834 to bd43f67 Compare April 29, 2024 13:55
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@spastorino spastorino force-pushed the add-new-fnsafety-enum branch 2 times, most recently from 3824cb3 to 6b76cac Compare April 29, 2024 17:40
@spastorino spastorino changed the title Add new fn safety enum for functions Add new safety enum for inner extern items Apr 30, 2024
@bors
Copy link
Contributor

bors commented May 2, 2024

☔ The latest upstream changes (presumably #124621) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 4, 2024

☔ The latest upstream changes (presumably #123602) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -913,10 +913,16 @@ pub enum Mutability {
Mut,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add documentation to these two enumerations? It isn't clear to me why we need two different enumerations here.

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Safety {
Unsafe,
Normal,
Default,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we already know if a function / static is safe or unsafe by the time we are translating to StableMIR? If so, wouldn't it be better to keep Unsafe / Safe (Normal)?

I'm assuming that the way this is designed today, the Default value will require users to perform an extra query to know the context where this Fn / Static was declared to know whether it is safe or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is just a suggestion. I know this is a big change already. If it makes sense, maybe just add a fixme comment for us to improve this later. Thanks

@spastorino
Copy link
Member Author

spastorino commented May 13, 2024

I'm going to wait on a review and decision about this or #125077 or any other alternative before solving the conflicts and @celinval's thoughts as it is a lot of work to keep all these in a mergeable state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants