Skip to content

Commit 912baa8

Browse files
committed
[Serialization] Use direct operator lookup for xrefs
We don't need to look at re-exports when resolving cross references. Luckily the old lookup logic didn't, but the new logic will. Therefore switch it over to calling the appropriate request for a direct operator lookup. In addition, return a deserialization error instead of silently returning nullptr if the lookup fails.
1 parent 54df0a4 commit 912baa8

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,19 +1364,35 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
13641364
Identifier opName = getIdentifier(IID);
13651365
pathTrace.addOperator(opName);
13661366

1367+
auto &ctx = getContext();
1368+
auto desc = OperatorLookupDescriptor::forModule(baseModule, opName);
13671369
switch (rawOpKind) {
13681370
case OperatorKind::Infix:
1369-
return baseModule->lookupInfixOperator(opName);
13701371
case OperatorKind::Prefix:
1371-
return baseModule->lookupPrefixOperator(opName);
1372-
case OperatorKind::Postfix:
1373-
return baseModule->lookupPostfixOperator(opName);
1374-
case OperatorKind::PrecedenceGroup:
1375-
return baseModule->lookupPrecedenceGroup(opName);
1372+
case OperatorKind::Postfix: {
1373+
auto req = DirectOperatorLookupRequest{
1374+
desc, getASTOperatorFixity(static_cast<OperatorKind>(rawOpKind))};
1375+
auto results = evaluateOrDefault(ctx.evaluator, req, {});
1376+
if (results.size() != 1) {
1377+
return llvm::make_error<XRefError>("operator not found", pathTrace,
1378+
opName);
1379+
}
1380+
return results[0];
1381+
}
1382+
case OperatorKind::PrecedenceGroup: {
1383+
auto results = evaluateOrDefault(
1384+
ctx.evaluator, DirectPrecedenceGroupLookupRequest{desc}, {});
1385+
if (results.size() != 1) {
1386+
return llvm::make_error<XRefError>("precedencegroup not found",
1387+
pathTrace, opName);
1388+
}
1389+
return results[0];
1390+
}
13761391
default:
13771392
// Unknown operator kind.
13781393
fatal();
13791394
}
1395+
llvm_unreachable("Unhandled case in switch!");
13801396
}
13811397

13821398
case XREF_GENERIC_PARAM_PATH_PIECE:

lib/Serialization/ModuleFormat.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,21 @@ static inline OperatorKind getStableFixity(OperatorFixity fixity) {
401401
llvm_unreachable("Unhandled case in switch");
402402
}
403403

404+
/// Translates a stable Serialization fixity back to an AST operator fixity.
405+
static inline OperatorFixity getASTOperatorFixity(OperatorKind fixity) {
406+
switch (fixity) {
407+
case Prefix:
408+
return OperatorFixity::Prefix;
409+
case Postfix:
410+
return OperatorFixity::Postfix;
411+
case Infix:
412+
return OperatorFixity::Infix;
413+
case PrecedenceGroup:
414+
llvm_unreachable("Not an operator kind");
415+
}
416+
llvm_unreachable("Unhandled case in switch");
417+
}
418+
404419
// These IDs must \em not be renumbered or reordered without incrementing
405420
// the module version.
406421
enum GenericRequirementKind : uint8_t {

0 commit comments

Comments
 (0)