Skip to content

Commit 676dfbe

Browse files
authored
---
yaml --- r: 349138 b: refs/heads/master c: 4f4557c h: refs/heads/master
1 parent a02a741 commit 676dfbe

File tree

80 files changed

+741
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+741
-335
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: d1072621ba984cb737a8de1b799debbb87b5ab1f
2+
refs/heads/master: 4f4557ceac91a0bfce53036cae10ac8048571db0
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/Decl.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace swift {
7171
class GenericTypeParamDecl;
7272
class GenericTypeParamType;
7373
class ModuleDecl;
74+
class NamedPattern;
7475
class EnumCaseDecl;
7576
class EnumElementDecl;
7677
class ParameterList;
@@ -4773,6 +4774,8 @@ enum class PropertyWrapperSynthesizedPropertyKind {
47734774

47744775
/// VarDecl - 'var' and 'let' declarations.
47754776
class VarDecl : public AbstractStorageDecl {
4777+
NamedPattern *NamingPattern = nullptr;
4778+
47764779
public:
47774780
enum class Introducer : uint8_t {
47784781
Let = 0,
@@ -4786,10 +4789,6 @@ class VarDecl : public AbstractStorageDecl {
47864789
bool issCaptureList, SourceLoc nameLoc, Identifier name,
47874790
DeclContext *dc, StorageIsMutable_t supportsMutation);
47884791

4789-
TypeRepr *ParentRepr = nullptr;
4790-
4791-
Type typeInContext;
4792-
47934792
public:
47944793
VarDecl(bool isStatic, Introducer introducer, bool isCaptureList,
47954794
SourceLoc nameLoc, Identifier name, DeclContext *dc)
@@ -4806,26 +4805,10 @@ class VarDecl : public AbstractStorageDecl {
48064805
return hasName() ? getBaseName().getIdentifier().str() : "_";
48074806
}
48084807

4809-
/// Retrieve the TypeRepr corresponding to the parsed type of the parent
4810-
/// pattern, if it exists.
4811-
TypeRepr *getTypeRepr() const { return ParentRepr; }
4812-
void setTypeRepr(TypeRepr *repr) { ParentRepr = repr; }
4813-
4814-
bool hasType() const {
4815-
// We have a type if either the type has been computed already or if
4816-
// this is a deserialized declaration with an interface type.
4817-
return !typeInContext.isNull();
4818-
}
4819-
48204808
/// Get the type of the variable within its context. If the context is generic,
48214809
/// this will use archetypes.
48224810
Type getType() const;
48234811

4824-
/// Set the type of the variable within its context.
4825-
void setType(Type t);
4826-
4827-
void markInvalid();
4828-
48294812
/// Retrieve the source range of the variable type, or an invalid range if the
48304813
/// variable's type is not explicitly written in the source.
48314814
///
@@ -4864,6 +4847,14 @@ class VarDecl : public AbstractStorageDecl {
48644847
///
48654848
Pattern *getParentPattern() const;
48664849

4850+
/// Returns the parsed type of this variable declaration. For parameters, this
4851+
/// is the parsed type the user explicitly wrote. For variables, this is the
4852+
/// type the user wrote in the typed pattern that binds this variable.
4853+
///
4854+
/// Note that there are many cases where the user may elide types. This will
4855+
/// return null in those cases.
4856+
TypeRepr *getTypeReprOrParentPatternTypeRepr() const;
4857+
48674858
/// Return the statement that owns the pattern associated with this VarDecl,
48684859
/// if one exists.
48694860
///
@@ -4904,6 +4895,9 @@ class VarDecl : public AbstractStorageDecl {
49044895
Parent = v;
49054896
}
49064897

4898+
NamedPattern *getNamingPattern() const { return NamingPattern; }
4899+
void setNamingPattern(NamedPattern *Pat) { NamingPattern = Pat; }
4900+
49074901
/// If this is a VarDecl that does not belong to a CaseLabelItem's pattern,
49084902
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
49094903
/// CaseLabelItem. In that case, return the first case label item of the first
@@ -5158,6 +5152,8 @@ class ParamDecl : public VarDecl {
51585152
SourceLoc ArgumentNameLoc;
51595153
SourceLoc SpecifierLoc;
51605154

5155+
TypeRepr *TyRepr = nullptr;
5156+
51615157
struct StoredDefaultArgument {
51625158
PointerUnion<Expr *, VarDecl *> DefaultArg;
51635159
Initializer *InitContext = nullptr;
@@ -5203,6 +5199,10 @@ class ParamDecl : public VarDecl {
52035199

52045200
SourceLoc getSpecifierLoc() const { return SpecifierLoc; }
52055201

5202+
/// Retrieve the TypeRepr corresponding to the parsed type of the parameter, if it exists.
5203+
TypeRepr *getTypeRepr() const { return TyRepr; }
5204+
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
5205+
52065206
DefaultArgumentKind getDefaultArgumentKind() const {
52075207
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
52085208
}

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ ERROR(pattern_binds_no_variables,none,
15091509
"%select{property|global variable}0 declaration does not bind any "
15101510
"variables",
15111511
(unsigned))
1512+
ERROR(variable_bound_by_no_pattern,none,
1513+
"variable %0 is not bound by any pattern",
1514+
(DeclName))
15121515

15131516
WARNING(optional_ambiguous_case_ref,none,
15141517
"assuming you mean '%0.%2'; did you mean '%1.%2' instead?",

trunk/include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ namespace swift {
202202
/// before termination of the shrink phrase of the constraint solver.
203203
unsigned SolverShrinkUnsolvedThreshold = 10;
204204

205-
/// Enable one-way constraints in function builders.
206-
bool FunctionBuilderOneWayConstraints = true;
207-
208205
/// Disable the shrink phase of the expression type checker.
209206
bool SolverDisableShrink = false;
210207

trunk/include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,6 @@ def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">,
414414

415415
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;
416416

417-
def enable_function_builder_one_way_constraints : Flag<["-"],
418-
"enable-function-builder-one-way-constraints">,
419-
HelpText<"Enable one-way constraints in the function builder transformation">;
420-
421-
def disable_function_builder_one_way_constraints : Flag<["-"],
422-
"disable-function-builder-one-way-constraints">,
423-
HelpText<"Disable one-way constraints in the function builder transformation">;
424-
425417
def solver_disable_shrink :
426418
Flag<["-"], "solver-disable-shrink">,
427419
HelpText<"Disable the shrink phase of expression type checking">;

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/SIL/SILDeclRef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ struct SILDeclRef {
249249
bool isStoredPropertyInitializer() const {
250250
return kind == Kind::StoredPropertyInitializer;
251251
}
252+
/// True if the SILDeclRef references the initializer for the backing storage
253+
/// of a property wrapper.
254+
bool isPropertyWrapperBackingInitializer() const {
255+
return kind == Kind::PropertyWrapperBackingInitializer;
256+
}
252257

253258
/// True if the SILDeclRef references the ivar initializer or deinitializer of
254259
/// a class.

trunk/lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ namespace {
725725

726726
if (auto *var = dyn_cast<VarDecl>(VD)) {
727727
PrintWithColorRAII(OS, TypeColor) << " type='";
728-
if (var->hasType())
728+
if (auto varTy = var->hasInterfaceType())
729729
var->getType().print(PrintWithColorRAII(OS, TypeColor).getOS());
730730
else
731731
PrintWithColorRAII(OS, TypeColor) << "<null type>";
@@ -954,13 +954,11 @@ namespace {
954954
PrintWithColorRAII(OS, IdentifierColor)
955955
<< " apiName=" << P->getArgumentName();
956956

957-
if (P->hasType()) {
957+
if (P->hasInterfaceType()) {
958958
PrintWithColorRAII(OS, TypeColor) << " type='";
959959
P->getType().print(PrintWithColorRAII(OS, TypeColor).getOS());
960960
PrintWithColorRAII(OS, TypeColor) << "'";
961-
}
962961

963-
if (P->hasInterfaceType()) {
964962
PrintWithColorRAII(OS, InterfaceTypeColor) << " interface type='";
965963
P->getInterfaceType().print(
966964
PrintWithColorRAII(OS, InterfaceTypeColor).getOS());

trunk/lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25242524
if (decl->hasInterfaceType()) {
25252525
Printer << ": ";
25262526
TypeLoc tyLoc;
2527-
if (auto *repr = decl->getTypeRepr())
2527+
if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr())
25282528
tyLoc = TypeLoc(repr, decl->getInterfaceType());
25292529
else
25302530
tyLoc = TypeLoc::withoutLoc(decl->getInterfaceType());

0 commit comments

Comments
 (0)