Skip to content

Commit dc055bf

Browse files
committed
[NFC] Add flag distinguishing @impl and @objcImpl
They will have slightly different enablement and diagnostic behavior in a future commit.
1 parent 8b72b9a commit dc055bf

File tree

9 files changed

+41
-18
lines changed

9 files changed

+41
-18
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ BridgedObjCAttr BridgedObjCAttr_createParsedSelector(
625625
BridgedArrayRef cNameLocs, BridgedArrayRef cNames,
626626
BridgedSourceLoc cRParenLoc);
627627

628-
SWIFT_NAME("BridgedObjCImplementationAttr.createParsed(_:atLoc:range:name:)")
628+
SWIFT_NAME("BridgedObjCImplementationAttr.createParsed(_:atLoc:range:name:isEarlyAdopter:)")
629629
BridgedObjCImplementationAttr BridgedObjCImplementationAttr_createParsed(
630630
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
631-
BridgedSourceRange cRange, BridgedIdentifier cName);
631+
BridgedSourceRange cRange, BridgedIdentifier cName, bool isEarlyAdopter);
632632

633633
SWIFT_NAME("BridgedObjCRuntimeNameAttr.createParsed(_:atLoc:range:name:)")
634634
BridgedObjCRuntimeNameAttr BridgedObjCRuntimeNameAttr_createParsed(

include/swift/AST/Attr.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ class DeclAttribute : public AttributeBase {
184184
isUnchecked : 1
185185
);
186186

187-
SWIFT_INLINE_BITFIELD(ObjCImplementationAttr, DeclAttribute, 1,
188-
isCategoryNameInvalid : 1
187+
SWIFT_INLINE_BITFIELD(ObjCImplementationAttr, DeclAttribute, 2,
188+
isCategoryNameInvalid : 1,
189+
isEarlyAdopter : 1
189190
);
190191

191192
SWIFT_INLINE_BITFIELD(NonisolatedAttr, DeclAttribute, 1,
@@ -2424,11 +2425,19 @@ class ObjCImplementationAttr final : public DeclAttribute {
24242425
Identifier CategoryName;
24252426

24262427
ObjCImplementationAttr(Identifier CategoryName, SourceLoc AtLoc,
2427-
SourceRange Range, bool Implicit = false,
2428+
SourceRange Range, bool isEarlyAdopter = false,
2429+
bool Implicit = false,
24282430
bool isCategoryNameInvalid = false)
24292431
: DeclAttribute(DeclAttrKind::ObjCImplementation, AtLoc, Range, Implicit),
24302432
CategoryName(CategoryName) {
24312433
Bits.ObjCImplementationAttr.isCategoryNameInvalid = isCategoryNameInvalid;
2434+
Bits.ObjCImplementationAttr.isEarlyAdopter = isEarlyAdopter;
2435+
}
2436+
2437+
/// Early adopters use the \c \@_objcImplementation spelling. For backwards
2438+
/// compatibility, issues with them are diagnosed as warnings, not errors.
2439+
bool isEarlyAdopter() const {
2440+
return Bits.ObjCImplementationAttr.isEarlyAdopter;
24322441
}
24332442

24342443
bool isCategoryNameInvalid() const {

lib/AST/ASTBridging.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,10 @@ BridgedObjCAttr BridgedObjCAttr_createParsedSelector(
662662

663663
BridgedObjCImplementationAttr BridgedObjCImplementationAttr_createParsed(
664664
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
665-
BridgedSourceRange cRange, BridgedIdentifier cName) {
665+
BridgedSourceRange cRange, BridgedIdentifier cName, bool isEarlyAdopter) {
666666
return new (cContext.unbridged()) ObjCImplementationAttr(
667-
cName.unbridged(), cAtLoc.unbridged(), cRange.unbridged());
667+
cName.unbridged(), cAtLoc.unbridged(), cRange.unbridged(),
668+
isEarlyAdopter);
668669
}
669670

670671
BridgedObjCRuntimeNameAttr BridgedObjCRuntimeNameAttr_createParsed(

lib/AST/Attr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,9 @@ StringRef DeclAttribute::getAttrName() const {
18201820
case DeclAttrKind::ObjCRuntimeName:
18211821
return "objc";
18221822
case DeclAttrKind::ObjCImplementation:
1823-
return "_objcImplementation";
1823+
if (cast<ObjCImplementationAttr>(this)->isEarlyAdopter())
1824+
return "_objcImplementation";
1825+
return "implementation";
18241826
case DeclAttrKind::MainType:
18251827
return "main";
18261828
case DeclAttrKind::DynamicReplacement:

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,25 @@ extension ASTGenVisitor {
732732
}
733733

734734
func generateObjCImplementationAttr(attribute node: AttributeSyntax) -> BridgedObjCImplementationAttr? {
735-
let name: BridgedIdentifier? = self.generateSingleAttrOption(attribute: node) {
736-
self.generateIdentifier($0)
737-
}
735+
let name: BridgedIdentifier? = self.generateSingleAttrOption(
736+
attribute: node,
737+
self.generateIdentifier,
738+
valueIfOmitted: BridgedIdentifier()
739+
)
738740
guard let name else {
739-
// TODO: Diagnose.
741+
// Should be diagnosed by `generateSingleAttrOption`.
740742
return nil
741743
}
742744

745+
let attrName = node.attributeName.as(IdentifierTypeSyntax.self)?.name.text
746+
let isEarlyAdopter = attrName != "implementation"
747+
743748
return .createParsed(
744749
self.ctx,
745750
atLoc: self.generateSourceLoc(node.atSign),
746751
range: self.generateSourceRange(node),
747-
name: name
752+
name: name,
753+
isEarlyAdopter: isEarlyAdopter
748754
)
749755
}
750756

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,9 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36403640
if (!name)
36413641
return makeParserSuccess();
36423642

3643-
Attributes.add(new (Context) ObjCImplementationAttr(*name, AtLoc, range));
3643+
bool isEarlyAdopter = (AttrName != "implementation");
3644+
Attributes.add(new (Context) ObjCImplementationAttr(*name, AtLoc, range,
3645+
isEarlyAdopter));
36443646
break;
36453647
}
36463648
case DeclAttrKind::ObjCRuntimeName: {

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6127,13 +6127,15 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
61276127
case decls_block::ObjCImplementation_DECL_ATTR: {
61286128
bool isImplicit;
61296129
bool isCategoryNameInvalid;
6130+
bool isEarlyAdopter;
61306131
uint64_t categoryNameID;
61316132
serialization::decls_block::ObjCImplementationDeclAttrLayout::
61326133
readRecord(scratch, isImplicit, isCategoryNameInvalid,
6133-
categoryNameID);
6134+
isEarlyAdopter, categoryNameID);
61346135
Identifier categoryName = MF.getIdentifier(categoryNameID);
61356136
Attr = new (ctx) ObjCImplementationAttr(categoryName, SourceLoc(),
6136-
SourceRange(), isImplicit,
6137+
SourceRange(), isEarlyAdopter,
6138+
isImplicit,
61376139
isCategoryNameInvalid);
61386140
break;
61396141
}

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 867; // _distributed_get accessor for distributed thunks
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 868; // @implementation
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -2314,6 +2314,7 @@ namespace decls_block {
23142314
ObjCImplementation_DECL_ATTR,
23152315
BCFixed<1>, // implicit flag
23162316
BCFixed<1>, // category name invalid
2317+
BCFixed<1>, // is early adopter
23172318
IdentifierIDField // category name
23182319
>;
23192320

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2947,7 +2947,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
29472947
S.DeclTypeAbbrCodes[ObjCImplementationDeclAttrLayout::Code];
29482948
ObjCImplementationDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord,
29492949
abbrCode, theAttr->isImplicit(), theAttr->isCategoryNameInvalid(),
2950-
categoryNameID);
2950+
theAttr->isEarlyAdopter(), categoryNameID);
29512951
return;
29522952
}
29532953

0 commit comments

Comments
 (0)