Skip to content

Commit 03832cb

Browse files
committed
[NFC] Allow ImportedModuleDesc to be a DenseMap key
1 parent f8df2f6 commit 03832cb

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

include/swift/AST/SourceFile.h

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class SourceFile final : public FileUnit {
5454
/// elsewhere.
5555
///
5656
/// Mutually exclusive with Exported.
57-
ImplementationOnly = 0x8
57+
ImplementationOnly = 0x8,
58+
59+
/// Used for DenseMap.
60+
Reserved = 0x80
5861
};
5962

6063
/// \see ImportFlags
@@ -69,7 +72,8 @@ class SourceFile final : public FileUnit {
6972
StringRef filename = {})
7073
: module(module), importOptions(options), filename(filename) {
7174
assert(!(importOptions.contains(ImportFlags::Exported) &&
72-
importOptions.contains(ImportFlags::ImplementationOnly)));
75+
importOptions.contains(ImportFlags::ImplementationOnly)) ||
76+
importOptions.contains(ImportFlags::Reserved));
7377
}
7478
};
7579

@@ -542,4 +546,58 @@ inline void simple_display(llvm::raw_ostream &out, const SourceFile *SF) {
542546
}
543547
} // end namespace swift
544548

549+
namespace llvm {
550+
551+
template<>
552+
struct DenseMapInfo<swift::SourceFile::ImportOptions> {
553+
using ImportOptions = swift::SourceFile::ImportOptions;
554+
555+
using UnsignedDMI = DenseMapInfo<uint8_t>;
556+
557+
static inline ImportOptions getEmptyKey() {
558+
return ImportOptions(UnsignedDMI::getEmptyKey());
559+
}
560+
static inline ImportOptions getTombstoneKey() {
561+
return ImportOptions(UnsignedDMI::getTombstoneKey());
562+
}
563+
static inline unsigned getHashValue(ImportOptions options) {
564+
return UnsignedDMI::getHashValue(options.toRaw());
565+
}
566+
static bool isEqual(ImportOptions a, ImportOptions b) {
567+
return UnsignedDMI::isEqual(a.toRaw(), b.toRaw());
568+
}
569+
};
570+
571+
template<>
572+
struct DenseMapInfo<swift::SourceFile::ImportedModuleDesc> {
573+
using ImportedModuleDesc = swift::SourceFile::ImportedModuleDesc;
574+
575+
using ImportedModuleDMI = DenseMapInfo<swift::ModuleDecl::ImportedModule>;
576+
using ImportOptionsDMI = DenseMapInfo<swift::SourceFile::ImportOptions>;
577+
using StringRefDMI = DenseMapInfo<StringRef>;
578+
579+
static inline ImportedModuleDesc getEmptyKey() {
580+
return ImportedModuleDesc(ImportedModuleDMI::getEmptyKey(),
581+
ImportOptionsDMI::getEmptyKey(),
582+
StringRefDMI::getEmptyKey());
583+
}
584+
static inline ImportedModuleDesc getTombstoneKey() {
585+
return ImportedModuleDesc(ImportedModuleDMI::getTombstoneKey(),
586+
ImportOptionsDMI::getTombstoneKey(),
587+
StringRefDMI::getTombstoneKey());
588+
}
589+
static inline unsigned getHashValue(const ImportedModuleDesc &import) {
590+
return combineHashValue(ImportedModuleDMI::getHashValue(import.module),
591+
combineHashValue(ImportOptionsDMI::getHashValue(import.importOptions),
592+
StringRefDMI::getHashValue(import.filename)));
593+
}
594+
static bool isEqual(const ImportedModuleDesc &a,
595+
const ImportedModuleDesc &b) {
596+
return ImportedModuleDMI::isEqual(a.module, b.module) &&
597+
ImportOptionsDMI::isEqual(a.importOptions, b.importOptions) &&
598+
StringRefDMI::isEqual(a.filename, b.filename);
599+
}
600+
};
601+
}
602+
545603
#endif

include/swift/Basic/OptionSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class OptionSet {
8888
}
8989

9090
/// Check if this option set contains the exact same options as the given set.
91-
bool containsOnly(OptionSet set) {
91+
bool containsOnly(OptionSet set) const {
9292
return Storage == set.Storage;
9393
}
9494

0 commit comments

Comments
 (0)