Skip to content

Commit 0386448

Browse files
authored
Merge pull request #1167 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents 9a06725 + b291134 commit 0386448

13 files changed

+98
-71
lines changed

include/swift/Parse/Parser.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,8 @@ class Parser {
929929
std::pair<std::vector<Decl *>, Optional<std::string>>
930930
parseDeclListDelayed(IterableDeclContext *IDC);
931931

932-
bool parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
933-
SourceLoc PosBeforeLB,
934-
Diag<> ErrorDiag,
932+
bool parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
933+
Diag<> LBraceDiag, Diag<> RBraceDiag,
935934
IterableDeclContext *IDC);
936935

937936
bool canDelayMemberDeclParsing(bool &HasOperatorDeclarations,

lib/AST/AbstractSourceFileDepGraphFactory.cpp

+19-3
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/Parse/ParseDecl.cpp

+27-39
Original file line numberDiff line numberDiff line change
@@ -4425,10 +4425,18 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
44254425
return Result;
44264426
}
44274427

4428-
bool Parser::parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
4429-
SourceLoc PosBeforeLB,
4430-
Diag<> ErrorDiag,
4428+
bool Parser::parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
4429+
Diag<> LBraceDiag, Diag<> RBraceDiag,
44314430
IterableDeclContext *IDC) {
4431+
if (parseToken(tok::l_brace, LBLoc, LBraceDiag)) {
4432+
LBLoc = RBLoc = PreviousLoc;
4433+
4434+
// Cache the empty result to prevent delayed parsing.
4435+
Context.evaluator.cacheOutput(
4436+
ParseMembersRequest{IDC}, FingerprintAndMembers{None, {}});
4437+
return true;
4438+
}
4439+
44324440
bool HasOperatorDeclarations;
44334441
bool HasNestedClassDeclarations;
44344442

@@ -4447,7 +4455,7 @@ bool Parser::parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
44474455
bool hadError = false;
44484456
ParseDeclOptions Options = getMemberParseDeclOptions(IDC);
44494457
auto membersAndHash =
4450-
parseDeclList(LBLoc, RBLoc, ErrorDiag, Options, IDC, hadError);
4458+
parseDeclList(LBLoc, RBLoc, RBraceDiag, Options, IDC, hadError);
44514459
IDC->setMaybeHasOperatorDeclarations();
44524460
IDC->setMaybeHasNestedClassDeclarations();
44534461
Context.evaluator.cacheOutput(
@@ -4617,16 +4625,12 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
46174625
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
46184626
SourceLoc LBLoc, RBLoc;
46194627

4620-
auto PosBeforeLB = Tok.getLoc();
4621-
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_extension)) {
4622-
LBLoc = PreviousLoc;
4623-
RBLoc = LBLoc;
4624-
status.setIsParseError();
4625-
} else {
4628+
{
46264629
ContextChange CC(*this, ext);
46274630
Scope S(this, ScopeKind::Extension);
46284631

4629-
if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
4632+
if (parseMemberDeclList(LBLoc, RBLoc,
4633+
diag::expected_lbrace_extension,
46304634
diag::expected_rbrace_extension,
46314635
ext))
46324636
status.setIsParseError();
@@ -6578,15 +6582,11 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
65786582

65796583
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
65806584
SourceLoc LBLoc, RBLoc;
6581-
SourceLoc PosBeforeLB = Tok.getLoc();
6582-
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_enum)) {
6583-
LBLoc = PreviousLoc;
6584-
RBLoc = LBLoc;
6585-
Status.setIsParseError();
6586-
} else {
6585+
{
65876586
Scope S(this, ScopeKind::EnumBody);
65886587

6589-
if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
6588+
if (parseMemberDeclList(LBLoc, RBLoc,
6589+
diag::expected_lbrace_enum,
65906590
diag::expected_rbrace_enum,
65916591
ED))
65926592
Status.setIsParseError();
@@ -6864,16 +6864,12 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
68646864
// Make the entities of the struct as a code block.
68656865
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
68666866
SourceLoc LBLoc, RBLoc;
6867-
SourceLoc PosBeforeLB = Tok.getLoc();
6868-
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
6869-
LBLoc = PreviousLoc;
6870-
RBLoc = LBLoc;
6871-
Status.setIsParseError();
6872-
} else {
6867+
{
68736868
// Parse the body.
68746869
Scope S(this, ScopeKind::StructBody);
68756870

6876-
if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
6871+
if (parseMemberDeclList(LBLoc, RBLoc,
6872+
diag::expected_lbrace_struct,
68776873
diag::expected_rbrace_struct,
68786874
SD))
68796875
Status.setIsParseError();
@@ -6980,16 +6976,12 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
69806976

69816977
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
69826978
SourceLoc LBLoc, RBLoc;
6983-
auto PosBeforeLB = Tok.getLoc();
6984-
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_class)) {
6985-
LBLoc = PreviousLoc;
6986-
RBLoc = LBLoc;
6987-
Status.setIsParseError();
6988-
} else {
6979+
{
69896980
// Parse the body.
69906981
Scope S(this, ScopeKind::ClassBody);
69916982

6992-
if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
6983+
if (parseMemberDeclList(LBLoc, RBLoc,
6984+
diag::expected_lbrace_class,
69936985
diag::expected_rbrace_class,
69946986
CD))
69956987
Status.setIsParseError();
@@ -7081,14 +7073,10 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
70817073
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
70827074
SourceLoc LBraceLoc;
70837075
SourceLoc RBraceLoc;
7084-
SourceLoc PosBeforeLB = Tok.getLoc();
7085-
if (parseToken(tok::l_brace, LBraceLoc, diag::expected_lbrace_protocol)) {
7086-
LBraceLoc = PreviousLoc;
7087-
RBraceLoc = LBraceLoc;
7088-
Status.setIsParseError();
7089-
} else {
7076+
{
70907077
// Parse the members.
7091-
if (parseMemberDeclList(LBraceLoc, RBraceLoc, PosBeforeLB,
7078+
if (parseMemberDeclList(LBraceLoc, RBraceLoc,
7079+
diag::expected_lbrace_protocol,
70927080
diag::expected_rbrace_protocol,
70937081
Proto))
70947082
Status.setIsParseError();

lib/Sema/CSGen.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,19 @@ namespace {
25352535
ConstraintKind::CheckedCast, subPatternType, castType,
25362536
locator.withPathElement(LocatorPathElt::PatternMatch(pattern)));
25372537

2538-
return setType(subPatternType);
2538+
// Allow `is` pattern to infer type from context which is then going
2539+
// to be propaged down to its sub-pattern via conversion. This enables
2540+
// correct handling of patterns like `_ as Foo` where `_` would
2541+
// get a type of `Foo` but `is` pattern enclosing it could still be
2542+
// inferred from enclosing context.
2543+
auto isType = CS.createTypeVariable(
2544+
CS.getConstraintLocator(
2545+
locator.withPathElement(LocatorPathElt::PatternMatch(pattern))),
2546+
TVO_CanBindToNoEscape);
2547+
CS.addConstraint(
2548+
ConstraintKind::Conversion, subPatternType, isType,
2549+
locator.withPathElement(LocatorPathElt::PatternMatch(pattern)));
2550+
return setType(isType);
25392551
}
25402552

25412553
case PatternKind::Bool:

test/Constraints/patterns.swift

+17
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,20 @@ func rdar_60048356() {
478478
}
479479
}
480480
}
481+
482+
// rdar://problem/63510989 - valid pattern doesn't type-check
483+
func rdar63510989() {
484+
enum Value : P {
485+
func p() {}
486+
}
487+
488+
enum E {
489+
case foo(P?)
490+
}
491+
492+
func test(e: E) {
493+
if case .foo(_ as Value) = e {} // Ok
494+
if case .foo(let v as Value) = e {} // Ok
495+
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
496+
}
497+
}

test/Frontend/Fingerprints/class-fingerprint.swift

+1-6
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

+1-6
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

+1-5
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

+1-6
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/IRGen/framepointer_arm64.sil

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %target-swift-frontend -target arm64-apple-ios8.0 -primary-file %s -S -no-omit-leaf-frame-pointer | %FileCheck %s --check-prefix=CHECKASM-ALL
55

66
// REQUIRES: CODEGENERATOR=AArch64
7+
// REQUIRES: OS=ios
78

89
// UNSUPPORTED: OS=linux-gnu
910
// UNSUPPORTED: OS=windows
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func test() {
2+
class C:
3+
}
4+
5+
// RUN: %sourcekitd-test \
6+
// RUN: -req=complete -pos=2:11 -repeat-request=2 %s -- %s -parse-as-library \
7+
// RUN: | %FileCheck %s
8+
9+
// CHECK: key.results: [
10+
// CHECK: description: "Int",

test/multifile/batch-mode-llvmIRHash-consistency.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Ensure that the LLVMIR hash of the 2nd compilation in batch mode
22
// is consistent no matter if the first one generates code or not.
33

4+
// This test fails in some configurations.
5+
// REQUIRES: rdar_62338337
6+
47
// RUN: %empty-directory(%t)
58
// RUN: echo 'public enum E: Error {}' >%t/main.swift
69
// RUN: echo >%t/other.swift

unittests/Driver/TypeBodyFingerprintsDependencyGraphTests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,10 @@ TEST(ModuleDepGraph, UseFingerprints) {
808808
{
809809
const auto jobs =
810810
simulateReload(graph, &job0, {{NodeKind::nominal, {"A1@11", "A2@2"}}});
811-
EXPECT_EQ(2u, jobs.size());
811+
EXPECT_EQ(3u, jobs.size());
812812
EXPECT_TRUE(contains(jobs, &job0));
813813
EXPECT_TRUE(contains(jobs, &job1));
814-
EXPECT_FALSE(contains(jobs, &job2));
814+
EXPECT_TRUE(contains(jobs, &job2));
815815
EXPECT_FALSE(contains(jobs, &job3));
816816
}
817817
}

0 commit comments

Comments
 (0)