Skip to content

Commit 1ddedf9

Browse files
authored
Merge pull request #2501 from swiftwasm/release/5.4
[pull] swiftwasm-release/5.4 from release/5.4
2 parents b46035f + 9121e41 commit 1ddedf9

File tree

11 files changed

+136
-8
lines changed

11 files changed

+136
-8
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static bool emitReferenceDependencies(CompilerInstance &Instance,
539539
});
540540
}
541541

542-
static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
542+
static void emitSwiftdepsForAllPrimaryInputsIfNeeded(
543543
CompilerInstance &Instance) {
544544
const auto &Invocation = Instance.getInvocation();
545545
if (Invocation.getFrontendOptions()
@@ -549,6 +549,22 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
549549
SourceLoc(), diag::emit_reference_dependencies_without_primary_file);
550550
return;
551551
}
552+
553+
// Do not write out swiftdeps for any primaries if we've encountered an
554+
// error. Without this, the driver will attempt to integrate swiftdeps
555+
// from broken swift files. One way this could go wrong is if a primary that
556+
// fails to build in an early wave has dependents in a later wave. The
557+
// driver will not schedule those later dependents after this batch exits,
558+
// so they will have no opportunity to bring their swiftdeps files up to
559+
// date. With this early exit, the driver sees the same priors in the
560+
// swiftdeps files from before errors were introduced into the batch, and
561+
// integration therefore always hops from "known good" to "known good" states.
562+
//
563+
// FIXME: It seems more appropriate for the driver to notice the early-exit
564+
// and react by always enqueuing the jobs it dropped in the other waves.
565+
if (Instance.getDiags().hadAnyError())
566+
return;
567+
552568
for (auto *SF : Instance.getPrimarySourceFiles()) {
553569
const std::string &referenceDependenciesFilePath =
554570
Invocation.getReferenceDependenciesFilePathForPrimary(
@@ -957,8 +973,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
957973
emitIndexData(Instance);
958974
}
959975

960-
// Emit dependencies.
961-
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
976+
// Emit Swiftdeps for every file in the batch.
977+
emitSwiftdepsForAllPrimaryInputsIfNeeded(Instance);
978+
979+
// Emit Make-style dependencies.
962980
emitMakeDependenciesIfNeeded(Instance.getDiags(),
963981
Instance.getDependencyTracker(), opts);
964982

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,20 +565,22 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
565565
if (current == other || (other->hasInterfaceType() && other->isInvalid()))
566566
continue;
567567

568+
auto *otherDC = other->getDeclContext();
569+
568570
// Skip declarations in other modules.
569-
if (currentModule != other->getModuleContext())
571+
if (currentModule != otherDC->getParentModule())
570572
continue;
571573

572574
// If both declarations are in the same file, only diagnose the second one.
573-
if (currentFile == other->getDeclContext()->getParentSourceFile())
575+
if (currentFile == otherDC->getParentSourceFile())
574576
if (current->getLoc().isValid() &&
575577
ctx.SourceMgr.isBeforeInBuffer(
576578
current->getLoc(), other->getLoc()))
577579
continue;
578580

579581
// Don't compare methods vs. non-methods (which only happens with
580582
// operators).
581-
if (currentDC->isTypeContext() != other->getDeclContext()->isTypeContext())
583+
if (currentDC->isTypeContext() != otherDC->isTypeContext())
582584
continue;
583585

584586
// In local context, only consider exact name matches.
@@ -592,7 +594,7 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
592594
if (!conflicting(currentSig, otherSig))
593595
continue;
594596

595-
// Skip declarations in other files.
597+
// Skip inaccessible declarations in other files.
596598
// In practice, this means we will warn on a private declaration that
597599
// shadows a non-private one, but only in the file where the shadowing
598600
// happens. We will warn on conflicting non-private declarations in both
@@ -605,6 +607,15 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
605607
if (other->isInvalid())
606608
continue;
607609

610+
// Allow redeclarations of typealiases in different constrained
611+
// extensions.
612+
if (isa<TypeAliasDecl>(current) &&
613+
isa<TypeAliasDecl>(other) &&
614+
currentDC != otherDC &&
615+
currentDC->getGenericSignatureOfContext().getCanonicalSignature() !=
616+
otherDC->getGenericSignatureOfContext().getCanonicalSignature())
617+
continue;
618+
608619
// Thwart attempts to override the same declaration more than once.
609620
const auto *currentOverride = current->getOverriddenDecl();
610621
const auto *otherOverride = other->getOverriddenDecl();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct A {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct B {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct B< {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"main.swift": {
3+
"object": "./main.o",
4+
"swift-dependencies": "./main.swiftdeps"
5+
},
6+
"definesA.swift": {
7+
"object": "./definesA.o",
8+
"swift-dependencies": "./definesA.swiftdeps"
9+
},
10+
"usesA.swift": {
11+
"object": "./usesA.o",
12+
"swift-dependencies": "./usesA.swiftdeps"
13+
},
14+
"": {
15+
"swift-dependencies": "./main~buildrecord.swiftdeps"
16+
}
17+
}
18+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func use() {
2+
let _ = A()
3+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Establish baseline
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: cp %S/Inputs/cross-file-failure/* %t
5+
// RUN: cp %t/definesA{-one,}.swift
6+
// RUN: touch -t 200101010101 %t/*.swift
7+
// RUN: cd %t
8+
9+
// RUN: %target-swiftc_driver -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesA.swift usesA.swift -module-name main -output-file-map ofm.json >&output-baseline
10+
11+
// Change one type and cause a syntax error. This should cause _both_ files to
12+
// rebuild.
13+
14+
// RUN: cp %t/definesA{-two,}.swift
15+
// RUN: touch -t 200201010101 %t/*
16+
// RUN: touch -t 200101010101 %t/*.swift
17+
// RUN: touch -t 200301010101 %t/definesA.swift
18+
19+
// RUN: not %target-swiftc_driver -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesA.swift usesA.swift -module-name main -output-file-map ofm.json
20+
21+
// RUN: cp %t/definesA{-three,}.swift
22+
// RUN: touch -t 200401010101 %t/definesA.swift
23+
24+
// RUN: not %target-swiftc_driver -enable-batch-mode -j2 -incremental -driver-show-incremental main.swift definesA.swift usesA.swift -module-name main -output-file-map ofm.json >&output-incremental
25+
26+
// RUN: %FileCheck -check-prefix=CHECK-RECOMPILED %s --dump-input=always < %t/output-incremental
27+
28+
// CHECK-RECOMPILED: Queuing (initial): {compile: definesA.o <= definesA.swift}
29+
// CHECK-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}

test/decl/protocol/req/missing_conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ extension CountSteps1 // expected-error {{type 'CountSteps1<T>' does not conform
132132
where T : Equatable
133133
{
134134
typealias Index = Int
135-
// expected-error@-1 {{invalid redeclaration of synthesized implementation for protocol requirement 'Index'}}
135+
136136
func index(_ i: Index, offsetBy d: Int) -> Index {
137137
return i + d
138138
}

0 commit comments

Comments
 (0)