Skip to content

Commit f227bff

Browse files
committed
---
yaml --- r: 327637 b: refs/heads/tensorflow c: cd2a9dd h: refs/heads/master i: 327635: fdc4a1e
1 parent ac293ac commit f227bff

File tree

19 files changed

+96
-309
lines changed

19 files changed

+96
-309
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: 1f0e2da9a09648b6065e099a75ae4b7d6a010707
819+
refs/heads/tensorflow: cd2a9dd2e9fe224033113dbbd4de380df8d9b89b
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/docs/CToSwiftNameTranslation.md

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
This document gives a high-level description of how C and Objective-C declarations are translated to Swift, with particular focus on how names are adjusted. It is not attempting to be a *complete* description of everything the compiler does except with regards to how *names* are transformed; even there, some special cases that only apply to Apple's SDKs have been omitted.
44

5-
## Word boundaries
6-
7-
Several forms of name translation are defined in terms of word boundaries. The word-splitting algorithm used by the Swift compiler is as follows: there is a boundary after
8-
9-
1. An underscore ("\_").
10-
2. A series of two or more uppercase ASCII characters and the suffix "s", "es", or "ies" (e.g. "URLs", "VAXes")...unless the last uppercase letter is "I" and the suffix is "s", in which case it's just as likely to be an acronym followed by "Is" (i.e. "URLIs" is treated as "URL Is").
11-
2. A series of two or more uppercase ASCII characters followed by an uppercase ASCII character and then a lowercase ASCII character ("XMLReader" becomes "XML Reader").
12-
3. A series of two or more uppercase ASCII characters followed by a non-ASCII-alphabetic character. ("UTF8" becomes "UTF 8")
13-
4. A series of two or more uppercase ASCII characters at the end of the string.
14-
5. An uppercase ASCII character and any number of non-ASCII-uppercase, non-underscore characters ("ContrivedExample" becomes "Contrived Example").
15-
6. Any number of non-ASCII-uppercase, non-underscore characters ("lowercase\_example" becomes "lowercase \_ example").
16-
17-
185
## Enums
196

207
1. Anonymous? Import elements as constants of the underlying type, *except* that Int is used for an inferred underlying type if all the cases fit in an Int32, since integer conversions are explicit in Swift.
@@ -127,7 +114,15 @@ In C, enumerators (enum cases) aren't namespaced under their enum type, so their
127114

128115
1. Collect all *available, non-deprecated* enum cases *without custom names.* If there are no such cases, collect all cases without custom names, whether available or not.
129116

130-
2. Find the common word-boundary prefix __CP__ of these cases.
117+
2. Find the common word-boundary prefix __CP__ of these cases. There is a word boundary after
118+
119+
1. An underscore ("\_").
120+
2. A series of two or more uppercase ASCII characters and the suffix "s", "es", or "ies" (e.g. "URLs", "VAXes")...unless the last uppercase letter is "I" and the suffix is "s", in which case it's just as likely to be an acronym followed by "Is" (i.e. "URLIs" is treated as "URL Is").
121+
2. A series of two or more uppercase ASCII characters followed by an uppercase ASCII character and then a lowercase ASCII character ("XMLReader" becomes "XML Reader").
122+
3. A series of two or more uppercase ASCII characters followed by a non-ASCII-alphabetic character. ("UTF8" becomes "UTF 8")
123+
4. A series of two or more uppercase ASCII characters at the end of the string.
124+
5. An uppercase ASCII character and any number of non-ASCII-uppercase, non-underscore characters ("ContrivedExample" becomes "Contrived Example").
125+
6. Any number of non-ASCII-uppercase, non-underscore characters ("lowercase\_example" becomes "lowercase \_ example").
131126

132127
3. If __CP__ starts with "k" followed by an uppercase letter, or if it's *just* "k" and none of the cases have a non-identifier-start character immediately after the 'k', treat that as meaning "constant" and ignore it for the next step.
133128

@@ -149,7 +144,7 @@ In C, enumerators (enum cases) aren't namespaced under their enum type, so their
149144

150145
9. ASCII-lowercase the first word of the remaining name if it starts with an uppercase ASCII character.
151146

152-
_There's a bug in this step where the special case for "Is" is missing, so "URLIs" will be lowercased to "urlis"._
147+
_There's a bug here where the special case for "Is" is missing, so "URLIs" will be lowercased to "urlis"._
153148

154149
## `swift_wrapper` typedefs
155150

@@ -195,48 +190,4 @@ extension SecretResourceID {
195190

196191
On Apple platforms, whenever Foundation is imported, constants with the type "NSNotificationName" additionally have the suffix "Notification" stripped before performing the above rules unless they have a custom name. Global NSString constants whose name ends in "Notification" will also automatically be treated as if they were declared with the type NSNotificationName unless they have a custom name.
197192

198-
199-
## Objective-C Protocols
200-
201-
Protocols in Objective-C are normally in a separate namespace from the "ordinary" identifier namespace used by typedefs and classes. Swift does not have separate namespaces, so if the protocol has the same name as another declaration in the same module, the suffix "Protocol" is appended. (Example: NSObjectProtocol in the ObjectiveC module.)
202-
203-
204-
## CF Types
205-
206-
"Core Foundation" is a C-based object-oriented system with strong conventions built around pointers to opaque structs. Creating new Core Foundation types is not generally supported, but Swift will recognize those in Apple's SDKs. If a struct has the `objc_bridge`, `objc_mutable_bridge`, or `objc_bridge_related` Clang attributes, it will be treated as a CF type and a typedef of a pointer to that struct will be imported as a class in Swift. The suffix "Ref" will be dropped from the class's name if present unless doing so would conflict with another declaration in the same module as the typedef.
207-
208-
If the class name contains the word "Mutable" exactly once per the usual word-boundary rules, a corresponding class name without the word "Mutable" will be used as the superclass if present. Otherwise, the CF type is taken to be a root object.
209-
210-
Additionally, typedefs for `void *` or `const void *` that are themselves annotated with `objc_bridge` will be treated as CFTypeRef-like and imported as `Any` rather than `Unsafe[Mutable]RawPointer`.
211-
212-
If a typedef's underlying type is itself a "CF pointer" typedef, the "alias" typedef will be imported as a regular typealias, with the suffix "Ref" still dropped from its name (if present) unless doing so would conflict with another declaration in the same module as the typedef.
213-
214-
215-
## `swift_private`
216-
217-
The `swift_private` Clang attribute prepends `__` onto the base name of any declaration being imported except initializers. For initializers with no arguments, a dummy `Void` argument with the name `__` is inserted; otherwise, the label for the first argument has `__` prepended. This transformation takes place after any other name manipulation, unless the declaration has a custom name. It will not occur if the declaration is an override; in that case the name needs to match the overridden declaration.
218-
219-
```objc
220-
@interface Example : NSObject
221-
- (instancetype)initWithValue:(int)value __attribute__((swift_private));
222-
@property(readonly) int value __attribute__((swift_private));
223-
@end
224-
225-
// Usually seen as NS_REFINED_FOR_SWIFT
226-
```
227-
228-
```swift
229-
class Example: NSObject {
230-
init(__value: Int32)
231-
var __value: Int32 { get }
232-
}
233-
```
234-
235-
The purpose of this annotation is to allow a more idiomatic implementation to be provided in Swift. The effect of `swift_private` is inherited from an enum onto its elements if the enum is not imported as an error code enum, an `@objc` enum, or an option set.
236-
237-
_The original intent of the `swift_private` attribute was additionally to limit access to a Swift module with the same name as the owning Clang module, e.g. the Swift half of a mixed-source framework. However, this restriction has not been implemented as of Swift 5.1._
238-
239-
_For "historical reasons", the `swift_private` attribute is ignored on factory methods with no arguments imported as initializers. This is essentially matching the behavior of older Swift compilers for source compatibility in case someone has marked such a factory method as `swift_private`._
240-
241-
242193
## More to come...

branches/tensorflow/include/swift/AST/Attr.def

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,11 @@ DECL_ATTR(available, Available,
121121
1)
122122
CONTEXTUAL_SIMPLE_DECL_ATTR(final, Final,
123123
OnClass | OnFunc | OnAccessor | OnVar | OnSubscript |
124-
DeclModifier | ABIBreakingToAdd | ABIBreakingToRemove |
125-
APIBreakingToAdd,
124+
DeclModifier,
126125
2)
127126
DECL_ATTR(objc, ObjC,
128127
OnAbstractFunction | OnClass | OnProtocol | OnExtension | OnVar |
129-
OnSubscript | OnEnum | OnEnumElement | ABIBreakingToAdd | ABIBreakingToRemove,
128+
OnSubscript | OnEnum | OnEnumElement,
130129
3)
131130
CONTEXTUAL_SIMPLE_DECL_ATTR(required, Required,
132131
OnConstructor |
@@ -188,7 +187,7 @@ DECL_ATTR(_semantics, Semantics,
188187
21)
189188
CONTEXTUAL_SIMPLE_DECL_ATTR(dynamic, Dynamic,
190189
OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor |
191-
DeclModifier | ABIBreakingToAdd | ABIBreakingToRemove,
190+
DeclModifier,
192191
22)
193192
CONTEXTUAL_SIMPLE_DECL_ATTR(infix, Infix,
194193
OnFunc | OnOperator |
@@ -213,7 +212,7 @@ SIMPLE_DECL_ATTR(nonobjc, NonObjC,
213212
30)
214213
SIMPLE_DECL_ATTR(_fixed_layout, FixedLayout,
215214
OnVar | OnClass | OnStruct |
216-
UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove,
215+
UserInaccessible,
217216
31)
218217
SIMPLE_DECL_ATTR(inlinable, Inlinable,
219218
OnVar | OnSubscript | OnAbstractFunction,
@@ -363,7 +362,7 @@ SIMPLE_DECL_ATTR(_weakLinked, WeakLinked,
363362
OnSubscript | OnConstructor | OnEnumElement | OnExtension | UserInaccessible,
364363
75)
365364
SIMPLE_DECL_ATTR(frozen, Frozen,
366-
OnEnum | OnStruct | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToRemove,
365+
OnEnum | OnStruct,
367366
76)
368367
DECL_ATTR_ALIAS(_frozen, Frozen)
369368
SIMPLE_DECL_ATTR(_forbidSerializingReference, ForbidSerializingReference,

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,6 @@ class DeclAttribute : public AttributeBase {
353353

354354
/// Whether client code cannot use the attribute.
355355
UserInaccessible = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 7),
356-
357-
/// Whether adding this attribute can break API
358-
APIBreakingToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 8),
359-
360-
/// Whether removing this attribute can break API
361-
APIBreakingToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 9),
362-
363-
/// Whether adding this attribute can break ABI
364-
ABIBreakingToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 10),
365-
366-
/// Whether removing this attribute can break ABI
367-
ABIBreakingToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 11),
368356
};
369357

370358
LLVM_READNONE
@@ -447,21 +435,6 @@ class DeclAttribute : public AttributeBase {
447435
return getOptions(DK) & UserInaccessible;
448436
}
449437

450-
static bool isAddingBreakingABI(DeclAttrKind DK) {
451-
return getOptions(DK) & ABIBreakingToAdd;
452-
}
453-
454-
static bool isAddingBreakingAPI(DeclAttrKind DK) {
455-
return getOptions(DK) & APIBreakingToAdd;
456-
}
457-
458-
static bool isRemovingBreakingABI(DeclAttrKind DK) {
459-
return getOptions(DK) & ABIBreakingToRemove;
460-
}
461-
static bool isRemovingBreakingAPI(DeclAttrKind DK) {
462-
return getOptions(DK) & APIBreakingToRemove;
463-
}
464-
465438
bool isDeclModifier() const {
466439
return isDeclModifier(getKind());
467440
}

branches/tensorflow/include/swift/SILOptimizer/Utils/StackNesting.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ class StackNesting {
155155
return bitNumberForAlloc(AllocInst);
156156
}
157157

158-
/// Insert deallocations at block boundaries.
159-
Changes insertDeallocsAtBlockBoundaries();
160-
161158
/// Modifies the SIL to end up with a correct stack nesting.
162159
///
163160
/// Returns the status of what changes were made.
164-
bool adaptDeallocs();
161+
Changes adaptDeallocs();
165162
};
166163

167164
} // end namespace swift

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

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void StackNesting::setup(SILFunction *F) {
2424

2525
// We use pointers to BlockInfo structs. Therefore it's important that the
2626
// BlockInfos vector is never re-allocated.
27-
BlockInfos.clear();
2827
BlockInfos.reserve(F->size());
2928

3029
// Start with the function entry block and add blocks while walking down along
@@ -232,26 +231,36 @@ bool StackNesting::insertDeallocs(const BitVector &AliveBefore,
232231
return changesMade;
233232
}
234233

235-
// Insert deallocations at block boundaries.
236-
// This can be necessary for unreachable blocks. Example:
237-
//
238-
// %1 = alloc_stack
239-
// %2 = alloc_stack
240-
// cond_br %c, bb2, bb3
241-
// bb2: <--- need to insert a dealloc_stack %2 at the begin of bb2
242-
// dealloc_stack %1
243-
// unreachable
244-
// bb3:
245-
// dealloc_stack %2
246-
// dealloc_stack %1
247-
StackNesting::Changes StackNesting::insertDeallocsAtBlockBoundaries() {
248-
Changes changes = Changes::None;
234+
StackNesting::Changes StackNesting::adaptDeallocs() {
235+
236+
bool InstChanged = false;
237+
bool CFGChanged = false;
238+
BitVector Bits(StackLocs.size());
239+
240+
// Visit all blocks. Actually the order doesn't matter, but let's to it in
241+
// the same order as in solve().
249242
for (const BlockInfo &BI : reversed(BlockInfos)) {
250-
for (unsigned SuccIdx = 0, NumSuccs = BI.Successors.size();
251-
SuccIdx < NumSuccs; ++SuccIdx) {
243+
// Collect the alive-bits (at the block exit) from the successor blocks.
244+
Bits = BI.AliveStackLocsAtExit;
252245

246+
// Insert deallocations at block boundaries.
247+
// This can be necessary for unreachable blocks. Example:
248+
//
249+
// %1 = alloc_stack
250+
// %2 = alloc_stack
251+
// cond_br %c, bb2, bb3
252+
// bb2: <--- need to insert a dealloc_stack %2 at the begin of bb2
253+
// dealloc_stack %1
254+
// unreachable
255+
// bb3:
256+
// dealloc_stack %2
257+
// dealloc_stack %1
258+
//
259+
for (unsigned SuccIdx = 0, NumSuccs = BI.Successors.size();
260+
SuccIdx < NumSuccs; ++ SuccIdx) {
253261
BlockInfo *SuccBI = BI.Successors[SuccIdx];
254-
if (SuccBI->AliveStackLocsAtEntry == BI.AliveStackLocsAtExit)
262+
263+
if (SuccBI->AliveStackLocsAtEntry == Bits)
255264
continue;
256265

257266
// Insert deallocations for all locations which are alive at the end of
@@ -262,26 +271,11 @@ StackNesting::Changes StackNesting::insertDeallocsAtBlockBoundaries() {
262271
// block, we have to insert a new block where we can add the
263272
// deallocations.
264273
InsertionBlock = splitEdge(BI.Block->getTerminator(), SuccIdx);
265-
changes = Changes::CFG;
266-
}
267-
if (insertDeallocs(BI.AliveStackLocsAtExit, SuccBI->AliveStackLocsAtEntry,
268-
&InsertionBlock->front(), None)) {
269-
if (changes == Changes::None)
270-
changes = Changes::Instructions;
274+
CFGChanged = true;
271275
}
276+
InstChanged |= insertDeallocs(Bits, SuccBI->AliveStackLocsAtEntry,
277+
&InsertionBlock->front(), None);
272278
}
273-
}
274-
return changes;
275-
}
276-
277-
bool StackNesting::adaptDeallocs() {
278-
bool InstChanged = false;
279-
BitVector Bits(StackLocs.size());
280-
281-
// Visit all blocks. Actually the order doesn't matter, but let's to it in
282-
// the same order as in solve().
283-
for (const BlockInfo &BI : reversed(BlockInfos)) {
284-
Bits = BI.AliveStackLocsAtExit;
285279

286280
// Insert/remove deallocations inside blocks.
287281
for (SILInstruction *StackInst : reversed(BI.StackInsts)) {
@@ -316,29 +310,19 @@ bool StackNesting::adaptDeallocs() {
316310
}
317311
assert(Bits == BI.AliveStackLocsAtEntry && "dataflow didn't converge");
318312
}
319-
return InstChanged;
313+
if (CFGChanged)
314+
return Changes::CFG;
315+
if (InstChanged)
316+
return Changes::Instructions;
317+
return Changes::None;
320318
}
321319

322320
StackNesting::Changes StackNesting::correctStackNesting(SILFunction *F) {
323321
setup(F);
324-
if (!solve())
325-
return Changes::None;
326-
327-
// Insert deallocs at block boundaries. This might be necessary in CFG sub
328-
// graphs which don't reach a function exit, but only an unreachable.
329-
Changes changes = insertDeallocsAtBlockBoundaries();
330-
if (changes != Changes::None) {
331-
// Those inserted deallocs make it necessary to re-compute the analysis.
332-
setup(F);
333-
solve();
334-
}
335-
// Do the real work: extend lifetimes by moving deallocs.
336-
if (adaptDeallocs()) {
337-
if (changes == Changes::None)
338-
changes = Changes::Instructions;
322+
if (solve()) {
323+
return adaptDeallocs();
339324
}
340-
341-
return changes;
325+
return Changes::None;
342326
}
343327

344328
void StackNesting::dump() const {

branches/tensorflow/lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,11 +2478,11 @@ namespace {
24782478
}
24792479

24802480
Type visitDefaultArgumentExpr(DefaultArgumentExpr *expr) {
2481-
return expr->getType();
2481+
llvm_unreachable("Already type checked");
24822482
}
24832483

24842484
Type visitCallerDefaultArgumentExpr(CallerDefaultArgumentExpr *expr) {
2485-
return expr->getType();
2485+
llvm_unreachable("Already type checked");
24862486
}
24872487

24882488
Type visitApplyExpr(ApplyExpr *expr) {

branches/tensorflow/lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4713,8 +4713,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
47134713
// as representing "dynamic lookup" unless it's a direct call
47144714
// to such subscript (in that case label is expected to match).
47154715
if (auto *subscript = dyn_cast<SubscriptDecl>(cand)) {
4716-
if (memberLocator &&
4717-
::hasDynamicMemberLookupAttribute(instanceTy,
4716+
if (::hasDynamicMemberLookupAttribute(instanceTy,
47184717
DynamicMemberLookupCache) &&
47194718
isValidKeyPathDynamicMemberLookup(subscript, TC)) {
47204719
auto info = getArgumentInfo(memberLocator);

branches/tensorflow/lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,9 +2880,6 @@ ConstraintSystem::getArgumentInfoLocator(ConstraintLocator *locator) {
28802880

28812881
Optional<ConstraintSystem::ArgumentInfo>
28822882
ConstraintSystem::getArgumentInfo(ConstraintLocator *locator) {
2883-
if (!locator)
2884-
return None;
2885-
28862883
if (auto *infoLocator = getArgumentInfoLocator(locator)) {
28872884
auto known = ArgumentInfos.find(infoLocator);
28882885
if (known != ArgumentInfos.end())

branches/tensorflow/lib/Sema/TypeCheckCaptures.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,6 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
645645
}
646646
}
647647

648-
static bool isLazy(PatternBindingDecl *PBD) {
649-
if (auto var = PBD->getSingleVar())
650-
return var->getAttrs().hasAttribute<LazyAttr>();
651-
return false;
652-
}
653-
654648
void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
655649
auto &ctx = typeDecl->getASTContext();
656650

@@ -675,7 +669,7 @@ void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
675669
/*ObjC=*/false);
676670
init->walk(finder);
677671

678-
if (finder.getDynamicSelfCaptureLoc().isValid() && !isLazy(PBD)) {
672+
if (finder.getDynamicSelfCaptureLoc().isValid()) {
679673
ctx.Diags.diagnose(finder.getDynamicSelfCaptureLoc(),
680674
diag::dynamic_self_stored_property_init);
681675
}

0 commit comments

Comments
 (0)