Skip to content

Commit 7af6a24

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents d91d33f + 89787e2 commit 7af6a24

File tree

14 files changed

+137
-81
lines changed

14 files changed

+137
-81
lines changed

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ struct swiftscan_dependency_info_s {
6565
/// The list of source import infos.
6666
swiftscan_import_info_set_t *imports;
6767

68+
/// The list of source optional import infos.
69+
swiftscan_import_info_set_t *optional_imports;
70+
6871
/// Specific details of a particular kind of module.
6972
swiftscan_module_details_t details;
7073
};

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using llvm::BCVBR;
4141
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
4242
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 10;
4343
/// Increment this on every change.
44-
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 3;
44+
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 4;
4545

4646
/// Various identifiers in this format will rely on having their strings mapped
4747
/// using this ID.

include/swift/Sema/ConstraintLocator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
260260
/// of the key path at some index.
261261
bool isKeyPathMemberComponent() const;
262262

263+
/// Determine whether this locator points to an apply component of the key
264+
/// path at some index.
265+
bool isKeyPathApplyComponent() const;
266+
263267
/// Determine whether this locator points to the member found
264268
/// via key path dynamic member lookup.
265269
bool isForKeyPathDynamicMemberLookup() const;

lib/DependencyScan/DependencyScanJSON.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ void writeLinkLibraries(llvm::raw_ostream &out,
228228

229229
void writeImportInfos(llvm::raw_ostream &out,
230230
const swiftscan_import_info_set_t *imports,
231-
unsigned indentLevel, bool trailingComma) {
231+
bool optional, unsigned indentLevel,
232+
bool trailingComma) {
232233
out.indent(indentLevel * 2);
233-
out << "\"imports\": ";
234+
if (optional)
235+
out << "\"optionalImports\": ";
236+
else
237+
out << "\"imports\": ";
234238
out << "[\n";
235239

236240
for (size_t i = 0; i < imports->count; ++i) {
@@ -441,7 +445,9 @@ void writeJSON(llvm::raw_ostream &out,
441445
/*trailingComma=*/true);
442446
writeLinkLibraries(out, moduleInfo.link_libraries,
443447
3, /*trailingComma=*/true);
444-
writeImportInfos(out, moduleInfo.imports,
448+
writeImportInfos(out, moduleInfo.imports, /*optional*/ false,
449+
3, /*trailingComma=*/true);
450+
writeImportInfos(out, moduleInfo.optional_imports, /*optional*/ true,
445451
3, /*trailingComma=*/true);
446452
}
447453
// Swift and Clang-specific details.

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class ModuleDependenciesCacheDeserializer {
4949
std::vector<std::vector<uint64_t>> ArraysOfMacroDependenciesIDs;
5050
std::vector<ScannerImportStatementInfo> ImportStatements;
5151
std::vector<std::vector<uint64_t>> ArraysOfImportStatementIDs;
52-
std::vector<std::vector<uint64_t>> ArraysOfSearchPathIDs;
5352
std::vector<std::vector<uint64_t>> ArraysOfOptionalImportStatementIDs;
53+
std::vector<std::vector<uint64_t>> ArraysOfSearchPathIDs;
5454

5555
llvm::BitstreamCursor Cursor;
5656
SmallVector<uint64_t, 64> Scratch;
@@ -1170,6 +1170,7 @@ class ModuleDependenciesCacheSerializer {
11701170
unsigned writeImportStatementInfos(const ModuleDependencyInfo &dependencyInfo,
11711171
bool optional);
11721172
void writeImportStatementInfosArray(unsigned startIndex, unsigned count);
1173+
void writeOptionalImportStatementInfosArray(unsigned startIndex, unsigned count);
11731174

11741175
void writeModuleInfo(ModuleDependencyID moduleID,
11751176
const ModuleDependencyInfo &dependencyInfo);
@@ -1478,7 +1479,7 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfos(
14781479
}
14791480
auto optionalEntries = optionalImportInfoArrayMap.at(moduleID);
14801481
if (optionalEntries.second != 0) {
1481-
writeImportStatementInfosArray(optionalEntries.first, optionalEntries.second);
1482+
writeOptionalImportStatementInfosArray(optionalEntries.first, optionalEntries.second);
14821483
OptionalImportInfosArrayIDsMap.insert({moduleID, lastOptionalImportInfoArrayIndex++});
14831484
}
14841485
}
@@ -1530,6 +1531,15 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfosArray(
15301531
Out, ScratchRecord, AbbrCodes[ImportStatementArrayLayout::Code], vec);
15311532
}
15321533

1534+
void ModuleDependenciesCacheSerializer::writeOptionalImportStatementInfosArray(
1535+
unsigned startIndex, unsigned count) {
1536+
using namespace graph_block;
1537+
std::vector<unsigned> vec(count);
1538+
std::iota(vec.begin(), vec.end(), startIndex);
1539+
OptionalImportStatementArrayLayout::emitRecord(
1540+
Out, ScratchRecord, AbbrCodes[OptionalImportStatementArrayLayout::Code], vec);
1541+
}
1542+
15331543
void ModuleDependenciesCacheSerializer::writeModuleInfo(
15341544
ModuleDependencyID moduleID, const ModuleDependencyInfo &dependencyInfo) {
15351545
using namespace graph_block;
@@ -1965,6 +1975,7 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
19651975
registerRecordAbbr<SearchPathArrayLayout>();
19661976
registerRecordAbbr<ImportStatementLayout>();
19671977
registerRecordAbbr<ImportStatementArrayLayout>();
1978+
registerRecordAbbr<OptionalImportStatementArrayLayout>();
19681979
registerRecordAbbr<ModuleInfoLayout>();
19691980
registerRecordAbbr<SwiftSourceModuleDetailsLayout>();
19701981
registerRecordAbbr<SwiftInterfaceModuleDetailsLayout>();

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -922,37 +922,44 @@ static swiftscan_dependency_graph_t generateFullDependencyGraph(
922922
}
923923
moduleInfo->link_libraries = linkLibrarySet;
924924

925-
// Create source import infos set for this module
926-
auto imports = moduleDependencyInfo.getModuleImports();
927-
swiftscan_import_info_set_t *importInfoSet =
928-
new swiftscan_import_info_set_t;
929-
importInfoSet->count = imports.size();
930-
importInfoSet->imports = new swiftscan_import_info_t[importInfoSet->count];
931-
for (size_t i = 0; i < imports.size(); ++i) {
932-
const auto &ii = imports[i];
933-
swiftscan_import_info_s *iInfo = new swiftscan_import_info_s;
934-
iInfo->import_identifier = create_clone(ii.importIdentifier.c_str());
935-
iInfo->access_level =
936-
static_cast<swiftscan_access_level_t>(ii.accessLevel);
937-
938-
const auto &sourceLocations = ii.importLocations;
939-
swiftscan_source_location_set_t *sourceLocSet =
940-
new swiftscan_source_location_set_t;
941-
sourceLocSet->count = sourceLocations.size();
942-
sourceLocSet->source_locations =
943-
new swiftscan_source_location_t[sourceLocSet->count];
944-
for (size_t j = 0; j < sourceLocations.size(); ++j) {
945-
const auto &sl = sourceLocations[j];
946-
swiftscan_source_location_s *slInfo = new swiftscan_source_location_s;
947-
slInfo->buffer_identifier = create_clone(sl.bufferIdentifier.c_str());
948-
slInfo->line_number = sl.lineNumber;
949-
slInfo->column_number = sl.columnNumber;
950-
sourceLocSet->source_locations[j] = slInfo;
925+
auto createImportSetInfo = [&](ArrayRef<ScannerImportStatementInfo> imports)
926+
-> swiftscan_import_info_set_t * {
927+
swiftscan_import_info_set_t *importInfoSet =
928+
new swiftscan_import_info_set_t;
929+
importInfoSet->count = imports.size();
930+
importInfoSet->imports =
931+
new swiftscan_import_info_t[importInfoSet->count];
932+
for (size_t i = 0; i < imports.size(); ++i) {
933+
const auto &ii = imports[i];
934+
swiftscan_import_info_s *iInfo = new swiftscan_import_info_s;
935+
iInfo->import_identifier = create_clone(ii.importIdentifier.c_str());
936+
iInfo->access_level =
937+
static_cast<swiftscan_access_level_t>(ii.accessLevel);
938+
939+
const auto &sourceLocations = ii.importLocations;
940+
swiftscan_source_location_set_t *sourceLocSet =
941+
new swiftscan_source_location_set_t;
942+
sourceLocSet->count = sourceLocations.size();
943+
sourceLocSet->source_locations =
944+
new swiftscan_source_location_t[sourceLocSet->count];
945+
for (size_t j = 0; j < sourceLocations.size(); ++j) {
946+
const auto &sl = sourceLocations[j];
947+
swiftscan_source_location_s *slInfo = new swiftscan_source_location_s;
948+
slInfo->buffer_identifier = create_clone(sl.bufferIdentifier.c_str());
949+
slInfo->line_number = sl.lineNumber;
950+
slInfo->column_number = sl.columnNumber;
951+
sourceLocSet->source_locations[j] = slInfo;
952+
}
953+
iInfo->source_locations = sourceLocSet;
954+
importInfoSet->imports[i] = iInfo;
951955
}
952-
iInfo->source_locations = sourceLocSet;
953-
importInfoSet->imports[i] = iInfo;
954-
}
955-
moduleInfo->imports = importInfoSet;
956+
return importInfoSet;
957+
};
958+
// Create source import infos set for this module
959+
moduleInfo->imports =
960+
createImportSetInfo(moduleDependencyInfo.getModuleImports());
961+
moduleInfo->optional_imports =
962+
createImportSetInfo(moduleDependencyInfo.getOptionalModuleImports());
956963
}
957964

958965
swiftscan_dependency_graph_t result = new swiftscan_dependency_graph_s;

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,7 +6405,8 @@ SourceLoc KeyPathSubscriptIndexHashableFailure::getLoc() const {
64056405
auto *locator = getLocator();
64066406

64076407
if (locator->isKeyPathSubscriptComponent() ||
6408-
locator->isKeyPathMemberComponent()) {
6408+
locator->isKeyPathMemberComponent() ||
6409+
locator->isKeyPathApplyComponent()) {
64096410
auto *KPE = castToExpr<KeyPathExpr>(getAnchor());
64106411
if (auto kpElt = locator->findFirst<LocatorPathElt::KeyPathComponent>())
64116412
return KPE->getComponents()[kpElt->getIndex()].getLoc();
@@ -6417,7 +6418,7 @@ SourceLoc KeyPathSubscriptIndexHashableFailure::getLoc() const {
64176418
bool KeyPathSubscriptIndexHashableFailure::diagnoseAsError() {
64186419
auto *locator = getLocator();
64196420
emitDiagnostic(diag::expr_keypath_arg_or_index_not_hashable,
6420-
!locator->isKeyPathMemberComponent(),
6421+
!locator->isKeyPathApplyComponent(),
64216422
resolveType(NonConformingType));
64226423
return true;
64236424
}

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,9 +1707,10 @@ class KeyPathSubscriptIndexHashableFailure final : public FailureDiagnostic {
17071707
KeyPathSubscriptIndexHashableFailure(const Solution &solution, Type type,
17081708
ConstraintLocator *locator)
17091709
: FailureDiagnostic(solution, locator), NonConformingType(type) {
1710-
assert((locator->isResultOfKeyPathDynamicMemberLookup() ||
1711-
locator->isKeyPathSubscriptComponent()) ||
1712-
locator->isKeyPathMemberComponent());
1710+
assert(locator->isResultOfKeyPathDynamicMemberLookup() ||
1711+
locator->isKeyPathSubscriptComponent() ||
1712+
locator->isKeyPathMemberComponent() ||
1713+
locator->isKeyPathApplyComponent());
17131714
}
17141715

17151716
SourceLoc getLoc() const override;

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,6 @@ namespace {
11981198
/// component kind.
11991199
Type addApplyConstraints(
12001200
Expr *anchor, Type memberTy, ArgumentList *argList,
1201-
ConstraintLocator *memberComponentLoc,
12021201
ConstraintLocator *applyComponentLoc,
12031202
SmallVectorImpl<TypeVariableType *> *addedTypeVars = nullptr) {
12041203
// Locators used in this expression.
@@ -1225,7 +1224,7 @@ namespace {
12251224
for (auto index : indices(params)) {
12261225
const auto &param = params[index];
12271226
CS.verifyThatArgumentIsHashable(index, param.getParameterType(),
1228-
memberComponentLoc, loc);
1227+
applyComponentLoc, loc);
12291228
}
12301229

12311230
// Add the constraint that the index expression's type be convertible
@@ -3895,11 +3894,8 @@ namespace {
38953894

38963895
case KeyPathExpr::Component::Kind::UnresolvedApply:
38973896
case KeyPathExpr::Component::Kind::Apply: {
3898-
auto prevMemberLocator = CS.getConstraintLocator(
3899-
locator, LocatorPathElt::KeyPathComponent(i - 1));
39003897
base = addApplyConstraints(E, base, component.getArgs(),
3901-
prevMemberLocator, memberLocator,
3902-
&componentTypeVars);
3898+
memberLocator, &componentTypeVars);
39033899
break;
39043900
}
39053901

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9221,9 +9221,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
92219221
// If this is an implicit Hashable conformance check generated for each
92229222
// index argument of the keypath subscript component, we could just treat
92239223
// it as though it conforms.
9224-
if ((loc->isResultOfKeyPathDynamicMemberLookup() ||
9225-
loc->isKeyPathSubscriptComponent()) ||
9226-
loc->isKeyPathMemberComponent()) {
9224+
if (loc->isResultOfKeyPathDynamicMemberLookup() ||
9225+
loc->isKeyPathSubscriptComponent() ||
9226+
loc->isKeyPathMemberComponent() ||
9227+
loc->isKeyPathApplyComponent()) {
92279228
if (protocol ==
92289229
getASTContext().getProtocol(KnownProtocolKind::Hashable)) {
92299230
auto *fix =

0 commit comments

Comments
 (0)