Skip to content

[pull] swiftwasm-release/5.3 from release/5.3 #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,8 @@ class Parser {
std::pair<std::vector<Decl *>, Optional<std::string>>
parseDeclListDelayed(IterableDeclContext *IDC);

bool parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
SourceLoc PosBeforeLB,
Diag<> ErrorDiag,
bool parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
Diag<> LBraceDiag, Diag<> RBraceDiag,
IterableDeclContext *IDC);

bool canDelayMemberDeclParsing(bool &HasOperatorDeclarations,
Expand Down
22 changes: 19 additions & 3 deletions lib/AST/AbstractSourceFileDepGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,30 @@ void AbstractSourceFileDepGraphFactory::addAUsedDecl(
const DependencyKey &defKey, const DependencyKey &useKey) {
auto *defNode =
g.findExistingNodeOrCreateIfNew(defKey, None, false /* = !isProvides */);

// If the depended-upon node is defined in this file, then don't
// create an arc to the user, when the user is the whole file.
// Otherwise, if the defNode's type-body fingerprint changes,
// the whole file will be marked as dirty, losing the benefit of the
// fingerprint.
if (defNode->getIsProvides() &&
useKey.getKind() == NodeKind::sourceFileProvide)
return;

// if (defNode->getIsProvides() &&
// useKey.getKind() == NodeKind::sourceFileProvide)
// return;

// Turns out the above three lines cause miscompiles, so comment them out
// for now. We might want them back if we can change the inputs to this
// function to be more precise.

// Example of a miscompile:
// In main.swift
// func foo(_: Any) { print("Hello Any") }
// foo(123)
// Then add the following line to another file:
// func foo(_: Int) { print("Hello Int") }
// Although main.swift needs to get recompiled, the commented-out code below
// prevents that.

auto nullableUse = g.findExistingNode(useKey);
assert(nullableUse.isNonNull() && "Use must be an already-added provides");
auto *useNode = nullableUse.get();
Expand Down
66 changes: 27 additions & 39 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4425,10 +4425,18 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
return Result;
}

bool Parser::parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
SourceLoc PosBeforeLB,
Diag<> ErrorDiag,
bool Parser::parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
Diag<> LBraceDiag, Diag<> RBraceDiag,
IterableDeclContext *IDC) {
if (parseToken(tok::l_brace, LBLoc, LBraceDiag)) {
LBLoc = RBLoc = PreviousLoc;

// Cache the empty result to prevent delayed parsing.
Context.evaluator.cacheOutput(
ParseMembersRequest{IDC}, FingerprintAndMembers{None, {}});
return true;
}

bool HasOperatorDeclarations;
bool HasNestedClassDeclarations;

Expand All @@ -4447,7 +4455,7 @@ bool Parser::parseMemberDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
bool hadError = false;
ParseDeclOptions Options = getMemberParseDeclOptions(IDC);
auto membersAndHash =
parseDeclList(LBLoc, RBLoc, ErrorDiag, Options, IDC, hadError);
parseDeclList(LBLoc, RBLoc, RBraceDiag, Options, IDC, hadError);
IDC->setMaybeHasOperatorDeclarations();
IDC->setMaybeHasNestedClassDeclarations();
Context.evaluator.cacheOutput(
Expand Down Expand Up @@ -4617,16 +4625,12 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
SourceLoc LBLoc, RBLoc;

auto PosBeforeLB = Tok.getLoc();
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_extension)) {
LBLoc = PreviousLoc;
RBLoc = LBLoc;
status.setIsParseError();
} else {
{
ContextChange CC(*this, ext);
Scope S(this, ScopeKind::Extension);

if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
if (parseMemberDeclList(LBLoc, RBLoc,
diag::expected_lbrace_extension,
diag::expected_rbrace_extension,
ext))
status.setIsParseError();
Expand Down Expand Up @@ -6578,15 +6582,11 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,

SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
SourceLoc LBLoc, RBLoc;
SourceLoc PosBeforeLB = Tok.getLoc();
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_enum)) {
LBLoc = PreviousLoc;
RBLoc = LBLoc;
Status.setIsParseError();
} else {
{
Scope S(this, ScopeKind::EnumBody);

if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
if (parseMemberDeclList(LBLoc, RBLoc,
diag::expected_lbrace_enum,
diag::expected_rbrace_enum,
ED))
Status.setIsParseError();
Expand Down Expand Up @@ -6864,16 +6864,12 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
// Make the entities of the struct as a code block.
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
SourceLoc LBLoc, RBLoc;
SourceLoc PosBeforeLB = Tok.getLoc();
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
LBLoc = PreviousLoc;
RBLoc = LBLoc;
Status.setIsParseError();
} else {
{
// Parse the body.
Scope S(this, ScopeKind::StructBody);

if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
if (parseMemberDeclList(LBLoc, RBLoc,
diag::expected_lbrace_struct,
diag::expected_rbrace_struct,
SD))
Status.setIsParseError();
Expand Down Expand Up @@ -6980,16 +6976,12 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,

SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
SourceLoc LBLoc, RBLoc;
auto PosBeforeLB = Tok.getLoc();
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_class)) {
LBLoc = PreviousLoc;
RBLoc = LBLoc;
Status.setIsParseError();
} else {
{
// Parse the body.
Scope S(this, ScopeKind::ClassBody);

if (parseMemberDeclList(LBLoc, RBLoc, PosBeforeLB,
if (parseMemberDeclList(LBLoc, RBLoc,
diag::expected_lbrace_class,
diag::expected_rbrace_class,
CD))
Status.setIsParseError();
Expand Down Expand Up @@ -7081,14 +7073,10 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
SyntaxParsingContext BlockContext(SyntaxContext, SyntaxKind::MemberDeclBlock);
SourceLoc LBraceLoc;
SourceLoc RBraceLoc;
SourceLoc PosBeforeLB = Tok.getLoc();
if (parseToken(tok::l_brace, LBraceLoc, diag::expected_lbrace_protocol)) {
LBraceLoc = PreviousLoc;
RBraceLoc = LBraceLoc;
Status.setIsParseError();
} else {
{
// Parse the members.
if (parseMemberDeclList(LBraceLoc, RBraceLoc, PosBeforeLB,
if (parseMemberDeclList(LBraceLoc, RBraceLoc,
diag::expected_lbrace_protocol,
diag::expected_rbrace_protocol,
Proto))
Status.setIsParseError();
Expand Down
14 changes: 13 additions & 1 deletion lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,19 @@ namespace {
ConstraintKind::CheckedCast, subPatternType, castType,
locator.withPathElement(LocatorPathElt::PatternMatch(pattern)));

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

case PatternKind::Bool:
Expand Down
17 changes: 17 additions & 0 deletions test/Constraints/patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,20 @@ func rdar_60048356() {
}
}
}

// rdar://problem/63510989 - valid pattern doesn't type-check
func rdar63510989() {
enum Value : P {
func p() {}
}

enum E {
case foo(P?)
}

func test(e: E) {
if case .foo(_ as Value) = e {} // Ok
if case .foo(let v as Value) = e {} // Ok
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
}
}
7 changes: 1 addition & 6 deletions test/Frontend/Fingerprints/class-fingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,4 @@

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

// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4

// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}

// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4
7 changes: 1 addition & 6 deletions test/Frontend/Fingerprints/enum-fingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,4 @@

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

// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4

// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}

// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4
6 changes: 1 addition & 5 deletions test/Frontend/Fingerprints/protocol-fingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,5 @@

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

// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4

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

7 changes: 1 addition & 6 deletions test/Frontend/Fingerprints/struct-fingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,4 @@

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

// RUN: %FileCheck -check-prefix=CHECK-MAINB-RECOMPILED %s < %t/output4

// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}
// CHECK-MAINB-RECOMPILED: Queuing because of dependencies discovered later: {compile: usesA.o <= usesA.swift}
// CHECK-MAINB-RECOMPILED-NOT: Queuing because of dependencies discovered later: {compile: usesB.o <= usesB.swift}

// RUN: %FileCheck -check-prefix=CHECK-MAINAB-RECOMPILED %s < %t/output4
1 change: 1 addition & 0 deletions test/IRGen/framepointer_arm64.sil
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-swift-frontend -target arm64-apple-ios8.0 -primary-file %s -S -no-omit-leaf-frame-pointer | %FileCheck %s --check-prefix=CHECKASM-ALL

// REQUIRES: CODEGENERATOR=AArch64
// REQUIRES: OS=ios

// UNSUPPORTED: OS=linux-gnu
// UNSUPPORTED: OS=windows
Expand Down
10 changes: 10 additions & 0 deletions test/SourceKit/CodeComplete/complete_sequence_innertype.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func test() {
class C:
}

// RUN: %sourcekitd-test \
// RUN: -req=complete -pos=2:11 -repeat-request=2 %s -- %s -parse-as-library \
// RUN: | %FileCheck %s

// CHECK: key.results: [
// CHECK: description: "Int",
3 changes: 3 additions & 0 deletions test/multifile/batch-mode-llvmIRHash-consistency.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Ensure that the LLVMIR hash of the 2nd compilation in batch mode
// is consistent no matter if the first one generates code or not.

// This test fails in some configurations.
// REQUIRES: rdar_62338337

// RUN: %empty-directory(%t)
// RUN: echo 'public enum E: Error {}' >%t/main.swift
// RUN: echo >%t/other.swift
Expand Down
4 changes: 2 additions & 2 deletions unittests/Driver/TypeBodyFingerprintsDependencyGraphTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ TEST(ModuleDepGraph, UseFingerprints) {
{
const auto jobs =
simulateReload(graph, &job0, {{NodeKind::nominal, {"A1@11", "A2@2"}}});
EXPECT_EQ(2u, jobs.size());
EXPECT_EQ(3u, jobs.size());
EXPECT_TRUE(contains(jobs, &job0));
EXPECT_TRUE(contains(jobs, &job1));
EXPECT_FALSE(contains(jobs, &job2));
EXPECT_TRUE(contains(jobs, &job2));
EXPECT_FALSE(contains(jobs, &job3));
}
}
Expand Down