Skip to content

Commit 3902cbc

Browse files
committed
Merge branch 'swift-5.1-branch' into fix/SR-10992-5.1
2 parents b47b64a + bf61952 commit 3902cbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+781
-574
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ ERROR(unsupported_version_of_module_interface,none,
281281
(StringRef, llvm::VersionTuple))
282282
ERROR(error_extracting_flags_from_module_interface,none,
283283
"error extracting flags from module interface", ())
284-
ERROR(missing_dependency_of_module_interface,none,
285-
"missing dependency '%0' of module interface '%1': %2",
286-
(StringRef, StringRef, StringRef))
287284
REMARK(rebuilding_module_from_interface,none,
288285
"rebuilding module '%0' from interface '%1'", (StringRef, StringRef))
289286
NOTE(out_of_date_module_here,none,
@@ -292,6 +289,9 @@ NOTE(out_of_date_module_here,none,
292289
NOTE(module_interface_dependency_out_of_date,none,
293290
"dependency is out of date: '%0'",
294291
(StringRef))
292+
NOTE(module_interface_dependency_missing,none,
293+
"dependency is missing: '%0'",
294+
(StringRef))
295295
NOTE(compiled_module_invalid,none,
296296
"unable to load compiled module '%0'",
297297
(StringRef))

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ namespace swift {
8989
bool DisableAvailabilityChecking = false;
9090

9191
/// Maximum number of typo corrections we are allowed to perform.
92-
unsigned TypoCorrectionLimit = 10;
92+
/// This is disabled by default until we can get typo-correction working within acceptable performance bounds.
93+
unsigned TypoCorrectionLimit = 0;
9394

9495
/// Should access control be respected?
9596
bool EnableAccessControl = true;

include/swift/IDE/CodeCompletion.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ enum class CompletionKind {
495495
TypeIdentifierWithoutDot,
496496
CaseStmtKeyword,
497497
CaseStmtBeginning,
498-
CaseStmtDotPrefix,
499498
NominalMemberBeginning,
500499
AccessorBeginning,
501500
AttributeBegin,

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ class CodeCompletionCallbacks {
175175
virtual void completeCaseStmtKeyword() {};
176176

177177
/// Complete at the beginning of a case stmt pattern.
178-
virtual void completeCaseStmtBeginning() {};
179-
180-
/// Complete a case stmt pattern that starts with a dot.
181-
virtual void completeCaseStmtDotPrefix() {};
178+
virtual void completeCaseStmtBeginning(CodeCompletionExpr *E) {};
182179

183180
/// Complete at the beginning of member of a nominal decl member -- no tokens
184181
/// provided by user.

include/swift/Sema/IDETypeChecking.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,14 @@ namespace swift {
207207
/// @dynamicMemberLookup attribute on it.
208208
bool hasDynamicMemberLookupAttribute(Type type);
209209

210-
/// Returns the root type of the keypath type in a keypath dynamic member
211-
/// lookup subscript, or \c None if it cannot be determined.
210+
/// Returns the root type and result type of the keypath type in a keypath
211+
/// dynamic member lookup subscript, or \c None if it cannot be determined.
212212
///
213213
/// \param subscript The potential keypath dynamic member lookup subscript.
214214
/// \param DC The DeclContext from which the subscript is being referenced.
215-
Optional<Type> getRootTypeOfKeypathDynamicMember(SubscriptDecl *subscript,
216-
const DeclContext *DC);
215+
Optional<std::pair<Type, Type>>
216+
getRootAndResultTypeOfKeypathDynamicMember(SubscriptDecl *subscript,
217+
const DeclContext *DC);
217218
}
218219

219220
#endif

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,11 @@ bool PatternBindingDecl::isDefaultInitializable(unsigned i) const {
15761576
if (auto wrapperInfo = singleVar->getAttachedPropertyWrapperTypeInfo(0)) {
15771577
if (wrapperInfo.defaultInit)
15781578
return true;
1579+
1580+
// If one of the attached wrappers is missing an initialValue
1581+
// initializer, cannot default-initialize.
1582+
if (!singleVar->allAttachedPropertyWrappersHaveInitialValueInit())
1583+
return false;
15791584
}
15801585
}
15811586

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,19 @@ static bool serializedASTLooksValid(const llvm::MemoryBuffer &buf) {
223223
}
224224

225225
static std::unique_ptr<llvm::MemoryBuffer> getBufferOfDependency(
226-
llvm::vfs::FileSystem &fs, StringRef depPath, StringRef interfacePath,
227-
DiagnosticEngine &diags, SourceLoc diagnosticLoc) {
226+
llvm::vfs::FileSystem &fs, StringRef depPath) {
228227
auto depBuf = fs.getBufferForFile(depPath, /*FileSize=*/-1,
229228
/*RequiresNullTerminator=*/false);
230229
if (!depBuf) {
231-
diags.diagnose(diagnosticLoc,
232-
diag::missing_dependency_of_module_interface,
233-
depPath, interfacePath, depBuf.getError().message());
234230
return nullptr;
235231
}
236232
return std::move(depBuf.get());
237233
}
238234

239235
static Optional<llvm::vfs::Status> getStatusOfDependency(
240-
llvm::vfs::FileSystem &fs, StringRef depPath, StringRef interfacePath,
241-
DiagnosticEngine &diags, SourceLoc diagnosticLoc) {
236+
llvm::vfs::FileSystem &fs, StringRef depPath) {
242237
auto status = fs.status(depPath);
243238
if (!status) {
244-
diags.diagnose(diagnosticLoc,
245-
diag::missing_dependency_of_module_interface,
246-
depPath, interfacePath, status.getError().message());
247239
return None;
248240
}
249241
return status.get();
@@ -293,6 +285,7 @@ class swift::ParseableInterfaceBuilder {
293285
const SourceLoc diagnosticLoc;
294286
DependencyTracker *const dependencyTracker;
295287
CompilerInvocation subInvocation;
288+
SmallVector<StringRef, 3> extraDependencies;
296289

297290
void configureSubInvocationInputsAndOutputs(StringRef OutPath) {
298291
auto &SubFEOpts = subInvocation.getFrontendOptions();
@@ -406,6 +399,8 @@ class swift::ParseableInterfaceBuilder {
406399
auto DTDeps = SubInstance.getDependencyTracker()->getDependencies();
407400
SmallVector<StringRef, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
408401
InitialDepNames.push_back(interfacePath);
402+
InitialDepNames.insert(InitialDepNames.end(),
403+
extraDependencies.begin(), extraDependencies.end());
409404
llvm::StringSet<> AllDepNames;
410405
SmallString<128> Scratch;
411406

@@ -433,8 +428,7 @@ class swift::ParseableInterfaceBuilder {
433428
if (DepName.startswith(ResourcePath))
434429
continue;
435430

436-
auto Status = getStatusOfDependency(fs, DepName, interfacePath,
437-
diags, diagnosticLoc);
431+
auto Status = getStatusOfDependency(fs, DepName);
438432
if (!Status)
439433
return true;
440434

@@ -444,8 +438,7 @@ class swift::ParseableInterfaceBuilder {
444438
std::unique_ptr<llvm::MemoryBuffer> DepBuf = nullptr;
445439
auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
446440
if (DepBuf) return DepBuf.get();
447-
if (auto Buf = getBufferOfDependency(fs, DepName, interfacePath,
448-
diags, diagnosticLoc)) {
441+
if (auto Buf = getBufferOfDependency(fs, DepName)) {
449442
DepBuf = std::move(Buf);
450443
return DepBuf.get();
451444
}
@@ -498,6 +491,12 @@ class swift::ParseableInterfaceBuilder {
498491
return subInvocation;
499492
}
500493

494+
/// Ensures the requested file name is added as a dependency of the resulting
495+
/// module.
496+
void addExtraDependency(StringRef path) {
497+
extraDependencies.push_back(path);
498+
}
499+
501500
bool buildSwiftModule(StringRef OutPath, bool ShouldSerializeDeps,
502501
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer) {
503502
bool SubError = false;
@@ -656,14 +655,15 @@ struct ModuleRebuildInfo {
656655
Optional<serialization::Status> serializationStatus;
657656
ModuleKind kind;
658657
SmallVector<std::string, 10> outOfDateDependencies;
658+
SmallVector<std::string, 10> missingDependencies;
659659
};
660660
SmallVector<OutOfDateModule, 3> outOfDateModules;
661661

662662
OutOfDateModule &getOrInsertOutOfDateModule(StringRef path) {
663663
for (auto &mod : outOfDateModules) {
664664
if (mod.path == path) return mod;
665665
}
666-
outOfDateModules.push_back({path, None, ModuleKind::Normal, {}});
666+
outOfDateModules.push_back({path, None, ModuleKind::Normal, {}, {}});
667667
return outOfDateModules.back();
668668
}
669669

@@ -686,6 +686,22 @@ struct ModuleRebuildInfo {
686686
.outOfDateDependencies.push_back(depPath);
687687
}
688688

689+
/// Registers a missing dependency at \c depPath for the module
690+
/// at \c modulePath.
691+
void addMissingDependency(StringRef modulePath, StringRef depPath) {
692+
getOrInsertOutOfDateModule(modulePath)
693+
.missingDependencies.push_back(depPath);
694+
}
695+
696+
/// Determines if we saw the given module path and registered is as out of
697+
/// date.
698+
bool sawOutOfDateModule(StringRef modulePath) {
699+
for (auto &mod : outOfDateModules)
700+
if (mod.path == modulePath)
701+
return true;
702+
return false;
703+
}
704+
689705
const char *invalidModuleReason(serialization::Status status) {
690706
using namespace serialization;
691707
switch (status) {
@@ -722,6 +738,11 @@ struct ModuleRebuildInfo {
722738
dep);
723739
}
724740

741+
// Diagnose any missing dependencies in this module.
742+
for (auto &dep : mod.missingDependencies) {
743+
ctx.Diags.diagnose(loc, diag::module_interface_dependency_missing, dep);
744+
}
745+
725746
// If there was a compiled module that wasn't able to be read, diagnose
726747
// the reason we couldn't read it.
727748
if (auto status = mod.serializationStatus) {
@@ -835,31 +856,44 @@ class ParseableInterfaceModuleLoaderImpl {
835856
return StringRef(scratch.data(), scratch.size());
836857
}
837858

859+
enum class DependencyStatus {
860+
UpToDate,
861+
OutOfDate,
862+
Missing
863+
};
864+
838865
// Checks that a dependency read from the cached module is up to date compared
839866
// to the interface file it represents.
840-
bool dependencyIsUpToDate(const FileDependency &dep, StringRef fullPath) {
841-
auto status = getStatusOfDependency(fs, fullPath, interfacePath,
842-
diags, diagnosticLoc);
843-
if (!status) return false;
867+
DependencyStatus checkDependency(StringRef modulePath,
868+
const FileDependency &dep,
869+
StringRef fullPath) {
870+
auto status = getStatusOfDependency(fs, fullPath);
871+
if (!status)
872+
return DependencyStatus::Missing;
844873

845874
// If the sizes differ, then we know the file has changed.
846-
if (status->getSize() != dep.getSize()) return false;
875+
if (status->getSize() != dep.getSize())
876+
return DependencyStatus::OutOfDate;
847877

848878
// Otherwise, if this dependency is verified by modification time, check
849879
// it vs. the modification time of the file.
850880
if (dep.isModificationTimeBased()) {
851881
uint64_t mtime =
852882
status->getLastModificationTime().time_since_epoch().count();
853-
return mtime == dep.getModificationTime();
883+
return mtime == dep.getModificationTime() ?
884+
DependencyStatus::UpToDate :
885+
DependencyStatus::OutOfDate;
854886
}
855887

856888
// Slow path: if the dependency is verified by content hash, check it vs.
857889
// the hash of the file.
858-
auto buf = getBufferOfDependency(fs, fullPath, interfacePath,
859-
diags, diagnosticLoc);
860-
if (!buf) return false;
890+
auto buf = getBufferOfDependency(fs, fullPath);
891+
if (!buf)
892+
return DependencyStatus::Missing;
861893

862-
return xxHash64(buf->getBuffer()) == dep.getContentHash();
894+
return xxHash64(buf->getBuffer()) == dep.getContentHash() ?
895+
DependencyStatus::UpToDate :
896+
DependencyStatus::OutOfDate;
863897
}
864898

865899
// Check if all the provided file dependencies are up-to-date compared to
@@ -869,13 +903,19 @@ class ParseableInterfaceModuleLoaderImpl {
869903
SmallString<128> SDKRelativeBuffer;
870904
for (auto &in : deps) {
871905
StringRef fullPath = getFullDependencyPath(in, SDKRelativeBuffer);
872-
if (!dependencyIsUpToDate(in, fullPath)) {
873-
LLVM_DEBUG(llvm::dbgs() << "Dep " << fullPath
874-
<< " is directly out of date\n");
906+
switch (checkDependency(modulePath, in, fullPath)) {
907+
case DependencyStatus::UpToDate:
908+
LLVM_DEBUG(llvm::dbgs() << "Dep " << fullPath << " is up to date\n");
909+
break;
910+
case DependencyStatus::OutOfDate:
911+
LLVM_DEBUG(llvm::dbgs() << "Dep " << fullPath << " is out of date\n");
875912
rebuildInfo.addOutOfDateDependency(modulePath, fullPath);
876913
return false;
914+
case DependencyStatus::Missing:
915+
LLVM_DEBUG(llvm::dbgs() << "Dep " << fullPath << " is missing\n");
916+
rebuildInfo.addMissingDependency(modulePath, fullPath);
917+
return false;
877918
}
878-
LLVM_DEBUG(llvm::dbgs() << "Dep " << fullPath << " is up to date\n");
879919
}
880920
return true;
881921
}
@@ -885,7 +925,12 @@ class ParseableInterfaceModuleLoaderImpl {
885925
bool serializedASTBufferIsUpToDate(
886926
StringRef path, const llvm::MemoryBuffer &buf,
887927
SmallVectorImpl<FileDependency> &allDeps) {
888-
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << modulePath << "\n");
928+
929+
// Clear the existing dependencies, because we're going to re-fill them
930+
// in validateSerializedAST.
931+
allDeps.clear();
932+
933+
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
889934
auto validationInfo = serialization::validateSerializedAST(
890935
buf.getBuffer(), /*ExtendedValidationInfo=*/nullptr, &allDeps);
891936

@@ -916,6 +961,13 @@ class ParseableInterfaceModuleLoaderImpl {
916961
StringRef path, const ForwardingModule &fwd,
917962
SmallVectorImpl<FileDependency> &deps,
918963
std::unique_ptr<llvm::MemoryBuffer> &moduleBuffer) {
964+
965+
// Clear the existing dependencies, because we're going to re-fill them
966+
// from the forwarding module.
967+
deps.clear();
968+
969+
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
970+
919971
// First, make sure the underlying module path exists and is valid.
920972
auto modBuf = fs.getBufferForFile(fwd.underlyingModulePath);
921973
if (!modBuf || !serializedASTLooksValid(*modBuf.get()))
@@ -1160,6 +1212,9 @@ class ParseableInterfaceModuleLoaderImpl {
11601212
ModuleRebuildInfo::ModuleKind::Normal);
11611213
}
11621214
} else if (adjacentModuleBuffer.getError() != notFoundError) {
1215+
LLVM_DEBUG(llvm::dbgs() << "Found unreadable module at "
1216+
<< modulePath
1217+
<< "; deferring to serialized module loader\n");
11631218
return std::make_error_code(std::errc::not_supported);
11641219
}
11651220

@@ -1306,6 +1361,14 @@ class ParseableInterfaceModuleLoaderImpl {
13061361
interfacePath);
13071362
}
13081363

1364+
// If we found an out-of-date .swiftmodule, we still want to add it as
1365+
// a dependency of the .swiftinterface. That way if it's updated, but
1366+
// the .swiftinterface remains the same, we invalidate the cache and
1367+
// check the new .swiftmodule, because it likely has more information
1368+
// about the state of the world.
1369+
if (rebuildInfo.sawOutOfDateModule(modulePath))
1370+
builder.addExtraDependency(modulePath);
1371+
13091372
if (builder.buildSwiftModule(cachedOutputPath, /*shouldSerializeDeps*/true,
13101373
&moduleBuffer))
13111374
return std::make_error_code(std::errc::invalid_argument);

0 commit comments

Comments
 (0)