diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 8ba0d7b3856..956edb105d1 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -6287,6 +6287,12 @@ public: DesignatedProtocolName(DesignatedProtocolName), DesignatedProtocolNameLoc(DesignatedProtocolNameLoc) {} + OperatorDecl(DeclKind kind, DeclContext *DC, SourceLoc OperatorLoc, + Identifier Name, SourceLoc NameLoc, + ProtocolDecl *DesignatedProtocol) + : Decl(kind, DC), OperatorLoc(OperatorLoc), NameLoc(NameLoc), name(Name), + DesignatedProtocol(DesignatedProtocol) {} + SourceLoc getLoc() const { return NameLoc; } SourceLoc getOperatorLoc() const { return OperatorLoc; } @@ -6337,6 +6343,15 @@ public: SecondIdentifierLoc(secondIdentifierLoc), FirstIdentifier(firstIdentifier), SecondIdentifier(secondIdentifier) {} + InfixOperatorDecl(DeclContext *DC, SourceLoc operatorLoc, Identifier name, + SourceLoc nameLoc, SourceLoc colonLoc, + Identifier firstIdentifier, SourceLoc firstIdentifierLoc, + ProtocolDecl *designatedProtocol) + : OperatorDecl(DeclKind::InfixOperator, DC, operatorLoc, name, nameLoc, + designatedProtocol), + ColonLoc(colonLoc), FirstIdentifierLoc(firstIdentifierLoc), + FirstIdentifier(firstIdentifier) {} + SourceLoc getEndLoc() const { if (!SecondIdentifier.empty()) return SecondIdentifierLoc; @@ -6385,6 +6400,11 @@ public: : OperatorDecl(DeclKind::PrefixOperator, DC, OperatorLoc, Name, NameLoc, DesignatedProtocolName, DesignatedProtocolNameLoc) {} + PrefixOperatorDecl(DeclContext *DC, SourceLoc OperatorLoc, Identifier Name, + SourceLoc NameLoc, ProtocolDecl *DesignatedProtocol) + : OperatorDecl(DeclKind::PrefixOperator, DC, OperatorLoc, Name, NameLoc, + DesignatedProtocol) {} + SourceRange getSourceRange() const { return { getOperatorLoc(), getNameLoc() }; } @@ -6414,6 +6434,11 @@ public: : OperatorDecl(DeclKind::PostfixOperator, DC, OperatorLoc, Name, NameLoc, DesignatedProtocolName, DesignatedProtocolNameLoc) {} + PostfixOperatorDecl(DeclContext *DC, SourceLoc OperatorLoc, Identifier Name, + SourceLoc NameLoc, ProtocolDecl *DesignatedProtocol) + : OperatorDecl(DeclKind::PostfixOperator, DC, OperatorLoc, Name, NameLoc, + DesignatedProtocol) {} + SourceRange getSourceRange() const { return { getOperatorLoc(), getNameLoc() }; } diff --git a/include/swift/Serialization/ModuleFormat.h b/include/swift/Serialization/ModuleFormat.h index 514800a6b1f..266288d3a10 100644 --- a/include/swift/Serialization/ModuleFormat.h +++ b/include/swift/Serialization/ModuleFormat.h @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -55,7 +55,7 @@ const uint16_t VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t VERSION_MINOR = 441; // Last change: remove end_borrow src arg +const uint16_t VERSION_MINOR = 442; // Last change: operator protocol using DeclIDField = BCFixed<31>; @@ -1089,8 +1089,9 @@ namespace decls_block { template using UnaryOperatorLayout = BCRecordLayout< Code, // ID field - IdentifierIDField, // name - DeclContextIDField // context decl + IdentifierIDField, // name + DeclContextIDField, // context decl + DeclIDField // protocol >; using PrefixOperatorLayout = UnaryOperatorLayout; @@ -1100,7 +1101,8 @@ namespace decls_block { INFIX_OPERATOR_DECL, IdentifierIDField, // name DeclContextIDField,// context decl - DeclIDField // precedence group + DeclIDField, // precedence group + DeclIDField // protocol >; using PrecedenceGroupLayout = BCRecordLayout< diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index c887a7d34b2..639a7f94902 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -3378,27 +3378,43 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) { case decls_block::PREFIX_OPERATOR_DECL: { IdentifierID nameID; DeclContextID contextID; + DeclID protoID; - decls_block::PrefixOperatorLayout::readRecord(scratch, nameID, - contextID); + decls_block::PrefixOperatorLayout::readRecord(scratch, nameID, contextID, + protoID); auto DC = getDeclContext(contextID); - declOrOffset = createDecl(DC, SourceLoc(), - getIdentifier(nameID), - SourceLoc()); + + Expected protocol = getDeclChecked(protoID); + if (!protocol) + return protocol.takeError(); + + auto result = createDecl( + DC, SourceLoc(), getIdentifier(nameID), SourceLoc(), + cast_or_null(protocol.get())); + + declOrOffset = result; break; } case decls_block::POSTFIX_OPERATOR_DECL: { IdentifierID nameID; DeclContextID contextID; + DeclID protoID; - decls_block::PostfixOperatorLayout::readRecord(scratch, nameID, - contextID); + decls_block::PostfixOperatorLayout::readRecord(scratch, nameID, contextID, + protoID); auto DC = getDeclContext(contextID); - declOrOffset = createDecl(DC, SourceLoc(), - getIdentifier(nameID), - SourceLoc()); + + Expected protocol = getDeclChecked(protoID); + if (!protocol) + return protocol.takeError(); + + auto result = createDecl( + DC, SourceLoc(), getIdentifier(nameID), SourceLoc(), + cast_or_null(protocol.get())); + + declOrOffset = result; break; } @@ -3406,9 +3422,10 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) { IdentifierID nameID; DeclContextID contextID; DeclID precedenceGroupID; + DeclID protoID; decls_block::InfixOperatorLayout::readRecord(scratch, nameID, contextID, - precedenceGroupID); + precedenceGroupID, protoID); PrecedenceGroupDecl *precedenceGroup = nullptr; Identifier precedenceGroupName; @@ -3422,11 +3439,14 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) { auto DC = getDeclContext(contextID); - auto result = createDecl(DC, SourceLoc(), - getIdentifier(nameID), - SourceLoc(), SourceLoc(), - precedenceGroupName, - SourceLoc()); + Expected protocol = getDeclChecked(protoID); + if (!protocol) + return protocol.takeError(); + + auto result = createDecl( + DC, SourceLoc(), getIdentifier(nameID), SourceLoc(), SourceLoc(), + precedenceGroupName, SourceLoc(), + cast_or_null(protocol.get())); result->setPrecedenceGroup(precedenceGroup); declOrOffset = result; diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 596bf377665..6966550ad98 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2819,10 +2819,11 @@ void Serializer::writeDecl(const Decl *D) { auto contextID = addDeclContextRef(op->getDeclContext()); auto nameID = addDeclBaseNameRef(op->getName()); auto groupID = addDeclRef(op->getPrecedenceGroup()); + auto protoID = addDeclRef(op->getDesignatedProtocol()); unsigned abbrCode = DeclTypeAbbrCodes[InfixOperatorLayout::Code]; - InfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode, - nameID, contextID, groupID); + InfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode, nameID, + contextID, groupID, protoID); break; } @@ -2831,11 +2832,12 @@ void Serializer::writeDecl(const Decl *D) { verifyAttrSerializable(op); auto contextID = addDeclContextRef(op->getDeclContext()); + auto protoID = addDeclRef(op->getDesignatedProtocol()); unsigned abbrCode = DeclTypeAbbrCodes[PrefixOperatorLayout::Code]; PrefixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode, addDeclBaseNameRef(op->getName()), - contextID); + contextID, protoID); break; } @@ -2844,11 +2846,12 @@ void Serializer::writeDecl(const Decl *D) { verifyAttrSerializable(op); auto contextID = addDeclContextRef(op->getDeclContext()); + auto protoID = addDeclRef(op->getDesignatedProtocol()); unsigned abbrCode = DeclTypeAbbrCodes[PostfixOperatorLayout::Code]; PostfixOperatorLayout::emitRecord(Out, ScratchRecord, abbrCode, addDeclBaseNameRef(op->getName()), - contextID); + contextID, protoID); break; }