Skip to content

Commit fd03db4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into init-kind-request
2 parents 9d00f42 + 1a72eec commit fd03db4

Some content is hidden

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

61 files changed

+943
-397
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ option(SWIFT_BUILD_STATIC_SDK_OVERLAY
6161
"Build static variants of the Swift SDK overlay"
6262
FALSE)
6363

64+
option(SWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT
65+
"If not building stdlib, controls whether to build 'stdlib/toolchain' content"
66+
TRUE)
67+
6468
# In many cases, the CMake build system needs to determine whether to include
6569
# a directory, or perform other actions, based on whether the stdlib or SDK is
6670
# being built at all -- statically or dynamically. Please note that these
@@ -1078,7 +1082,9 @@ endif()
10781082
if(SWIFT_BUILD_STDLIB)
10791083
add_subdirectory(stdlib)
10801084
else()
1081-
add_subdirectory(stdlib/toolchain)
1085+
if(SWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT)
1086+
add_subdirectory(stdlib/toolchain)
1087+
endif()
10821088

10831089
# Some tools (e.g. swift-reflection-dump) rely on a host swiftReflection, so
10841090
# ensure we build that when building tools.

docs/SwiftFormat.md

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

docs/SwiftIndent.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
# Swift-indent
3+
4+
## Introduction
5+
6+
Note: This tool is still a work in progress.
7+
8+
swift-indent is a tool for automatically indenting your Swift files according to a
9+
set of rules. It is implemented as another driver kind, like swiftc, the batch
10+
compiler, so swift-indent is actually a symbolic link to swift. This tool uses
11+
libIDE to indent code, so it can be leveraged from multiple systems and editors.
12+
13+
## Usage
14+
15+
To print all the available options:
16+
17+
swift-indent -help
18+
19+
By default, swift-indent will output the indented file to the standard output:
20+
21+
swift-indent sample.swift
22+
23+
You can either output the result to a separate file:
24+
25+
swift-indent sample.swift -o result.swift
26+
27+
Or you can indent in-place (the original file will be overwritten):
28+
29+
swift-indent -in-place sample.swift
30+
31+
If you want to indent using tabs instead of spaces, use the `-use-tabs` option:
32+
33+
swift-indent -use-tabs sample.swift
34+
35+
You can set the number of tabs or spaces using the `-tab-width` and
36+
`-indent-width` options, respectively.
37+
38+
If you want to indent cases in switch statements, use the "-indent-switch-case"
39+
option. The result would be something like this:
40+
41+
switch aSwitch {
42+
case .some(let s):
43+
print(s)
44+
45+
swift-indent supports indenting a range of lines from a file:
46+
47+
swift-indent -line-range 2:45 sample.swift
48+
49+
This will indent the file from lines 2 to 45, inclusive.
50+
51+
You can indent several files, but the `-line-range` option is not supported in
52+
that case.
53+
54+
You can also provide several line ranges by using multiple `-line-range` options:
55+
56+
swift-indent -line-range 2:45 -line-range 100:120 sample.swift

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ SWIFT_TYPEID(Type)
2323
SWIFT_TYPEID(PropertyWrapperBackingPropertyInfo)
2424
SWIFT_TYPEID(PropertyWrapperTypeInfo)
2525
SWIFT_TYPEID(CtorInitializerKind)
26+
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>, PropertyWrapperMutability)
2627
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
2728
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class NominalTypeDecl;
2525
struct PropertyWrapperBackingPropertyInfo;
2626
struct PropertyWrapperTypeInfo;
2727
enum class CtorInitializerKind;
28+
struct PropertyWrapperMutability;
2829
class Type;
2930
class VarDecl;
3031
class TypeAliasDecl;

include/swift/AST/Decl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace swift {
7979
struct PrintOptions;
8080
struct PropertyWrapperBackingPropertyInfo;
8181
struct PropertyWrapperTypeInfo;
82+
struct PropertyWrapperMutability;
8283
class ProtocolDecl;
8384
class ProtocolType;
8485
struct RawComment;
@@ -5062,6 +5063,11 @@ class VarDecl : public AbstractStorageDecl {
50625063
PropertyWrapperBackingPropertyInfo
50635064
getPropertyWrapperBackingPropertyInfo() const;
50645065

5066+
/// Retrieve information about the mutability of the composed
5067+
/// property wrappers.
5068+
Optional<PropertyWrapperMutability>
5069+
getPropertyWrapperMutability() const;
5070+
50655071
/// Retrieve the backing storage property for a property that has an
50665072
/// attached property wrapper.
50675073
///

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4481,8 +4481,9 @@ ERROR(property_wrapper_attribute_not_on_property, none,
44814481
NOTE(property_wrapper_declared_here,none,
44824482
"property wrapper type %0 declared here", (DeclName))
44834483

4484-
ERROR(property_wrapper_composition_not_implemented, none,
4485-
"multiple property wrappers are not supported", ())
4484+
ERROR(property_wrapper_mutating_get_composed_to_get_only,none,
4485+
"property wrapper %0 with a mutating getter cannot be composed inside "
4486+
"get-only property wrapper %1", (Type, Type))
44864487

44874488
ERROR(property_wrapper_local,none,
44884489
"property wrappers are not yet supported on local properties", ())

include/swift/AST/PropertyWrappers.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,47 @@ struct PropertyWrapperTypeInfo {
7777
}
7878
};
7979

80+
/// Describes the mutability of the operations on a property wrapper or composition.
81+
struct PropertyWrapperMutability {
82+
enum Value: uint8_t {
83+
Nonmutating = 0,
84+
Mutating = 1,
85+
DoesntExist = 2,
86+
};
87+
88+
Value Getter, Setter;
89+
90+
/// Get the mutability of a composed access chained after accessing a wrapper with `this`
91+
/// getter and setter mutability.
92+
Value composeWith(Value x) {
93+
switch (x) {
94+
case DoesntExist:
95+
return DoesntExist;
96+
97+
// If an operation is nonmutating, then its input relies only on the
98+
// mutating-ness of the outer wrapper's get operation.
99+
case Nonmutating:
100+
return Getter;
101+
102+
// If it's mutating, then it relies
103+
// on a) the outer wrapper having a setter to exist at all, and b) the
104+
// mutating-ness of either the getter or setter, since we need both to
105+
// perform a writeback cycle.
106+
case Mutating:
107+
if (Setter == DoesntExist) {
108+
return DoesntExist;
109+
}
110+
return std::max(Getter, Setter);
111+
}
112+
}
113+
114+
bool operator==(PropertyWrapperMutability other) const {
115+
return Getter == other.Getter && Setter == other.Setter;
116+
}
117+
};
118+
119+
void simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m);
120+
80121
/// Describes the backing property of a property that has an attached wrapper.
81122
struct PropertyWrapperBackingPropertyInfo {
82123
/// The backing property.

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace swift {
3232
class AbstractStorageDecl;
3333
class GenericParamList;
3434
struct PropertyWrapperBackingPropertyInfo;
35+
struct PropertyWrapperMutability;
3536
class RequirementRepr;
3637
class SpecializeAttr;
3738
class TypeAliasDecl;
@@ -601,6 +602,26 @@ class PropertyWrapperBackingPropertyTypeRequest :
601602
bool isCached() const;
602603
};
603604

605+
/// Request information about the mutability of composed property wrappers.
606+
class PropertyWrapperMutabilityRequest :
607+
public SimpleRequest<PropertyWrapperMutabilityRequest,
608+
Optional<PropertyWrapperMutability> (VarDecl *),
609+
CacheKind::Cached> {
610+
public:
611+
using SimpleRequest::SimpleRequest;
612+
613+
private:
614+
friend SimpleRequest;
615+
616+
// Evaluation.
617+
llvm::Expected<Optional<PropertyWrapperMutability>>
618+
evaluate(Evaluator &evaluator, VarDecl *var) const;
619+
620+
public:
621+
// Caching
622+
bool isCached() const;
623+
};
624+
604625
/// Request information about the backing property for properties that have
605626
/// attached property wrappers.
606627
class PropertyWrapperBackingPropertyInfoRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SWIFT_TYPEID(StructuralTypeRequest)
3333
SWIFT_TYPEID(DefaultTypeRequest)
3434
SWIFT_TYPEID(MangleLocalTypeDeclRequest)
3535
SWIFT_TYPEID(PropertyWrapperTypeInfoRequest)
36+
SWIFT_TYPEID(PropertyWrapperMutabilityRequest)
3637
SWIFT_TYPEID(AttachedPropertyWrappersRequest)
3738
SWIFT_TYPEID(AttachedPropertyWrapperTypeRequest)
3839
SWIFT_TYPEID(PropertyWrapperBackingPropertyTypeRequest)
@@ -47,4 +48,4 @@ SWIFT_TYPEID(LazyStoragePropertyRequest)
4748
SWIFT_TYPEID(TypeCheckFunctionBodyUntilRequest)
4849
SWIFT_TYPEID(StoredPropertiesRequest)
4950
SWIFT_TYPEID(StoredPropertiesAndMissingMembersRequest)
50-
SWIFT_TYPEID(StorageImplInfoRequest)
51+
SWIFT_TYPEID(StorageImplInfoRequest)

include/swift/Basic/AnyValue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ namespace llvm {
165165
bool operator!=(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
166166
return !(lhs == rhs);
167167
}
168+
169+
template<typename T>
170+
void simple_display(raw_ostream &out, const Optional<T> &opt) {
171+
if (opt) {
172+
simple_display(out, *opt);
173+
}
174+
out << "None";
175+
}
168176
} // end namespace llvm
169177

170178
#endif //

include/swift/Driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Driver {
158158
Interactive, // swift
159159
Batch, // swiftc
160160
AutolinkExtract, // swift-autolink-extract
161-
SwiftFormat // swift-format
161+
SwiftIndent // swift-indent
162162
};
163163

164164
class InputInfoMap;

include/swift/IDE/Formatting.h renamed to include/swift/IDE/Indenting.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Formatting.h -------------------------------------------*- C++ -*-===//
1+
//===--- Indenting.h --------------------------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_FORMATTING_H
14-
#define SWIFT_FORMATTING_H
13+
#ifndef SWIFT_INDENTING_H
14+
#define SWIFT_INDENTING_H
1515

1616
namespace swift {
1717
namespace ide {
@@ -101,4 +101,4 @@ std::pair<LineRange, std::string> reformat(LineRange Range,
101101
} // namespace ide
102102
} // namespace swift
103103

104-
#endif // LLVM_SWIFT_FORMATTING_H
104+
#endif // SWIFT_INDENTING_H

include/swift/Option/Options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace options {
3333
DoesNotAffectIncrementalBuild = (1 << 8),
3434
AutolinkExtractOption = (1 << 9),
3535
ModuleWrapOption = (1 << 10),
36-
SwiftFormatOption = (1 << 11),
36+
SwiftIndentOption = (1 << 11),
3737
ArgumentIsPath = (1 << 12),
3838
ModuleInterfaceOption = (1 << 13),
3939
};

0 commit comments

Comments
 (0)