-
Notifications
You must be signed in to change notification settings - Fork 10.5k
De-underscore @frozen, apply it to structs #24185
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1388,8 +1388,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, | ||
"type referenced from a stored property in a '@frozen' struct must " | ||
"be '@usableFromInline' or public", | ||
(/*ignored*/bool, /*ignored*/bool)) | ||
ERROR(pattern_type_not_usable_from_inline_inferred,none, | ||
|
@@ -1404,9 +1404,9 @@ WARNING(pattern_type_not_usable_from_inline_inferred_warn,none, | |
"with inferred type %2 " | ||
"should be '@usableFromInline' or public", | ||
(bool, bool, Type)) | ||
ERROR(pattern_type_not_usable_from_inline_inferred_fixed_layout,none, | ||
ERROR(pattern_type_not_usable_from_inline_inferred_frozen,none, | ||
"type referenced from a stored property with inferred type %2 in a " | ||
"'@_fixed_layout' struct must be '@usableFromInline' or public", | ||
"'@frozen' struct must be '@usableFromInline' or public", | ||
(/*ignored*/bool, /*ignored*/bool, Type)) | ||
|
||
ERROR(pattern_binds_no_variables,none, | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: please pick either |
||
|
||
ERROR(frozen_attr_on_internal_type, | ||
none, "'@frozen' attribute can only be applied to '@usableFromInline' " | ||
"or public declarations, but %0 is " | ||
"%select{private|fileprivate|internal|%error|%error}1", | ||
(DeclName, AccessLevel)) | ||
|
||
ERROR(usable_from_inline_attr_with_explicit_access, | ||
none, "'@usableFromInline' attribute can only be applied to internal " | ||
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1", | ||
|
@@ -4152,7 +4161,7 @@ ERROR(usable_from_inline_attr_in_protocol,none, | |
"an '@inlinable' function|" \ | ||
"an '@_alwaysEmitIntoClient' function|" \ | ||
"a default argument value|" \ | ||
"a property initializer in a '@_fixed_layout' type}" | ||
"a property initializer in a '@frozen' type}" | ||
|
||
#define DECL_OR_ACCESSOR "%select{%0|%0 for}" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1957,6 +1957,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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you weren't seeing
? Which is a different thing. You can test this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A |
||
} | ||
|
||
auto *VD = cast<ValueDecl>(D); | ||
|
||
if (VD->getFormalAccess() < AccessLevel::Public && | ||
|
@@ -2462,16 +2467,25 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) { | |
} | ||
|
||
void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) { | ||
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 commentThe 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 commentThe 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 commentThe 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. |
||
return; | ||
} | ||
|
||
if (!ED->getModuleContext()->isResilient()) { | ||
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonresilient, attr); | ||
return; | ||
if (ED->getFormalAccess() < AccessLevel::Public && | ||
!ED->getAttrs().hasAttribute<UsableFromInlineAttr>()) { | ||
jrose-apple marked this conversation as resolved.
Show resolved
Hide resolved
|
||
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonpublic, attr); | ||
return; | ||
} | ||
} | ||
|
||
if (ED->getFormalAccess() < AccessLevel::Public && | ||
!ED->getAttrs().hasAttribute<UsableFromInlineAttr>()) { | ||
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonpublic, attr); | ||
auto *VD = cast<ValueDecl>(D); | ||
|
||
if (VD->getFormalAccess() < AccessLevel::Public && | ||
!VD->getAttrs().hasAttribute<UsableFromInlineAttr>()) { | ||
diagnoseAndRemoveAttr(attr, diag::frozen_attr_on_internal_type, | ||
VD->getFullName(), VD->getFormalAccess()); | ||
} | ||
} | ||
|
||
|
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.