Skip to content

Commit 07635b5

Browse files
committed
---
yaml --- r: 327659 b: refs/heads/tensorflow c: 52479ca h: refs/heads/master i: 327657: 8eb0e07 327655: a9e36e7
1 parent 35bc45d commit 07635b5

File tree

11 files changed

+75
-131
lines changed

11 files changed

+75
-131
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: bd3b827fd613fc4d59509d5231366c269e2152fe
819+
refs/heads/tensorflow: 52479cadd5fb4dc73983998186296e7b10aa47d9
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/include/swift/AST/ImportCache.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -140,52 +140,13 @@ class alignas(ModuleDecl::ImportedModule) ImportCache {
140140
return !getAllVisibleAccessPaths(mod, dc).empty();
141141
}
142142

143-
/// Determines if 'mod' is visible from 'dc' as a result of a scoped import.
144-
/// Note that if 'mod' was not imported from 'dc' at all, this also returns
145-
/// false.
146-
bool isScopedImport(const ModuleDecl *mod, DeclBaseName name,
147-
const DeclContext *dc) {
148-
auto accessPaths = getAllVisibleAccessPaths(mod, dc);
149-
for (auto accessPath : accessPaths) {
150-
if (accessPath.empty())
151-
continue;
152-
if (ModuleDecl::matchesAccessPath(accessPath, name))
153-
return true;
154-
}
155-
156-
return false;
157-
}
158-
159143
/// Returns all access paths in 'mod' that are visible from 'dc' if we
160144
/// subtract imports of 'other'.
161145
ArrayRef<ModuleDecl::AccessPathTy>
162146
getAllAccessPathsNotShadowedBy(const ModuleDecl *mod,
163147
const ModuleDecl *other,
164148
const DeclContext *dc);
165149

166-
/// Returns 'true' if a declaration named 'name' defined in 'other' shadows
167-
/// defined in 'mod', because no access paths can find 'name' in 'mod' from
168-
/// 'dc' if we ignore imports of 'other'.
169-
bool isShadowedBy(const ModuleDecl *mod,
170-
const ModuleDecl *other,
171-
DeclBaseName name,
172-
const DeclContext *dc) {
173-
auto accessPaths = getAllAccessPathsNotShadowedBy(mod, other, dc);
174-
return llvm::none_of(accessPaths,
175-
[&](ModuleDecl::AccessPathTy accessPath) {
176-
return ModuleDecl::matchesAccessPath(accessPath, name);
177-
});
178-
}
179-
180-
/// Qualified lookup into types uses a slightly different check that does not
181-
/// take access paths into account.
182-
bool isShadowedBy(const ModuleDecl *mod,
183-
const ModuleDecl *other,
184-
const DeclContext *dc) {
185-
auto accessPaths = getAllAccessPathsNotShadowedBy(mod, other, dc);
186-
return accessPaths.empty();
187-
}
188-
189150
/// This is a hack to cope with main file parsing and REPL parsing, where
190151
/// we can add ImportDecls after name binding.
191152
void clear() {

branches/tensorflow/lib/AST/NameLookup.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,27 @@ static void recordShadowedDeclsAfterSignatureMatch(
193193
auto firstDecl = decls[firstIdx];
194194
auto firstModule = firstDecl->getModuleContext();
195195
auto name = firstDecl->getBaseName();
196+
197+
auto isShadowed = [&](ArrayRef<ModuleDecl::AccessPathTy> paths) {
198+
for (auto path : paths) {
199+
if (ModuleDecl::matchesAccessPath(path, name))
200+
return false;
201+
}
202+
203+
return true;
204+
};
205+
206+
auto isScopedImport = [&](ArrayRef<ModuleDecl::AccessPathTy> paths) {
207+
for (auto path : paths) {
208+
if (path.empty())
209+
continue;
210+
if (ModuleDecl::matchesAccessPath(path, name))
211+
return true;
212+
}
213+
214+
return false;
215+
};
216+
196217
for (unsigned secondIdx : range(firstIdx + 1, decls.size())) {
197218
// Determine whether one module takes precedence over another.
198219
auto secondDecl = decls[secondIdx];
@@ -206,22 +227,28 @@ static void recordShadowedDeclsAfterSignatureMatch(
206227
if (firstModule != secondModule &&
207228
firstDecl->getDeclContext()->isModuleScopeContext() &&
208229
secondDecl->getDeclContext()->isModuleScopeContext()) {
209-
// First, scoped imports shadow unscoped imports.
210-
bool firstScoped = imports.isScopedImport(firstModule, name, dc);
211-
bool secondScoped = imports.isScopedImport(secondModule, name, dc);
212-
if (!firstScoped && secondScoped) {
230+
auto firstPaths = imports.getAllAccessPathsNotShadowedBy(
231+
firstModule, secondModule, dc);
232+
auto secondPaths = imports.getAllAccessPathsNotShadowedBy(
233+
secondModule, firstModule, dc);
234+
235+
// Check if one module shadows the other.
236+
if (isShadowed(firstPaths)) {
213237
shadowed.insert(firstDecl);
214238
break;
215-
} else if (firstScoped && !secondScoped) {
239+
} else if (isShadowed(secondPaths)) {
216240
shadowed.insert(secondDecl);
217241
continue;
218242
}
219243

220-
// Now check if one module shadows the other.
221-
if (imports.isShadowedBy(firstModule, secondModule, name, dc)) {
244+
// We might be in a situation where neither module shadows the
245+
// other, but one declaration is visible via a scoped import.
246+
bool firstScoped = isScopedImport(firstPaths);
247+
bool secondScoped = isScopedImport(secondPaths);
248+
if (!firstScoped && secondScoped) {
222249
shadowed.insert(firstDecl);
223250
break;
224-
} else if (imports.isShadowedBy(secondModule, firstModule, name, dc)) {
251+
} else if (firstScoped && !secondScoped) {
225252
shadowed.insert(secondDecl);
226253
continue;
227254
}
@@ -278,10 +305,16 @@ static void recordShadowedDeclsAfterSignatureMatch(
278305
if (firstModule != secondModule &&
279306
!firstDecl->getDeclContext()->isModuleScopeContext() &&
280307
!secondDecl->getDeclContext()->isModuleScopeContext()) {
281-
if (imports.isShadowedBy(firstModule, secondModule, dc)) {
308+
auto firstPaths = imports.getAllAccessPathsNotShadowedBy(
309+
firstModule, secondModule, dc);
310+
auto secondPaths = imports.getAllAccessPathsNotShadowedBy(
311+
secondModule, firstModule, dc);
312+
313+
// Check if one module shadows the other.
314+
if (isShadowed(firstPaths)) {
282315
shadowed.insert(firstDecl);
283316
break;
284-
} else if (imports.isShadowedBy(secondModule, firstModule, dc)) {
317+
} else if (isShadowed(secondPaths)) {
285318
shadowed.insert(secondDecl);
286319
continue;
287320
}

branches/tensorflow/lib/Sema/CSRanking.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -822,27 +822,17 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
822822
continue;
823823
}
824824

825-
if (choice1.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
826-
if (choice2.getKind() == OverloadChoiceKind::DynamicMemberLookup)
827-
// Dynamic member lookup through a keypath is better than one using
828-
// string because it carries more type information.
829-
score1 += weight;
830-
else
831-
// Otherwise let's prefer non-dynamic declaration.
832-
score2 += weight;
833-
825+
// Dynamic member lookup through a keypath is better than one using string
826+
// because it carries more type information.
827+
if (choice1.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup &&
828+
choice2.getKind() == OverloadChoiceKind::DynamicMemberLookup) {
829+
score1 += weight;
834830
continue;
835831
}
836832

837-
if (choice2.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
838-
if (choice1.getKind() == OverloadChoiceKind::DynamicMemberLookup)
839-
// Dynamic member lookup through a keypath is better than one using
840-
// string because it carries more type information.
841-
score2 += weight;
842-
else
843-
// Otherwise let's prefer non-dynamic declaration.
844-
score1 += weight;
845-
833+
if (choice1.getKind() == OverloadChoiceKind::DynamicMemberLookup &&
834+
choice2.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
835+
score2 += weight;
846836
continue;
847837
}
848838

branches/tensorflow/lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222
#include "swift/AST/Pattern.h"
2323
#include "swift/Basic/Defer.h"
2424
#include "swift/Basic/SourceManager.h"
25-
#include "swift/Basic/Statistic.h"
2625
#include "swift/Basic/StringExtras.h"
2726
#include "swift/Parse/Lexer.h"
2827
#include "swift/Parse/Parser.h"
2928
#include "swift/Sema/IDETypeChecking.h"
3029
#include "llvm/ADT/MapVector.h"
3130
#include "llvm/ADT/StringSwitch.h"
3231
#include "llvm/Support/SaveAndRestore.h"
33-
34-
#define DEBUG_TYPE "Sema"
3532
using namespace swift;
3633

3734
/// Return true if this expression is an implicit promotion from T to T?.
@@ -1995,10 +1992,6 @@ class VarDeclUsageChecker : public ASTWalker {
19951992
/// This is a mapping from VarDecls to the if/while/guard statement that they
19961993
/// occur in, when they are in a pattern in a StmtCondition.
19971994
llvm::SmallDenseMap<VarDecl*, LabeledConditionalStmt*> StmtConditionForVD;
1998-
1999-
#ifndef NDEBUG
2000-
llvm::SmallPtrSet<Expr*, 32> AllExprsSeen;
2001-
#endif
20021995

20031996
bool sawError = false;
20041997

@@ -2739,19 +2732,13 @@ void VarDeclUsageChecker::markStoredOrInOutExpr(Expr *E, unsigned Flags) {
27392732

27402733
/// The heavy lifting happens when visiting expressions.
27412734
std::pair<bool, Expr *> VarDeclUsageChecker::walkToExprPre(Expr *E) {
2742-
STATISTIC(VarDeclUsageCheckerExprVisits,
2743-
"# of times VarDeclUsageChecker::walkToExprPre is called");
2744-
++VarDeclUsageCheckerExprVisits;
2745-
27462735
// Sema leaves some subexpressions null, which seems really unfortunate. It
27472736
// should replace them with ErrorExpr.
27482737
if (E == nullptr || !E->getType() || E->getType()->hasError()) {
27492738
sawError = true;
27502739
return { false, E };
27512740
}
27522741

2753-
assert(AllExprsSeen.insert(E).second && "duplicate traversal");
2754-
27552742
// If this is a DeclRefExpr found in a random place, it is a load of the
27562743
// vardecl.
27572744
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -2796,13 +2783,9 @@ std::pair<bool, Expr *> VarDeclUsageChecker::walkToExprPre(Expr *E) {
27962783
return { false, E };
27972784
}
27982785

2799-
// If we see an OpenExistentialExpr, remember the mapping for its OpaqueValue
2800-
// and only walk the subexpr.
2801-
if (auto *oee = dyn_cast<OpenExistentialExpr>(E)) {
2786+
// If we see an OpenExistentialExpr, remember the mapping for its OpaqueValue.
2787+
if (auto *oee = dyn_cast<OpenExistentialExpr>(E))
28022788
OpaqueValueMap[oee->getOpaqueValue()] = oee->getExistentialValue();
2803-
oee->getSubExpr()->walk(*this);
2804-
return { false, E };
2805-
}
28062789

28072790
// Visit bindings.
28082791
if (auto ove = dyn_cast<OpaqueValueExpr>(E)) {

branches/tensorflow/test/Constraints/keypath_dynamic_member_lookup.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -367,26 +367,3 @@ func make_sure_delayed_keypath_dynamic_member_works() {
367367
}
368368
}
369369
}
370-
371-
372-
// SR-11465 - Ambiguity in expression which matches both dynamic member lookup and declaration from constrained extension
373-
374-
@dynamicMemberLookup
375-
struct SR_11465<RawValue> {
376-
var rawValue: RawValue
377-
378-
subscript<Subject>(dynamicMember keyPath: KeyPath<RawValue, Subject>) -> Subject {
379-
rawValue[keyPath: keyPath]
380-
}
381-
}
382-
383-
extension SR_11465: Hashable, Equatable where RawValue: Hashable {
384-
func hash(into hasher: inout Hasher) {
385-
hasher.combine(self.rawValue)
386-
}
387-
}
388-
389-
func test_constrained_ext_vs_dynamic_member() {
390-
// CHECK: function_ref @$s29keypath_dynamic_member_lookup8SR_11465VAASHRzlE9hashValueSivg
391-
_ = SR_11465<Int>(rawValue: 1).hashValue // Ok, keep choice from constrained extension
392-
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@_exported import asdf
2+
3+
public struct S { public init(x: Int) {} }
4+
public struct D { public init(x: Int) {} }
5+
public struct F { public init(x: Int) {} }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/asdf.swift
3+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/sdf.swift -I %t
4+
// RUN: %target-swift-frontend -typecheck %s -I %t -verify
5+
6+
import asdf
7+
import sdf
8+
import struct sdf.S
9+
10+
var uS: S = sdf.S(x: 123)

branches/tensorflow/test/ParseableInterface/inherited-generic-parameters.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
44
// RUN: %FileCheck %s < %t/main.swiftinterface
55

6-
// RUN: %target-swift-frontend -emit-module -module-name main -primary-file %s -emit-module-path %t/main~partial.swiftmodule -enable-library-evolution
6+
// RUN: %target-build-swift %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
7+
// RUN: %FileCheck %s < %t/main.swiftinterface
78

8-
// RUN: %target-swift-frontend -merge-modules %t/main~partial.swiftmodule -emit-module-path %t/main.swiftmodule -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
9+
// RUN: %target-build-swift %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution -wmo
910
// RUN: %FileCheck %s < %t/main.swiftinterface
1011

1112
// This test makes sure that we substitute uses of the superclass's generic

branches/tensorflow/test/ParseableInterface/where-clause.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
44
// RUN: %FileCheck %s < %t/main.swiftinterface
55

6-
// RUN: %target-swift-frontend -emit-module -module-name main -primary-file %s -emit-module-path %t/main~partial.swiftmodule -enable-library-evolution
6+
// RUN: %target-build-swift %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
7+
// RUN: %FileCheck %s < %t/main.swiftinterface
78

8-
// RUN: %target-swift-frontend -merge-modules %t/main~partial.swiftmodule -emit-module-path %t/main.swiftmodule -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
9+
// RUN: %target-build-swift %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution -wmo
910
// RUN: %FileCheck %s < %t/main.swiftinterface
1011

1112
// CHECK: import Swift

branches/tensorflow/validation-test/compiler_scale/var_decl_usage_checker.swift.gyb

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)