Skip to content

Commit 1aef964

Browse files
authored
---
yaml --- r: 293839 b: refs/heads/tensorflow c: 830eebb h: refs/heads/master i: 293837: cfe8718 293835: b67adc1 293831: 953a3a3 293823: 7570ea4
1 parent 5dd1ac5 commit 1aef964

File tree

8 files changed

+236
-34
lines changed

8 files changed

+236
-34
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: bf2c4d951bb1b6d82ab26ad5924a94faf907459c
819+
refs/heads/tensorflow: 830eebb9a4ee3c0fb82f684e3a0ee9d9ab83288c
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/lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/Module.h"
2020
#include "swift/AST/ProtocolConformance.h"
2121
#include "swift/Basic/Lazy.h"
22+
#include "swift/Basic/Platform.h"
2223
#include "swift/Basic/STLExtras.h"
2324
#include "swift/Frontend/Frontend.h"
2425
#include "swift/Frontend/ParseableInterfaceSupport.h"
@@ -826,7 +827,7 @@ class ParseableInterfaceModuleLoaderImpl {
826827
// Assemble the expected path: $PREBUILT_CACHE/Foo.swiftmodule or
827828
// $PREBUILT_CACHE/Foo.swiftmodule/arch.swiftmodule. Note that there's no
828829
// cache key here.
829-
scratch.append(prebuiltCacheDir);
830+
scratch = prebuiltCacheDir;
830831

831832
// FIXME: Would it be possible to only have architecture-specific names
832833
// here? Then we could skip this check.
@@ -845,6 +846,48 @@ class ParseableInterfaceModuleLoaderImpl {
845846
return scratch.str();
846847
}
847848

849+
/// Hack to deal with build systems (including the Swift standard library, at
850+
/// the time of this comment) that aren't yet using target-specific names for
851+
/// multi-target swiftmodules, in case the prebuilt cache is.
852+
Optional<StringRef>
853+
computeFallbackPrebuiltModulePath(llvm::SmallString<256> &scratch) {
854+
namespace path = llvm::sys::path;
855+
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
856+
857+
// Check if the interface file comes from the SDK
858+
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
859+
path::end(interfacePath),
860+
path::begin(sdkPath),
861+
path::end(sdkPath)))
862+
return None;
863+
864+
// If the module isn't target-specific, there's no fallback path.
865+
StringRef inParentDirName =
866+
path::filename(path::parent_path(interfacePath));
867+
if (path::extension(inParentDirName) != ".swiftmodule")
868+
return None;
869+
870+
// If the interface is already using the target-specific name, there's
871+
// nothing else to try.
872+
auto normalizedTarget = getTargetSpecificModuleTriple(ctx.LangOpts.Target);
873+
if (path::stem(modulePath) == normalizedTarget.str())
874+
return None;
875+
876+
// Assemble the expected path:
877+
// $PREBUILT_CACHE/Foo.swiftmodule/target.swiftmodule. Note that there's no
878+
// cache key here.
879+
scratch = prebuiltCacheDir;
880+
path::append(scratch, inParentDirName);
881+
path::append(scratch, normalizedTarget.str());
882+
scratch += ".swiftmodule";
883+
884+
// If there isn't a file at this location, skip returning a path.
885+
if (!fs.exists(scratch))
886+
return None;
887+
888+
return scratch.str();
889+
}
890+
848891
bool isInResourceDir(StringRef path) {
849892
StringRef resourceDir = ctx.SearchPathOpts.RuntimeLibraryPath;
850893
if (resourceDir.empty()) return false;
@@ -926,7 +969,12 @@ class ParseableInterfaceModuleLoaderImpl {
926969
if (!prebuiltCacheDir.empty()) {
927970
llvm::SmallString<256> scratch;
928971
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
929-
auto path = computePrebuiltModulePath(scratch);
972+
Optional<StringRef> path = computePrebuiltModulePath(scratch);
973+
if (!path) {
974+
// Hack: deal with prebuilds of modules that still use the target-based
975+
// names.
976+
path = computeFallbackPrebuiltModulePath(scratch);
977+
}
930978
if (path) {
931979
if (swiftModuleIsUpToDate(*path, deps, moduleBuffer)) {
932980
LLVM_DEBUG(llvm::dbgs() << "Found up-to-date prebuilt module at "

branches/tensorflow/lib/SILOptimizer/Utils/ConstExpr.cpp

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum class WellKnownFunction {
4343
StringInitEmpty,
4444
// String.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)
4545
StringMakeUTF8,
46-
// static String.+= infix(_: inout String, _: String)
46+
// static String.append (_: String, _: inout String)
4747
StringAppend,
4848
// static String.== infix(_: String)
4949
StringEquals
@@ -233,12 +233,11 @@ SymbolicValue ConstExprFunctionState::computeConstantValue(SILValue value) {
233233
if (auto *sei = dyn_cast<StructExtractInst>(value)) {
234234
auto aggValue = sei->getOperand();
235235
auto val = getConstantValue(aggValue);
236-
if (val.isConstant()) {
237-
assert(val.getKind() == SymbolicValue::Aggregate);
238-
return val.getAggregateValue()[sei->getFieldNo()];
236+
if (!val.isConstant()) {
237+
return val;
239238
}
240-
// Not a const.
241-
return val;
239+
assert(val.getKind() == SymbolicValue::Aggregate);
240+
return val.getAggregateValue()[sei->getFieldNo()];
242241
}
243242

244243
// If this is an unchecked_enum_data from a fragile type, then we can return
@@ -375,6 +374,27 @@ SymbolicValue ConstExprFunctionState::computeConstantValue(SILValue value) {
375374
return createMemoryObject(value, enumVal.getEnumPayloadValue());
376375
}
377376

377+
if (isa<SelectEnumInst>(value) || isa<SelectEnumAddrInst>(value)) {
378+
SelectEnumInstBase *selectInst = dyn_cast<SelectEnumInst>(value);
379+
if (!selectInst) {
380+
selectInst = dyn_cast<SelectEnumAddrInst>(value);
381+
}
382+
383+
SILValue enumOperand = selectInst->getEnumOperand();
384+
SymbolicValue enumValue = isa<SelectEnumInst>(selectInst)
385+
? getConstantValue(enumOperand)
386+
: getConstAddrAndLoadResult(enumOperand);
387+
if (!enumValue.isConstant())
388+
return enumValue;
389+
390+
assert(enumValue.getKind() == SymbolicValue::Enum ||
391+
enumValue.getKind() == SymbolicValue::EnumWithPayload);
392+
393+
SILValue resultOperand =
394+
selectInst->getCaseResult(enumValue.getEnumValue());
395+
return getConstantValue(resultOperand);
396+
}
397+
378398
// This instruction is a marker that returns its first operand.
379399
if (auto *bai = dyn_cast<BeginAccessInst>(value))
380400
return getConstantValue(bai->getOperand());
@@ -678,29 +698,35 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
678698
return None;
679699
}
680700
case WellKnownFunction::StringAppend: {
681-
// static String.+= infix(_: inout String, _: String)
701+
// static String.append (_: String, _: inout String)
682702
assert(conventions.getNumDirectSILResults() == 0 &&
683703
conventions.getNumIndirectSILResults() == 0 &&
684-
conventions.getNumParameters() == 3 &&
685-
"unexpected String.+=() signature");
704+
conventions.getNumParameters() == 2 &&
705+
"unexpected String.append() signature");
686706

687-
auto firstOperand = apply->getOperand(1);
688-
auto firstString = getConstAddrAndLoadResult(firstOperand);
689-
if (firstString.getKind() != SymbolicValue::String) {
707+
auto otherString = getConstantValue(apply->getOperand(1));
708+
if (!otherString.isConstant()) {
709+
return otherString;
710+
}
711+
if (otherString.getKind() != SymbolicValue::String) {
690712
return evaluator.getUnknown((SILInstruction *)apply,
691713
UnknownReason::InvalidOperandValue);
692714
}
693715

694-
auto otherString = getConstantValue(apply->getOperand(2));
695-
if (otherString.getKind() != SymbolicValue::String) {
716+
auto inoutOperand = apply->getOperand(2);
717+
auto firstString = getConstAddrAndLoadResult(inoutOperand);
718+
if (!firstString.isConstant()) {
719+
return firstString;
720+
}
721+
if (firstString.getKind() != SymbolicValue::String) {
696722
return evaluator.getUnknown((SILInstruction *)apply,
697723
UnknownReason::InvalidOperandValue);
698724
}
699725

700726
auto result = SmallString<8>(firstString.getStringValue());
701727
result.append(otherString.getStringValue());
702728
auto resultVal = SymbolicValue::getString(result, evaluator.getAllocator());
703-
computeFSStore(resultVal, firstOperand);
729+
computeFSStore(resultVal, inoutOperand);
704730
return None;
705731
}
706732
case WellKnownFunction::StringEquals: {
@@ -1274,6 +1300,11 @@ ConstExprFunctionState::evaluateFlowSensitive(SILInstruction *inst) {
12741300
return computeFSStore(value, copy->getOperand(1));
12751301
}
12761302

1303+
if (auto *injectEnumInst = dyn_cast<InjectEnumAddrInst>(inst)) {
1304+
return computeFSStore(SymbolicValue::getEnum(injectEnumInst->getElement()),
1305+
injectEnumInst->getOperand());
1306+
}
1307+
12771308
// If the instruction produces normal results, try constant folding it.
12781309
// If this fails, then we fail.
12791310
if (inst->getNumResults() != 0) {

branches/tensorflow/stdlib/public/core/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ extension String {
571571

572572
// String append
573573
@inlinable // Forward inlinability to append
574-
@_semantics("string.append")
574+
@_semantics("string.plusequals")
575575
public static func += (lhs: inout String, rhs: String) {
576576
lhs.append(rhs)
577577
}

branches/tensorflow/stdlib/public/core/StringRangeReplaceableCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ extension String: RangeReplaceableCollection {
125125
/// // Prints "Hello, friend"
126126
///
127127
/// - Parameter other: Another string.
128+
@_semantics("string.append")
128129
public mutating func append(_ other: String) {
129130
if self.isEmpty && !_guts.hasNativeStorage {
130131
self = other
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Like prebuilt-module-cache-archs.swift, but testing the fallback behavior.
2+
// This means we have to know the expected names in advance, so this test only
3+
// runs on macOS.
4+
5+
// REQUIRES: OS=macosx
6+
// REQUIRES: CPU=x86_64
7+
8+
// Use the short name "x86_64.swiftmodule".
9+
// RUN: %empty-directory(%t)
10+
// RUN: %empty-directory(%t/include/Lib.swiftmodule)
11+
// RUN: cp %S/Inputs/prebuilt-module-cache/Lib.swiftinterface %t/include/Lib.swiftmodule/x86_64.swiftinterface
12+
13+
// Do a manual prebuild with the long name "x86_64-apple-macos.swiftmodule",
14+
// and see if it gets picked up.
15+
// RUN: %empty-directory(%t/MCP)
16+
// RUN: %empty-directory(%t/prebuilt-cache/Lib.swiftmodule)
17+
// RUN: sed -e 's/FromInterface/FromPrebuiltLong/g' %S/Inputs/prebuilt-module-cache/Lib.swiftinterface | %target-swift-frontend -parse-stdlib -module-cache-path %t/MCP -emit-module-path %t/prebuilt-cache/Lib.swiftmodule/x86_64-apple-macos.swiftmodule - -module-name Lib
18+
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %t/include -I %t/include/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT-LONG %s
19+
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
20+
21+
// Prefer a matching name.
22+
// RUN: %empty-directory(%t/MCP)
23+
// RUN: sed -e 's/FromInterface/FromPrebuiltShort/g' %S/Inputs/prebuilt-module-cache/Lib.swiftinterface | %target-swift-frontend -parse-stdlib -module-cache-path %t/MCP -emit-module-path %t/prebuilt-cache/Lib.swiftmodule/x86_64.swiftmodule - -module-name Lib
24+
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %t/include -I %t/include/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT-SHORT %s
25+
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
26+
27+
// Prefer a matching name in the other direction too.
28+
// RUN: %empty-directory(%t/MCP)
29+
// RUN: mv %t/include/Lib.swiftmodule/x86_64.swiftinterface %t/include/Lib.swiftmodule/x86_64-apple-macos.swiftinterface
30+
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %t/include -I %t/include/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT-LONG %s
31+
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
32+
33+
// Don't do the fallback thing for long names to short names.
34+
// RUN: %empty-directory(%t/MCP)
35+
// RUN: rm %t/prebuilt-cache/Lib.swiftmodule/x86_64-apple-macos.swiftmodule
36+
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %t/include -I %t/include/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
37+
// RUN: not %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
38+
39+
import Lib
40+
41+
struct X {}
42+
let _: X = Lib.testValue
43+
// FROM-INTERFACE: [[@LINE-1]]:16: error: cannot convert value of type 'FromInterface' to specified type 'X'
44+
// FROM-PREBUILT-LONG: [[@LINE-2]]:16: error: cannot convert value of type 'FromPrebuiltLong' to specified type 'X'
45+
// FROM-PREBUILT-SHORT: [[@LINE-3]]:16: error: cannot convert value of type 'FromPrebuiltShort' to specified type 'X'

0 commit comments

Comments
 (0)