Skip to content

Commit 5094376

Browse files
committed
Do not restore the precedencegroup name when deserializing them.
We only need to have the identifier during type checking of operator declarations, so we do not need to restore it from the PrecedenceGroupDecl during deserialization. We can just use the deserialized name from the PrecedenceGroupDecl directly if needed. This does result in one change in behavior. When printing modules, we previously didn't print 'DefaultPrecedence' for items that had no precedence specified, but now we will as seen in the test update for IDE/print_ast_tc_decls.swift.
1 parent 25c02ce commit 5094376

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6456,12 +6456,11 @@ class InfixOperatorDecl : public OperatorDecl {
64566456

64576457
InfixOperatorDecl(DeclContext *DC, SourceLoc operatorLoc, Identifier name,
64586458
SourceLoc nameLoc, SourceLoc colonLoc,
6459-
Identifier firstIdentifier, SourceLoc firstIdentifierLoc,
6459+
PrecedenceGroupDecl *precedenceGroup,
64606460
NominalTypeDecl *designatedNominalType)
64616461
: OperatorDecl(DeclKind::InfixOperator, DC, operatorLoc, name, nameLoc,
64626462
designatedNominalType),
6463-
ColonLoc(colonLoc), FirstIdentifierLoc(firstIdentifierLoc),
6464-
FirstIdentifier(firstIdentifier) {}
6463+
ColonLoc(colonLoc), PrecedenceGroup(precedenceGroup) {}
64656464

64666465
SourceLoc getEndLoc() const {
64676466
if (!SecondIdentifier.empty())

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,8 +2873,8 @@ void PrintAST::visitInfixOperatorDecl(InfixOperatorDecl *decl) {
28732873
[&]{
28742874
Printer.printName(decl->getName());
28752875
});
2876-
if (!decl->getFirstIdentifier().empty())
2877-
Printer << " : " << decl->getFirstIdentifier();
2876+
if (auto *group = decl->getPrecedenceGroup())
2877+
Printer << " : " << group->getName();
28782878
if (!decl->getSecondIdentifier().empty())
28792879
Printer << ", " << decl->getSecondIdentifier();
28802880
}

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,15 +3448,9 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
34483448
decls_block::InfixOperatorLayout::readRecord(scratch, nameID, contextID,
34493449
precedenceGroupID, nominalID);
34503450

3451-
PrecedenceGroupDecl *precedenceGroup = nullptr;
3452-
Identifier precedenceGroupName;
3453-
if (precedenceGroupID) {
3454-
precedenceGroup =
3455-
dyn_cast_or_null<PrecedenceGroupDecl>(getDecl(precedenceGroupID));
3456-
if (precedenceGroup) {
3457-
precedenceGroupName = precedenceGroup->getName();
3458-
}
3459-
}
3451+
Expected<Decl *> precedenceGroup = getDeclChecked(precedenceGroupID);
3452+
if (!precedenceGroup)
3453+
return precedenceGroup.takeError();
34603454

34613455
auto DC = getDeclContext(contextID);
34623456

@@ -3466,9 +3460,8 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
34663460

34673461
auto result = createDecl<InfixOperatorDecl>(
34683462
DC, SourceLoc(), getIdentifier(nameID), SourceLoc(), SourceLoc(),
3469-
precedenceGroupName, SourceLoc(),
3463+
cast_or_null<PrecedenceGroupDecl>(precedenceGroup.get()),
34703464
cast_or_null<NominalTypeDecl>(nominal.get()));
3471-
result->setPrecedenceGroup(precedenceGroup);
34723465

34733466
declOrOffset = result;
34743467
break;

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ infix operator %%%
11131113
func %%%(lhs: inout d2601_TestAssignment, rhs: d2601_TestAssignment) -> Int {
11141114
return 0
11151115
}
1116-
// PASS_2500-LABEL: {{^}}infix operator %%%{{$}}
1116+
// PASS_2500-LABEL: {{^}}infix operator %%% : DefaultPrecedence{{$}}
11171117
// PASS_2500: {{^}}func %%% (lhs: inout d2601_TestAssignment, rhs: d2601_TestAssignment) -> Int{{$}}
11181118

11191119
precedencegroup BoringPrecedence {

0 commit comments

Comments
 (0)