23
23
#include " swift/Parse/PersistentParserState.h"
24
24
#include " swift/Subsystems.h"
25
25
#include " llvm/Support/MemoryBuffer.h"
26
+ #include " llvm/ADT/Hashing.h"
26
27
27
28
using namespace swift ;
28
29
using namespace ide ;
@@ -124,6 +125,73 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
124
125
125
126
return newDC;
126
127
}
128
+
129
+ // / Calculate the hash value of the \c CompilerInvocation.
130
+ // / This should take all options affecting completion results into account.
131
+ // / If the hashes between multiple completion invocation are different, we
132
+ // / cannot reuse the CompilerInstance.
133
+ static llvm::hash_code calculateInvocationHash (const CompilerInvocation &Inv) {
134
+ llvm::hash_code hash (0 );
135
+
136
+ auto &frontendOpts = Inv.getFrontendOptions ();
137
+ for (const InputFile &Input : frontendOpts.InputsAndOutputs .getAllInputs ())
138
+ hash = llvm::hash_combine (hash, Input.file ());
139
+ hash = llvm::hash_combine (
140
+ hash,
141
+ frontendOpts.InputKind ,
142
+ llvm::makeArrayRef (frontendOpts.ImplicitImportModuleNames ),
143
+ frontendOpts.ImplicitObjCHeaderPath ,
144
+ frontendOpts.ModuleName ,
145
+ frontendOpts.PrebuiltModuleCachePath ,
146
+ llvm::makeArrayRef (frontendOpts.PreferInterfaceForModules ),
147
+ frontendOpts.ParseStdlib ,
148
+ frontendOpts.EnableSourceImport ,
149
+ frontendOpts.ImportUnderlyingModule );
150
+
151
+ auto &langOpts = Inv.getLangOptions ();
152
+ hash = llvm::hash_combine (
153
+ hash,
154
+ langOpts.Target .str (),
155
+ llvm::VersionTuple (langOpts.EffectiveLanguageVersion ).getAsString (),
156
+ llvm::VersionTuple (langOpts.PackageDescriptionVersion ).getAsString (),
157
+ langOpts.DisableAvailabilityChecking ,
158
+ langOpts.EnableAccessControl ,
159
+ langOpts.EnableAppExtensionRestrictions ,
160
+ langOpts.RequireExplicitAvailability ,
161
+ langOpts.RequireExplicitAvailabilityTarget ,
162
+ langOpts.EnableObjCInterop ,
163
+ langOpts.EnableCXXInterop ,
164
+ langOpts.InferImportAsMember ,
165
+ langOpts.EnableSwift3ObjCInference );
166
+
167
+ auto &searchPathOpts = Inv.getSearchPathOptions ();
168
+ hash = llvm::hash_combine (
169
+ hash,
170
+ searchPathOpts.SDKPath ,
171
+ llvm::makeArrayRef (searchPathOpts.ImportSearchPaths ),
172
+ llvm::makeArrayRef (searchPathOpts.VFSOverlayFiles ),
173
+ searchPathOpts.RuntimeResourcePath ,
174
+ llvm::makeArrayRef (searchPathOpts.RuntimeLibraryImportPaths ),
175
+ llvm::makeArrayRef (searchPathOpts.SkipRuntimeLibraryImportPaths ));
176
+ for (auto &P : searchPathOpts.FrameworkSearchPaths )
177
+ hash = llvm::hash_combine (hash, P.IsSystem , P.Path );
178
+
179
+ auto &clangOpts = Inv.getClangImporterOptions ();
180
+ hash = llvm::hash_combine (
181
+ hash,
182
+ clangOpts.ModuleCachePath ,
183
+ llvm::makeArrayRef (clangOpts.ExtraArgs ),
184
+ clangOpts.OverrideResourceDir ,
185
+ clangOpts.TargetCPU ,
186
+ static_cast <uint8_t >(clangOpts.Mode ),
187
+ clangOpts.ImportForwardDeclarations ,
188
+ clangOpts.InferImportAsMember ,
189
+ clangOpts.DisableSwiftBridgeAttr ,
190
+ clangOpts.DisableOverlayModules );
191
+
192
+ return hash;
193
+ }
194
+
127
195
} // namespace
128
196
129
197
CompilerInstance *CompletionInstance::getReusingCompilerInstance (
@@ -136,7 +204,8 @@ CompilerInstance *CompletionInstance::getReusingCompilerInstance(
136
204
if (!CachedCI)
137
205
return nullptr ;
138
206
139
- if (Invocation.getPCHHash () != CachedCI->getInvocation ().getPCHHash ())
207
+ if (calculateInvocationHash (Invocation) !=
208
+ calculateInvocationHash (CachedCI->getInvocation ()))
140
209
return nullptr ;
141
210
142
211
auto &oldState = CachedCI->getPersistentParserState ();
0 commit comments