Skip to content

Commit 0b1b2ee

Browse files
authored
---
yaml --- r: 349115 b: refs/heads/master c: ca19a9d h: refs/heads/master i: 349113: 0c45e7e 349111: 549117a
1 parent 2338e4e commit 0b1b2ee

34 files changed

+470
-87
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f15544de0b1cbb9cbcdbb1b5b83fd6fac008db79
2+
refs/heads/master: ca19a9d12fe3e819cdc1c61f008f3a07daae0008
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ option(SWIFT_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING
377377
"Build stdlibCore with exclusivity checking enabled"
378378
FALSE)
379379

380+
option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
381+
"Enable experimental Swift differentiable programming features"
382+
FALSE)
383+
380384
#
381385
# End of user-configurable options.
382386
#

trunk/benchmark/single-source/UTF8Decode.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public let UTF8Decode = [
4242
name: "UTF8Decode_InitFromBytes_ascii",
4343
runFunction: run_UTF8Decode_InitFromBytes_ascii,
4444
tags: [.validation, .api, .String]),
45+
BenchmarkInfo(
46+
name: "UTF8Decode_InitFromData_ascii_as_ascii",
47+
runFunction: run_UTF8Decode_InitFromData_ascii_as_ascii,
48+
tags: [.validation, .api, .String]),
49+
BenchmarkInfo(
50+
name: "UTF8Decode_InitDecoding_ascii_as_ascii",
51+
runFunction: run_UTF8Decode_InitDecoding_ascii_as_ascii,
52+
tags: [.validation, .api, .String]),
53+
BenchmarkInfo(
54+
name: "UTF8Decode_InitFromBytes_ascii_as_ascii",
55+
runFunction: run_UTF8Decode_InitFromBytes_ascii_as_ascii,
56+
tags: [.validation, .api, .String]),
4557
]
4658

4759
// 1-byte sequences
@@ -129,4 +141,26 @@ public func run_UTF8Decode_InitFromBytes_ascii(_ N: Int) {
129141
}
130142
}
131143

144+
@inline(never)
145+
public func run_UTF8Decode_InitFromData_ascii_as_ascii(_ N: Int) {
146+
let input = asciiData
147+
for _ in 0..<1_000*N {
148+
blackHole(String(data: input, encoding: .ascii))
149+
}
150+
}
151+
@inline(never)
152+
public func run_UTF8Decode_InitDecoding_ascii_as_ascii(_ N: Int) {
153+
let input = asciiBytes
154+
for _ in 0..<1_000*N {
155+
blackHole(String(decoding: input, as: Unicode.ASCII.self))
156+
}
157+
}
158+
@inline(never)
159+
public func run_UTF8Decode_InitFromBytes_ascii_as_ascii(_ N: Int) {
160+
let input = asciiBytes
161+
for _ in 0..<1_000*N {
162+
blackHole(String(bytes: input, encoding: .ascii))
163+
}
164+
}
165+
132166

trunk/cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ function(_add_variant_swift_compile_flags
422422
list(APPEND result "-D" "SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS")
423423
endif()
424424

425+
if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
426+
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING")
427+
endif()
428+
425429
set("${result_var_name}" "${result}" PARENT_SCOPE)
426430
endfunction()
427431

trunk/include/swift/AST/AnyFunctionRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class AnyFunctionRef {
5252
}
5353
}
5454

55-
const CaptureInfo &getCaptureInfo() const {
55+
CaptureInfo getCaptureInfo() const {
5656
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
5757
return AFD->getCaptureInfo();
5858
return TheFunction.get<AbstractClosureExpr *>()->getCaptureInfo();
5959
}
6060

61-
void setCaptureInfo(const CaptureInfo &captures) const {
61+
void setCaptureInfo(CaptureInfo captures) const {
6262
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
6363
AFD->setCaptureInfo(captures);
6464
return;

trunk/include/swift/AST/Decl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,8 @@ class PatternBindingEntry {
20212021
/// from the source range.
20222022
SourceRange getSourceRange(bool omitAccessors = false) const;
20232023

2024-
const CaptureInfo &getCaptureInfo() const { return Captures; }
2025-
void setCaptureInfo(const CaptureInfo &captures) { Captures = captures; }
2024+
CaptureInfo getCaptureInfo() const { return Captures; }
2025+
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }
20262026

20272027
private:
20282028
SourceLoc getLastAccessorEndLoc() const;
@@ -2126,11 +2126,11 @@ class PatternBindingDecl final : public Decl,
21262126
return getPatternList()[i].getInitContext();
21272127
}
21282128

2129-
const CaptureInfo &getCaptureInfo(unsigned i) const {
2129+
CaptureInfo getCaptureInfo(unsigned i) const {
21302130
return getPatternList()[i].getCaptureInfo();
21312131
}
21322132

2133-
void setCaptureInfo(unsigned i, const CaptureInfo &captures) {
2133+
void setCaptureInfo(unsigned i, CaptureInfo captures) {
21342134
getMutablePatternList()[i].setCaptureInfo(captures);
21352135
}
21362136

@@ -5237,12 +5237,12 @@ class ParamDecl : public VarDecl {
52375237

52385238
void setDefaultArgumentInitContext(Initializer *initContext);
52395239

5240-
const CaptureInfo &getDefaultArgumentCaptureInfo() const {
5240+
CaptureInfo getDefaultArgumentCaptureInfo() const {
52415241
assert(DefaultValueAndFlags.getPointer());
52425242
return DefaultValueAndFlags.getPointer()->Captures;
52435243
}
52445244

5245-
void setDefaultArgumentCaptureInfo(const CaptureInfo &captures);
5245+
void setDefaultArgumentCaptureInfo(CaptureInfo captures);
52465246

52475247
/// Extracts the text of the default argument attached to the provided
52485248
/// ParamDecl, removing all inactive #if clauses and providing only the
@@ -5814,8 +5814,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
58145814
/// Retrieve the source range of the function declaration name + patterns.
58155815
SourceRange getSignatureSourceRange() const;
58165816

5817-
const CaptureInfo &getCaptureInfo() const { return Captures; }
5818-
void setCaptureInfo(const CaptureInfo &captures) { Captures = captures; }
5817+
CaptureInfo getCaptureInfo() const { return Captures; }
5818+
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }
58195819

58205820
/// Retrieve the Objective-C selector that names this method.
58215821
ObjCSelector getObjCSelector(DeclName preferredName = DeclName(),

trunk/include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,7 @@ class AbstractClosureExpr : public DeclContext, public Expr {
34493449
Bits.AbstractClosureExpr.Discriminator = Discriminator;
34503450
}
34513451

3452-
const CaptureInfo &getCaptureInfo() const { return Captures; }
3452+
CaptureInfo getCaptureInfo() const { return Captures; }
34533453
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }
34543454

34553455
/// Retrieve the parameters of this closure.

trunk/include/swift/AST/Initializer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ class SerializedPatternBindingInitializer : public SerializedLocalDeclContext {
150150
/// A default argument expression. The parent context is the function
151151
/// (possibly a closure) for which this is a default argument.
152152
class DefaultArgumentInitializer : public Initializer {
153-
friend class ASTContext; // calls reset on unused contexts
154-
void reset(DeclContext *parent, unsigned index) {
155-
setParent(parent);
156-
SpareBits = index;
157-
}
158-
159153
public:
160154
explicit DefaultArgumentInitializer(DeclContext *parent, unsigned index)
161155
: Initializer(InitializerKind::DefaultArgument, parent) {

trunk/include/swift/SIL/SILArgumentConvention.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@
1717

1818
namespace swift {
1919

20-
enum class InoutAliasingAssumption {
21-
/// Assume that an inout indirect parameter may alias other objects.
22-
/// This is the safe assumption an optimization should make if it may break
23-
/// memory safety in case the inout aliasing rule is violation.
24-
Aliasing,
25-
26-
/// Assume that an inout indirect parameter cannot alias other objects.
27-
/// Optimizations should only use this if they can guarantee that they will
28-
/// not break memory safety even if the inout aliasing rule is violated.
29-
NotAliasing
30-
};
31-
3220
/// Conventions for apply operands and function-entry arguments in SIL.
3321
///
3422
/// This is simply a union of ParameterConvention and ResultConvention
@@ -142,19 +130,14 @@ struct SILArgumentConvention {
142130
}
143131

144132
/// Returns true if \p Value is a not-aliasing indirect parameter.
145-
/// The \p isInoutAliasing specifies what to assume about the inout
146-
/// convention.
147-
/// See InoutAliasingAssumption.
148-
bool isNotAliasedIndirectParameter(InoutAliasingAssumption isInoutAliasing) {
133+
bool isNotAliasedIndirectParameter() {
149134
switch (Value) {
150135
case SILArgumentConvention::Indirect_In:
151136
case SILArgumentConvention::Indirect_In_Constant:
152137
case SILArgumentConvention::Indirect_Out:
153138
case SILArgumentConvention::Indirect_In_Guaranteed:
154-
return true;
155-
156139
case SILArgumentConvention::Indirect_Inout:
157-
return isInoutAliasing == InoutAliasingAssumption::NotAliasing;
140+
return true;
158141

159142
case SILArgumentConvention::Indirect_InoutAliasable:
160143
case SILArgumentConvention::Direct_Unowned:

trunk/include/swift/SIL/SILConstants.h

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct DerivedAddressValue;
3333
struct EnumWithPayloadSymbolicValue;
3434
struct SymbolicValueMemoryObject;
3535
struct UnknownSymbolicValue;
36+
struct SymbolicClosure;
3637

3738
extern llvm::cl::opt<unsigned> ConstExprLimit;
3839

@@ -261,6 +262,9 @@ class SymbolicValue {
261262

262263
/// This represents an array.
263264
RK_Array,
265+
266+
/// This represents a closure.
267+
RK_Closure,
264268
};
265269

266270
union {
@@ -305,7 +309,7 @@ class SymbolicValue {
305309
/// information about the memory object and access path of the access.
306310
DerivedAddressValue *derivedAddress;
307311

308-
// The following fields are for representing an Array.
312+
// The following two fields are for representing an Array.
309313
//
310314
// In Swift, an array is a non-trivial struct that stores a reference to an
311315
// internal storage: _ContiguousArrayStorage. Though arrays have value
@@ -329,6 +333,10 @@ class SymbolicValue {
329333
/// When this symbolic value is of an "Array" kind, this stores a memory
330334
/// object that contains a SymbolicArrayStorage value.
331335
SymbolicValueMemoryObject *array;
336+
337+
/// When this symbolic value is of "Closure" kind, store a pointer to the
338+
/// symbolic representation of the closure.
339+
SymbolicClosure *closure;
332340
} value;
333341

334342
RepresentationKind representationKind : 8;
@@ -384,6 +392,9 @@ class SymbolicValue {
384392
/// This represents an array value.
385393
Array,
386394

395+
/// This represents a closure.
396+
Closure,
397+
387398
/// These values are generally only seen internally to the system, external
388399
/// clients shouldn't have to deal with them.
389400
UninitMemory
@@ -533,6 +544,22 @@ class SymbolicValue {
533544
/// Return the type of this array symbolic value.
534545
Type getArrayType() const;
535546

547+
/// Create and return a symbolic value that represents a closure.
548+
/// \param target SILFunction corresponding the target of the closure.
549+
/// \param capturedArguments an array consisting of SILValues of captured
550+
/// arguments along with their symbolic values when available.
551+
/// \param allocator the allocator to use for storing the contents of this
552+
/// symbolic value.
553+
static SymbolicValue makeClosure(
554+
SILFunction *target,
555+
ArrayRef<std::pair<SILValue, Optional<SymbolicValue>>> capturedArguments,
556+
SymbolicValueAllocator &allocator);
557+
558+
SymbolicClosure *getClosure() const {
559+
assert(getKind() == Closure);
560+
return value.closure;
561+
}
562+
536563
//===--------------------------------------------------------------------===//
537564
// Helpers
538565

@@ -607,6 +634,57 @@ struct SymbolicValueMemoryObject {
607634
SymbolicValueMemoryObject(const SymbolicValueMemoryObject &) = delete;
608635
void operator=(const SymbolicValueMemoryObject &) = delete;
609636
};
637+
638+
using SymbolicClosureArgument = std::pair<SILValue, Optional<SymbolicValue>>;
639+
640+
/// Representation of a symbolic closure. A symbolic closure consists of a
641+
/// SILFunction and an array of SIL values, corresponding to the captured
642+
/// arguments, and (optional) symbolic values representing the constant values
643+
/// of the captured arguments. The symbolic values are optional as it is not
644+
/// necessary for every captured argument to be a constant, which enables
645+
/// representing closures whose captured arguments are not compile-time
646+
/// constants.
647+
struct SymbolicClosure final
648+
: private llvm::TrailingObjects<SymbolicClosure, SymbolicClosureArgument> {
649+
650+
friend class llvm::TrailingObjects<SymbolicClosure, SymbolicClosureArgument>;
651+
652+
private:
653+
654+
SILFunction *target;
655+
656+
// The number of SIL values captured by the closure.
657+
unsigned numCaptures;
658+
659+
// True iff there exists captured arguments whose constant value is not known.
660+
bool hasNonConstantCaptures = true;
661+
662+
SymbolicClosure() = delete;
663+
SymbolicClosure(const SymbolicClosure &) = delete;
664+
SymbolicClosure(SILFunction *callee, unsigned numArguments,
665+
bool nonConstantCaptures)
666+
: target(callee), numCaptures(numArguments),
667+
hasNonConstantCaptures(nonConstantCaptures) {}
668+
669+
public:
670+
static SymbolicClosure *create(SILFunction *callee,
671+
ArrayRef<SymbolicClosureArgument> args,
672+
SymbolicValueAllocator &allocator);
673+
674+
ArrayRef<SymbolicClosureArgument> getCaptures() const {
675+
return {getTrailingObjects<SymbolicClosureArgument>(), numCaptures};
676+
}
677+
678+
// This is used by the llvm::TrailingObjects base class.
679+
size_t numTrailingObjects(OverloadToken<SymbolicClosureArgument>) const {
680+
return numCaptures;
681+
}
682+
683+
SILFunction *getTarget() {
684+
return target;
685+
}
686+
};
687+
610688
} // end namespace swift
611689

612690
#endif

trunk/include/swift/SILOptimizer/Analysis/ValueTracking.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ namespace swift {
2626
/// any other pointer in the function.
2727
/// The \p assumeInoutIsNotAliasing specifies in no-aliasing is assumed for
2828
/// the @inout convention. See swift::isNotAliasedIndirectParameter().
29-
bool isNotAliasingArgument(SILValue V, InoutAliasingAssumption isInoutAliasing =
30-
InoutAliasingAssumption::Aliasing);
29+
bool isNotAliasingArgument(SILValue V);
3130

3231
/// Returns true if \p V is local inside its function. This means its underlying
3332
/// object either is a non-aliasing function argument or a locally allocated
3433
/// object.
3534
/// The \p assumeInoutIsNotAliasing specifies in no-aliasing is assumed for
3635
/// the @inout convention. See swift::isNotAliasedIndirectParameter().
37-
bool pointsToLocalObject(SILValue V, InoutAliasingAssumption isInoutAliasing =
38-
InoutAliasingAssumption::Aliasing);
36+
bool pointsToLocalObject(SILValue V);
3937

4038
enum class IsZeroKind {
4139
Zero,

trunk/lib/AST/Decl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,11 +5643,16 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
56435643
if (AD->isGetter() && !AD->getAccessorKeywordLoc().isValid())
56445644
return;
56455645
}
5646-
5646+
56475647
auto &d = getASTContext().Diags;
5648-
d.diagnose(FD->getFuncLoc(), diag::change_to_mutating,
5649-
isa<AccessorDecl>(FD))
5650-
.fixItInsert(FD->getFuncLoc(), "mutating ");
5648+
auto diags = d.diagnose(FD->getFuncLoc(), diag::change_to_mutating,
5649+
isa<AccessorDecl>(FD));
5650+
if (auto nonmutatingAttr =
5651+
FD->getAttrs().getAttribute<NonMutatingAttr>()) {
5652+
diags.fixItReplace(nonmutatingAttr->getLocation(), "mutating");
5653+
} else {
5654+
diags.fixItInsert(FD->getFuncLoc(), "mutating ");
5655+
}
56515656
return;
56525657
}
56535658
}
@@ -5850,7 +5855,7 @@ void ParamDecl::setDefaultArgumentInitContext(Initializer *initContext) {
58505855
DefaultValueAndFlags.getPointer()->InitContext = initContext;
58515856
}
58525857

5853-
void ParamDecl::setDefaultArgumentCaptureInfo(const CaptureInfo &captures) {
5858+
void ParamDecl::setDefaultArgumentCaptureInfo(CaptureInfo captures) {
58545859
assert(DefaultValueAndFlags.getPointer());
58555860
DefaultValueAndFlags.getPointer()->Captures = captures;
58565861
}

0 commit comments

Comments
 (0)