Skip to content

Commit b510e88

Browse files
committed
---
yaml --- r: 348732 b: refs/heads/master c: dfe0085 h: refs/heads/master
1 parent eeb1a61 commit b510e88

Some content is hidden

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

44 files changed

+876
-1175
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: 2b790a96377c496e31ffa51b914d2df6d1fe7584
2+
refs/heads/master: dfe0085aeabf454273d783d36c83b4ddc587805e
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/docs/CToSwiftNameTranslation.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ __attribute__((swift_name("SpacecraftCoordinates")))
252252
struct SPKSpacecraftCoordinates {
253253
double x, y, z, t; // space and time, of course
254254
};
255+
256+
// Usually seen as NS_SWIFT_NAME.
255257
```
256258
257259
```swift
@@ -287,12 +289,10 @@ The `swift_name` attribute can be used to give a C function a custom name. The v
287289
```objc
288290
__attribute__((swift_name("doSomething(to:bar:)")))
289291
void doSomethingToFoo(Foo *foo, int bar);
290-
291-
// Usually seen as NS_SWIFT_NAME.
292292
```
293293
294294
```swift
295-
func doSomething(foo: UnsafeMutablePointer<Foo>, bar: Int32)
295+
func doSomething(to foo: UnsafeMutablePointer<Foo>, bar: Int32)
296296
```
297297

298298
An underscore can be used in place of an empty parameter label, as in Swift.
@@ -430,4 +430,86 @@ Although enumerators always have global scope in C, they are often imported as m
430430

431431
_Currently, `swift_name` does not even allow importing an enum case as a member of the enum type itself, even if the enum is not recognized as an `@objc` enum, error code enum, or option set (i.e. the situation where a case is imported as a global constant)._
432432

433+
434+
### Fields of structs and unions; Objective-C properties
435+
436+
The `swift_name` attribute can be applied to rename a struct or union field or an Objective-C property (whether on a class or a protocol). The value of the attribute must be a valid Swift identifier.
437+
438+
```objc
439+
struct SPKSpaceflightBooking {
440+
const SPKLocation * _Nullable destination;
441+
bool roundTrip __attribute__((swift_name("isRoundTrip")));
442+
};
443+
```
444+
445+
```swift
446+
struct SPKSpaceflightBooking {
447+
var destination: UnsafePointer<SPKLocation>?
448+
var isRoundTrip: Bool
449+
}
450+
```
451+
452+
453+
### Objective-C methods
454+
455+
The `swift_name` attribute can be used to give an Objective-C method a custom name. The value of the attribute must be a full Swift function name, including parameter labels.
456+
457+
```objc
458+
- (void)doSomethingToFoo:(Foo *)foo bar:(int)bar
459+
__attribute__((swift_name("doSomethingImportant(to:bar:)")));
460+
```
461+
462+
```swift
463+
func doSomethingImportant(to foo: UnsafeMutablePointer<Foo>, bar: Int32)
464+
```
465+
466+
As with functions, an underscore can be used to represent an empty parameter label.
467+
468+
Methods that follow the NSError out-parameter convention may provide one fewer parameter label than the number of parameters in the original method to indicate that a parameter should be dropped, but they do not have to. The `swift_error` attribute is still respected even when using a custom name for purposes of transforming an NSError out-parameter and the method return type.
469+
470+
```objc
471+
- (BOOL)doSomethingRiskyAndReturnError:(NSError **)error
472+
__attribute__((swift_name("doSomethingRisky()")));
473+
- (BOOL)doSomethingContrived:(NSString *)action error:(NSError **)outError
474+
__attribute__((swift_name("doSomethingContrived(_:error:)")));
475+
```
476+
477+
```swift
478+
func doSomethingRisky() throws
479+
func doSomethingContrived(_ action: String, error: ()) throws
480+
```
481+
482+
A base name of "init" can be used on a *class* method that returns `instancetype` or the containing static type in order to import that method as an initializer. Any other custom name *prevents* a class method from being imported as an initializer even if it would normally be inferred as one.
483+
484+
```objc
485+
+ (Action *)makeActionWithHandler:(void(^)(void))handler
486+
__attribute__((swift_name("init(handler:)")));
487+
+ (instancetype)makeActionWithName:(NSString *)name
488+
__attribute__((swift_name("init(name:)")));
489+
```
490+
491+
```swift
492+
/* non-inherited */ init(handler: () -> Void)
493+
init(name: String)
494+
```
495+
496+
A no-argument method imported as an initializer can be given a dummy argument label to disambiguate it from the no-argument `init()`, whether the method is an init-family instance method or a factory class method in Objective-C.
497+
498+
```objc
499+
- (instancetype)initSafely
500+
__attribute__((swift_name("init(safe:)")));
501+
+ (instancetype)makeDefaultAction
502+
__attribute__((swift_name("init(default:)")));
503+
```
504+
505+
```swift
506+
init(safe: ())
507+
init(default: ())
508+
```
509+
510+
A custom name on an instance method with one of Objective-C's subscript selectors (`objectAtIndexedSubscript:`, `objectForKeyedSubscript:`, `setObject:atIndexedSubscript:`, or `setObject:forKeyedSubscript:`) prevents that method from being imported as a subscript or used as the accessor for another subscript.
511+
512+
_Currently, this only works if *both* methods in a read/write subscript are given custom names; if just one is, a read/write subscript will still be formed. A read-only subscript only has one method to rename._
513+
514+
433515
## More to come...

trunk/include/swift/Parse/ASTGen.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class ASTGen {
3737

3838
// FIXME: remove when Syntax can represent all types and ASTGen can handle
3939
// them
40-
/// Decl attributes that cannot be represented by Syntax or generated by
41-
/// ASTGen.
40+
/// Types that cannot be represented by Syntax or generated by ASTGen.
41+
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
42+
4243
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
4344

4445
public:
@@ -102,8 +103,7 @@ class ASTGen {
102103
//===--------------------------------------------------------------------===//
103104
// Types.
104105

105-
TypeRepr *generate(const syntax::TypeSyntax &Type, const SourceLoc Loc,
106-
bool IsSILFuncDecl = false);
106+
TypeRepr *generate(const syntax::TypeSyntax &Type, const SourceLoc Loc);
107107
TypeRepr *generate(const syntax::SomeTypeSyntax &Type, const SourceLoc Loc);
108108
TypeRepr *generate(const syntax::CompositionTypeSyntax &Type,
109109
const SourceLoc Loc);
@@ -127,19 +127,11 @@ class ASTGen {
127127
const SourceLoc Loc);
128128
TypeRepr *generate(const syntax::ClassRestrictionTypeSyntax &Type,
129129
const SourceLoc Loc);
130-
TypeRepr *generate(const syntax::SILBoxTypeSyntax &Type, const SourceLoc Loc,
131-
bool IsSILFuncDecl);
132-
TypeRepr *generate(const syntax::SILFunctionTypeSyntax &Type,
133-
const SourceLoc Loc, bool IsSILFuncDecl);
134130
TypeRepr *generate(const syntax::CodeCompletionTypeSyntax &Type,
135131
const SourceLoc Loc);
136132
TypeRepr *generate(const syntax::UnknownTypeSyntax &Type,
137133
const SourceLoc Loc);
138134

139-
TypeAttributes
140-
generateTypeAttributes(const syntax::AttributeListSyntax &syntax,
141-
const SourceLoc Loc);
142-
143135
private:
144136
TupleTypeRepr *
145137
generateTuple(const syntax::TokenSyntax &LParen,
@@ -204,6 +196,10 @@ class ASTGen {
204196
TypeRepr *lookupType(syntax::TypeSyntax Type);
205197

206198
public:
199+
void addType(TypeRepr *Type, const SourceLoc Loc);
200+
bool hasType(const SourceLoc Loc) const;
201+
TypeRepr *getType(const SourceLoc Loc) const;
202+
207203
void addDeclAttributes(DeclAttributes attrs, const SourceLoc Loc);
208204
bool hasDeclAttributes(SourceLoc Loc) const;
209205
DeclAttributes getDeclAttributes(const SourceLoc Loc) const;

trunk/include/swift/Parse/ParsedRawSyntaxNode.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,8 @@ class ParsedRawSyntaxNode {
119119
assert(getTokenKind() == tokKind && "Token kind with too large value!");
120120
}
121121

122-
#ifndef NDEBUG
123-
bool ensureDataIsNotRecorded() {
124-
if (DK != DataKind::Recorded)
125-
return true;
126-
llvm::dbgs() << "Leaking node: ";
127-
dump(llvm::dbgs());
128-
llvm::dbgs() << "\n";
129-
return false;
130-
}
131-
#endif
132-
133122
ParsedRawSyntaxNode &operator=(ParsedRawSyntaxNode &&other) {
134-
assert(ensureDataIsNotRecorded() &&
135-
"recorded data is being destroyed by assignment");
123+
assert(DK != DataKind::Recorded);
136124
switch (other.DK) {
137125
case DataKind::Null:
138126
break;
@@ -157,7 +145,7 @@ class ParsedRawSyntaxNode {
157145
*this = std::move(other);
158146
}
159147
~ParsedRawSyntaxNode() {
160-
assert(ensureDataIsNotRecorded() && "recorded data is being destructed");
148+
assert(DK != DataKind::Recorded);
161149
}
162150

163151
syntax::SyntaxKind getKind() const { return syntax::SyntaxKind(SynKind); }

trunk/include/swift/Parse/Parser.h

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,13 +1082,24 @@ class Parser {
10821082
/// an error parsing.
10831083
bool parseVersionTuple(llvm::VersionTuple &Version, SourceRange &Range,
10841084
const Diagnostic &D);
1085+
10851086
bool parseTypeAttributeList(ParamDecl::Specifier &Specifier,
10861087
SourceLoc &SpecifierLoc,
1087-
TypeAttributes &Attributes);
1088-
ParserStatus parseTypeAttributeListSyntax(Optional<ParsedTokenSyntax> &specifier,
1089-
Optional<ParsedAttributeListSyntax> &attrs);
1090-
ParsedSyntaxResult<ParsedAttributeSyntax> parseTypeAttributeSyntax();
1091-
1088+
TypeAttributes &Attributes) {
1089+
if (Tok.isAny(tok::at_sign, tok::kw_inout) ||
1090+
(Tok.is(tok::identifier) &&
1091+
(Tok.getRawText().equals("__shared") ||
1092+
Tok.getRawText().equals("__owned"))))
1093+
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
1094+
return false;
1095+
}
1096+
bool parseTypeAttributeListPresent(ParamDecl::Specifier &Specifier,
1097+
SourceLoc &SpecifierLoc,
1098+
TypeAttributes &Attributes);
1099+
bool parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc,
1100+
bool justChecking = false);
1101+
1102+
10921103
ParserResult<ImportDecl> parseDeclImport(ParseDeclOptions Flags,
10931104
DeclAttributes &Attributes);
10941105
ParserStatus parseInheritance(MutableArrayRef<TypeLoc> &Inherited,
@@ -1179,47 +1190,44 @@ class Parser {
11791190
//===--------------------------------------------------------------------===//
11801191
// Type Parsing
11811192

1182-
ParserResult<TypeRepr> parseType();
1183-
ParserResult<TypeRepr> parseType(Diag<> MessageID,
1184-
bool HandleCodeCompletion = true,
1185-
bool IsSILFuncDecl = false);
1186-
ParserStatus parseGenericArguments(llvm::SmallVectorImpl<TypeRepr *> &ArgsAST,
1187-
SourceLoc &LAngleLoc,
1188-
SourceLoc &RAngleLoc);
1189-
TypeRepr *applyAttributeToType(TypeRepr *Ty, const TypeAttributes &Attr,
1190-
ParamDecl::Specifier Specifier,
1191-
SourceLoc SpecifierLoc);
1192-
ParserResult<TypeRepr> parseAnyTypeAST();
1193+
using TypeASTResult = ParserResult<TypeRepr>;
1194+
using TypeResult = ParsedSyntaxResult<ParsedTypeSyntax>;
11931195

11941196
ParsedSyntaxResult<ParsedLayoutConstraintSyntax>
11951197
parseLayoutConstraintSyntax();
11961198

1197-
ParsedSyntaxResult<ParsedTypeSyntax> parseTypeSyntax();
1198-
ParsedSyntaxResult<ParsedTypeSyntax>
1199-
parseTypeSyntax(Diag<> MessageID, bool HandleCodeCompletion = true,
1200-
bool IsSILFuncDecl = false);
1199+
TypeResult parseTypeSyntax();
1200+
TypeResult parseTypeSyntax(Diag<> MessageID, bool HandleCodeCompletion = true,
1201+
bool IsSILFuncDecl = false);
1202+
1203+
TypeASTResult parseType();
1204+
TypeASTResult parseType(Diag<> MessageID, bool HandleCodeCompletion = true,
1205+
bool IsSILFuncDecl = false);
1206+
ParserStatus
1207+
parseGenericArgumentsAST(llvm::SmallVectorImpl<TypeRepr *> &ArgsAST,
1208+
SourceLoc &LAngleLoc, SourceLoc &RAngleLoc);
1209+
TypeASTResult parseSILBoxType(GenericParamList *generics,
1210+
const TypeAttributes &attrs,
1211+
Optional<Scope> &GenericsScope);
1212+
TypeASTResult parseTypeSimpleOrCompositionAST(Diag<> MessageID,
1213+
bool HandleCodeCompletion);
1214+
TypeASTResult parseAnyTypeAST();
12011215

12021216
ParsedSyntaxResult<ParsedGenericArgumentClauseSyntax>
12031217
parseGenericArgumentClauseSyntax();
12041218

1205-
ParsedSyntaxResult<ParsedTypeSyntax>
1206-
parseTypeSimple(Diag<> MessageID, bool HandleCodeCompletion);
1207-
ParsedSyntaxResult<ParsedTypeSyntax>
1208-
parseTypeSimpleOrComposition(Diag<> MessageID, bool HandleCodeCompletion);
1209-
ParsedSyntaxResult<ParsedTypeSyntax> parseTypeIdentifier();
1210-
ParsedSyntaxResult<ParsedTypeSyntax> parseAnyType();
1211-
ParsedSyntaxResult<ParsedTypeSyntax> parseTypeTupleBody();
1212-
ParsedSyntaxResult<ParsedTypeSyntax> parseTypeCollection();
1213-
ParsedSyntaxResult<ParsedTypeSyntax> parseMetatypeType(ParsedTypeSyntax Base);
1214-
ParsedSyntaxResult<ParsedTypeSyntax> parseOptionalType(ParsedTypeSyntax Base);
1215-
ParsedSyntaxResult<ParsedTypeSyntax>
1216-
parseImplicitlyUnwrappedOptionalType(ParsedTypeSyntax Base);
1217-
ParsedSyntaxResult<ParsedTypeSyntax> parseSILBoxTypeSyntax(
1218-
Optional<ParsedGenericParameterClauseListSyntax> genericParams);
1219-
1220-
ParsedSyntaxResult<ParsedTypeSyntax> parseTypeArray(ParsedTypeSyntax Base,
1221-
SourceLoc BaseLoc);
1222-
ParsedSyntaxResult<ParsedTypeSyntax> parseOldStyleProtocolComposition();
1219+
TypeResult parseTypeSimple(Diag<> MessageID, bool HandleCodeCompletion);
1220+
TypeResult parseTypeSimpleOrComposition(Diag<> MessageID, bool HandleCodeCompletion);
1221+
TypeResult parseTypeIdentifier();
1222+
TypeResult parseAnyType();
1223+
TypeResult parseTypeTupleBody();
1224+
TypeResult parseTypeCollection();
1225+
TypeResult parseMetatypeType(ParsedTypeSyntax Base);
1226+
TypeResult parseOptionalType(ParsedTypeSyntax Base);
1227+
TypeResult parseImplicitlyUnwrappedOptionalType(ParsedTypeSyntax Base);
1228+
1229+
TypeResult parseTypeArray(ParsedTypeSyntax Base, SourceLoc BaseLoc);
1230+
TypeResult parseOldStyleProtocolComposition();
12231231

12241232
bool isOptionalToken(const Token &T) const;
12251233
ParsedTokenSyntax consumeOptionalTokenSyntax();
@@ -1229,10 +1237,9 @@ class Parser {
12291237
ParsedTokenSyntax consumeImplicitlyUnwrappedOptionalTokenSyntax();
12301238
SourceLoc consumeImplicitlyUnwrappedOptionalToken();
12311239

1232-
ParsedSyntaxResult<ParsedTypeSyntax>
1233-
applyAttributeToTypeSyntax(ParsedSyntaxResult<ParsedTypeSyntax> &&ty,
1234-
Optional<ParsedTokenSyntax> specifier,
1235-
Optional<ParsedAttributeListSyntax> attrs);
1240+
TypeRepr *applyAttributeToType(TypeRepr *Ty, const TypeAttributes &Attr,
1241+
ParamDecl::Specifier Specifier,
1242+
SourceLoc SpecifierLoc);
12361243

12371244
//===--------------------------------------------------------------------===//
12381245
// Pattern Parsing

trunk/lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,6 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn) {
14911491
Optional<ASTMangler::SpecialContext>
14921492
ASTMangler::getSpecialManglingContext(const ValueDecl *decl,
14931493
bool useObjCProtocolNames) {
1494-
#if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
1495-
return None; // not needed for the parser library.
1496-
#endif
1497-
14981494
// Declarations provided by a C module have a special context mangling.
14991495
// known-context ::= 'So'
15001496
//

trunk/lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6999,8 +6999,11 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
69996999
}
70007000

70017001
Type FuncDecl::getResultInterfaceType() const {
7002+
if (!hasInterfaceType())
7003+
return nullptr;
7004+
70027005
Type resultTy = getInterfaceType();
7003-
if (resultTy.isNull() || resultTy->is<ErrorType>())
7006+
if (resultTy->is<ErrorType>())
70047007
return resultTy;
70057008

70067009
if (hasImplicitSelfDecl())

trunk/lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,9 @@ void IRGenSILFunction::emitSILFunction() {
16391639

16401640
assert(!CurSILFn->empty() && "function has no basic blocks?!");
16411641

1642+
if (CurSILFn->isThunk())
1643+
IGM.setHasFramePointer(CurFn, false);
1644+
16421645
if (CurSILFn->getDynamicallyReplacedFunction())
16431646
IGM.IRGen.addDynamicReplacement(CurSILFn);
16441647

0 commit comments

Comments
 (0)