Skip to content

Commit fe0046b

Browse files
committed
Parser: calculating interface hash only for primary files.
1 parent b2538e9 commit fe0046b

22 files changed

+55
-47
lines changed

include/swift/AST/Module.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,8 @@ class SourceFile final : public FileUnit {
873873

874874
/// A hash of all interface-contributing tokens that have been lexed for
875875
/// this source file so far.
876-
llvm::MD5 InterfaceHash;
876+
/// We only collect interface hash for primary input files.
877+
llvm::Optional<llvm::MD5> InterfaceHash;
877878

878879
/// \brief The ID for the memory buffer containing this file's source.
879880
///
@@ -1117,20 +1118,26 @@ class SourceFile final : public FileUnit {
11171118
/// Set the root refinement context for the file.
11181119
void setTypeRefinementContext(TypeRefinementContext *TRC);
11191120

1121+
void enableInterfaceHash() {
1122+
assert(!hasInterfaceHash());
1123+
InterfaceHash.emplace();
1124+
}
1125+
1126+
bool hasInterfaceHash() const {
1127+
return InterfaceHash.hasValue();
1128+
}
1129+
11201130
void recordInterfaceToken(StringRef token) {
11211131
assert(!token.empty());
1122-
InterfaceHash.update(token);
1132+
InterfaceHash->update(token);
11231133
// Add null byte to separate tokens.
11241134
uint8_t a[1] = {0};
1125-
InterfaceHash.update(a);
1135+
InterfaceHash->update(a);
11261136
}
11271137

1128-
const llvm::MD5 &getInterfaceHashState() { return InterfaceHash; }
1129-
void setInterfaceHashState(const llvm::MD5 &state) { InterfaceHash = state; }
1130-
11311138
void getInterfaceHash(llvm::SmallString<32> &str) {
11321139
llvm::MD5::MD5Result result;
1133-
InterfaceHash.final(result);
1140+
InterfaceHash->final(result);
11341141
llvm::MD5::stringifyResult(result, str);
11351142
}
11361143

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
128128
void CompilerInstance::recordPrimarySourceFile(SourceFile *SF) {
129129
assert(MainModule && "main module not created yet");
130130
PrimarySourceFiles.push_back(SF);
131+
SF->enableInterfaceHash();
131132
SF->createReferencedNameTracker();
132133
if (SF->getBufferID().hasValue())
133134
recordPrimaryInputBuffer(SF->getBufferID().getValue());

lib/ParseSIL/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ bool swift::parseIntoSourceFile(SourceFile &SF,
117117
Parser P(BufferID, SF, SIL ? SIL->Impl.get() : nullptr, PersistentState);
118118
PrettyStackTraceParser StackTrace(P);
119119

120-
llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens, true);
121-
120+
llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens,
121+
SF.hasInterfaceHash());
122122
if (DelayedParseCB)
123123
P.setDelayedParsingCallbacks(DelayedParseCB);
124124

test/InterfaceHash/added_function.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_localfunc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_method.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_class_private_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_class_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_enum_private_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_enum_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_method.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_method_value_types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_protocol_method.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_protocol_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_struct_private_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/added_private_struct_property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/changed_private_var_type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/changed_var_name.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/changed_var_type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/edited_function_body.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/edited_method_body.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

test/InterfaceHash/edited_property_getter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
3-
// RUN: %target-swift-frontend -dump-interface-hash %t/a.swift 2> %t/a.hash
4-
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift 2> %t/b.hash
3+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/a.swift 2> %t/a.hash
4+
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: cmp %t/a.hash %t/b.hash
66

77
// BEGIN a.swift

0 commit comments

Comments
 (0)