Skip to content

Commit a82aa74

Browse files
authored
Merge pull request #1178 from swiftwasm/master
[pull] swiftwasm from master
2 parents 22ede19 + 932a91e commit a82aa74

File tree

8 files changed

+94
-75
lines changed

8 files changed

+94
-75
lines changed

lib/AST/AbstractSourceFileDepGraphFactory.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,30 @@ void AbstractSourceFileDepGraphFactory::addAUsedDecl(
7979
const DependencyKey &defKey, const DependencyKey &useKey) {
8080
auto *defNode =
8181
g.findExistingNodeOrCreateIfNew(defKey, None, false /* = !isProvides */);
82+
8283
// If the depended-upon node is defined in this file, then don't
8384
// create an arc to the user, when the user is the whole file.
8485
// Otherwise, if the defNode's type-body fingerprint changes,
8586
// the whole file will be marked as dirty, losing the benefit of the
8687
// fingerprint.
87-
if (defNode->getIsProvides() &&
88-
useKey.getKind() == NodeKind::sourceFileProvide)
89-
return;
88+
89+
// if (defNode->getIsProvides() &&
90+
// useKey.getKind() == NodeKind::sourceFileProvide)
91+
// return;
92+
93+
// Turns out the above three lines cause miscompiles, so comment them out
94+
// for now. We might want them back if we can change the inputs to this
95+
// function to be more precise.
96+
97+
// Example of a miscompile:
98+
// In main.swift
99+
// func foo(_: Any) { print("Hello Any") }
100+
// foo(123)
101+
// Then add the following line to another file:
102+
// func foo(_: Int) { print("Hello Int") }
103+
// Although main.swift needs to get recompiled, the commented-out code below
104+
// prevents that.
105+
90106
auto nullableUse = g.findExistingNode(useKey);
91107
assert(nullableUse.isNonNull() && "Use must be an already-added provides");
92108
auto *useNode = nullableUse.get();

lib/Sema/ConstraintSystem.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,72 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
955955
return *member;
956956
}
957957

958+
static Optional<std::pair<VarDecl *, Type>>
959+
getPropertyWrapperInformationFromOverload(
960+
SelectedOverload resolvedOverload, DeclContext *DC,
961+
llvm::function_ref<Optional<std::pair<VarDecl *, Type>>(VarDecl *)>
962+
getInformation) {
963+
if (auto *decl =
964+
dyn_cast_or_null<VarDecl>(resolvedOverload.choice.getDeclOrNull())) {
965+
if (auto declInformation = getInformation(decl)) {
966+
Type type;
967+
VarDecl *memberDecl;
968+
std::tie(memberDecl, type) = *declInformation;
969+
if (Type baseType = resolvedOverload.choice.getBaseType()) {
970+
type =
971+
baseType->getTypeOfMember(DC->getParentModule(), memberDecl, type);
972+
}
973+
return std::make_pair(decl, type);
974+
}
975+
}
976+
return None;
977+
}
978+
979+
Optional<std::pair<VarDecl *, Type>>
980+
ConstraintSystem::getStorageWrapperInformation(
981+
SelectedOverload resolvedOverload) {
982+
return getPropertyWrapperInformationFromOverload(
983+
resolvedOverload, DC,
984+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
985+
if (!decl->hasAttachedPropertyWrapper())
986+
return None;
987+
988+
auto storageWrapper = decl->getPropertyWrapperStorageWrapper();
989+
if (!storageWrapper)
990+
return None;
991+
992+
return std::make_pair(storageWrapper,
993+
storageWrapper->getInterfaceType());
994+
});
995+
}
996+
997+
Optional<std::pair<VarDecl *, Type>>
998+
ConstraintSystem::getPropertyWrapperInformation(
999+
SelectedOverload resolvedOverload) {
1000+
return getPropertyWrapperInformationFromOverload(
1001+
resolvedOverload, DC,
1002+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
1003+
if (!decl->hasAttachedPropertyWrapper())
1004+
return None;
1005+
1006+
return std::make_pair(decl,
1007+
decl->getPropertyWrapperBackingPropertyType());
1008+
});
1009+
}
1010+
1011+
Optional<std::pair<VarDecl *, Type>>
1012+
ConstraintSystem::getWrappedPropertyInformation(
1013+
SelectedOverload resolvedOverload) {
1014+
return getPropertyWrapperInformationFromOverload(
1015+
resolvedOverload, DC,
1016+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
1017+
if (auto wrapped = decl->getOriginalWrappedProperty())
1018+
return std::make_pair(decl, wrapped->getInterfaceType());
1019+
1020+
return None;
1021+
});
1022+
}
1023+
9581024
/// Does a var or subscript produce an l-value?
9591025
///
9601026
/// \param baseType - the type of the base on which this object

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,62 +3237,18 @@ class ConstraintSystem {
32373237
/// Gets the VarDecl associateed with resolvedOverload, and the type of the
32383238
/// storage wrapper if the decl has an associated storage wrapper.
32393239
Optional<std::pair<VarDecl *, Type>>
3240-
getStorageWrapperInformation(SelectedOverload resolvedOverload) {
3241-
if (resolvedOverload.choice.isDecl()) {
3242-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3243-
if (decl->hasAttachedPropertyWrapper()) {
3244-
if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper()) {
3245-
Type type = storageWrapper->getInterfaceType();
3246-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3247-
type = baseType->getTypeOfMember(DC->getParentModule(),
3248-
storageWrapper, type);
3249-
}
3250-
return std::make_pair(decl, type);
3251-
}
3252-
}
3253-
}
3254-
}
3255-
return None;
3256-
}
3240+
getStorageWrapperInformation(SelectedOverload resolvedOverload);
32573241

32583242
/// Gets the VarDecl associateed with resolvedOverload, and the type of the
32593243
/// backing storage if the decl has an associated property wrapper.
32603244
Optional<std::pair<VarDecl *, Type>>
3261-
getPropertyWrapperInformation(SelectedOverload resolvedOverload) {
3262-
if (resolvedOverload.choice.isDecl()) {
3263-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3264-
if (decl->hasAttachedPropertyWrapper()) {
3265-
auto wrapperTy = decl->getPropertyWrapperBackingPropertyType();
3266-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3267-
wrapperTy = baseType->getTypeOfMember(DC->getParentModule(),
3268-
decl, wrapperTy);
3269-
}
3270-
return std::make_pair(decl, wrapperTy);
3271-
}
3272-
}
3273-
}
3274-
return None;
3275-
}
3245+
getPropertyWrapperInformation(SelectedOverload resolvedOverload);
32763246

32773247
/// Gets the VarDecl, and the type of the type property that it wraps if
32783248
/// resolved overload has a decl which is the backing storage for a
32793249
/// property wrapper.
32803250
Optional<std::pair<VarDecl *, Type>>
3281-
getWrappedPropertyInformation(SelectedOverload resolvedOverload) {
3282-
if (resolvedOverload.choice.isDecl()) {
3283-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3284-
if (auto wrapped = decl->getOriginalWrappedProperty()) {
3285-
Type type = wrapped->getInterfaceType();
3286-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3287-
type = baseType->getTypeOfMember(DC->getParentModule(),
3288-
wrapped, type);
3289-
}
3290-
return std::make_pair(decl, type);
3291-
}
3292-
}
3293-
}
3294-
return None;
3295-
}
3251+
getWrappedPropertyInformation(SelectedOverload resolvedOverload);
32963252

32973253
/// Merge the equivalence sets of the two type variables.
32983254
///

test/Frontend/Fingerprints/class-fingerprint.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,4 @@
7171

7272
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps
7373

74-
// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4
75-
76-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
77-
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
78-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
79-
74+
// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4

test/Frontend/Fingerprints/enum-fingerprint.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,4 @@
7171

7272
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps
7373

74-
// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4
75-
76-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
77-
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
78-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
79-
74+
// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4

test/Frontend/Fingerprints/protocol-fingerprint.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,5 @@
7171

7272
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps
7373

74-
// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4
75-
76-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
77-
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
78-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
74+
// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4
7975

test/Frontend/Fingerprints/struct-fingerprint.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,4 @@
7171

7272
// only-run-for-debugging: cp %t/usesB.swiftdeps %t/usesB4.swiftdeps
7373

74-
// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4
75-
76-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
77-
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
78-
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
79-
74+
// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4

unittests/Driver/TypeBodyFingerprintsDependencyGraphTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,10 @@ TEST(ModuleDepGraph, UseFingerprints) {
807807
{
808808
const auto jobs =
809809
simulateReload(graph, &job0, {{NodeKind::nominal, {"A1@11", "A2@2"}}});
810-
EXPECT_EQ(2u, jobs.size());
810+
EXPECT_EQ(3u, jobs.size());
811811
EXPECT_TRUE(contains(jobs, &job0));
812812
EXPECT_TRUE(contains(jobs, &job1));
813-
EXPECT_FALSE(contains(jobs, &job2));
813+
EXPECT_TRUE(contains(jobs, &job2));
814814
EXPECT_FALSE(contains(jobs, &job3));
815815
}
816816
}

0 commit comments

Comments
 (0)