-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
De-underscore @frozen, apply it to structs #24185
De-underscore @frozen, apply it to structs #24185
Conversation
Oops, can you make a PR a draft retroactively? |
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -1354,8 +1354,8 @@ WARNING(pattern_type_not_usable_from_inline_warn,none, | |||
"%select{%select{variable|constant}0|property}1 " | |||
"should be '@usableFromInline' or public", | |||
(bool, bool)) | |||
ERROR(pattern_type_not_usable_from_inline_fixed_layout,none, | |||
"type referenced from a stored property in a '@_fixed_layout' struct must " | |||
ERROR(pattern_type_not_usable_from_inline_frozen,none, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use this diagnostic for classes too? If so it needs a %choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet we do, but it also says "struct" in the message, so…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it was always struct-specific even if it applies to both. I'll happily correct it but I'd like to do that in a follow-on PR than lump it in here.
ce3d92f
to
fadbdb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. Thanks, Ben!
@@ -1932,6 +1932,11 @@ void AttributeChecker::visitSpecializeAttr(SpecializeAttr *attr) { | |||
} | |||
|
|||
void AttributeChecker::visitFixedLayoutAttr(FixedLayoutAttr *attr) { | |||
if (isa<StructDecl>(D)) { | |||
TC.diagnose(attr->getLocation(), diag::fixed_layout_struct) | |||
.fixItReplace(attr->getRange(), "@frozen"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be getRangeWithAt
(or that you should omit the @
from your replacement).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm missing something, this looks right as-is to me:
'@frozen' attribute is now used for fixed-layout structs
@_fixed_layout
^~~~~~~~~~~~~~
@frozen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you weren't seeing
'@frozen' attribute is now used for fixed-layout structs
@_fixed_layout
^~~~~~~~~~~~~~
@frozen
? Which is a different thing. You can test this: expected-warning {{'@frozen' attribute is now used for fixed-layout structs}} {{1-13=@frozen}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A @_fixed_layout public struct FixedDeprecationWarning {} // expected-warning {{'@frozen' attribute is now used for fixed-layout structs}} {{1-15=@frozen}}
test passes.
auto *ED = cast<EnumDecl>(D); | ||
if (auto *ED = dyn_cast<EnumDecl>(D)) { | ||
if (!ED->getModuleContext()->isResilient()) { | ||
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonresilient, attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check probably applies to structs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar thing, this is the existing behavior, so I'd suggest landing and then a follow-up PR can make things more consistent across the two.
fadbdb2
to
41cb6bd
Compare
@swift-ci please test |
@@ -4136,6 +4136,15 @@ ERROR(fixed_layout_attr_on_internal_type, | |||
"%select{private|fileprivate|internal|%error|%error}1", | |||
(DeclName, AccessLevel)) | |||
|
|||
WARNING(fixed_layout_struct, | |||
none, "'@frozen' attribute is now used for fixed-layout structs", ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: please pick either '@frozen'
or 'frozen' attribute
(both here and below); having both is redundant.
Implementation for SE-260
This leaves classes and vars with
@_fixed_layout
for now. It also seems like leaving the compiler using the term "fixed layout" internally makes sense.I've added some tests for the old names, but migrated most of the tests to the new. Not sure if more tests of the old names are merited.
IHaveNoIdeaWhatImDoing.gif, sorry if this doesn't match some conventions.