Skip to content

Commit d6da747

Browse files
committed
---
yaml --- r: 345948 b: refs/heads/master c: 635eef2 h: refs/heads/master
1 parent 2375b64 commit d6da747

31 files changed

+440
-113
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: a86313f1291d0c1ef78ad5ce749dd24a3e898e19
2+
refs/heads/master: 635eef202f6ca5ea62f0360767ad0cf2aaaef06b
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/benchmark/single-source/ObjectiveCBridgingStubs.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public let ObjectiveCBridgingStubs = [
3737
BenchmarkInfo(name: "ObjectiveCBridgeStringRangeOfString", runFunction: run_ObjectiveCBridgeStringRangeOfString, tags: [.validation, .String, .bridging], setUpFunction: setup_StringBridgeBenchmark),
3838
BenchmarkInfo(name: "ObjectiveCBridgeStringHash", runFunction: run_ObjectiveCBridgeStringHash, tags: [.validation, .String, .bridging], setUpFunction: setup_StringBridgeBenchmark),
3939
BenchmarkInfo(name: "ObjectiveCBridgeStringUTF8String", runFunction: run_ObjectiveCBridgeStringUTF8String, tags: [.validation, .String, .bridging], setUpFunction: setup_StringBridgeBenchmark),
40+
BenchmarkInfo(name: "ObjectiveCBridgeStringCStringUsingEncoding", runFunction: run_ObjectiveCBridgeStringCStringUsingEncoding, tags: [.validation, .String, .bridging], setUpFunction: setup_StringBridgeBenchmark),
4041
]
4142

4243
var b:BridgeTester! = nil
@@ -387,6 +388,17 @@ public func run_ObjectiveCBridgeStringUTF8String(N: Int) {
387388
#endif
388389
}
389390

391+
@inline(never)
392+
public func run_ObjectiveCBridgeStringCStringUsingEncoding(N: Int) {
393+
#if _runtime(_ObjC)
394+
for _ in 0 ..< N {
395+
autoreleasepool {
396+
b.testCStringUsingEncoding()
397+
}
398+
}
399+
#endif
400+
}
401+
390402
@inline(never)
391403
public func setup_StringBridgeBenchmark() {
392404
#if _runtime(_ObjC)

trunk/benchmark/utils/ObjectiveCTests/ObjectiveCTests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
3838
- (void)testIsEqualToString2;
3939
- (void)testIsEqualToStringAllSwift;
4040
- (void)testUTF8String;
41+
- (void)testCStringUsingEncoding;
4142
- (void)testGetUTF8Contents;
4243
- (void)testGetASCIIContents;
4344
- (void)testRangeOfString;

trunk/benchmark/utils/ObjectiveCTests/ObjectiveCTests.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,30 @@ - (void)testUTF8String {
249249
}
250250
}
251251

252+
- (void)testCStringUsingEncoding {
253+
for (NSString *str1 in bridgedStrings) {
254+
@autoreleasepool {
255+
for (int i = 0; i < 100; i++) {
256+
(void)[str1 cStringUsingEncoding: NSASCIIStringEncoding];
257+
}
258+
}
259+
}
260+
for (NSString *str1 in bridgedStrings) {
261+
@autoreleasepool {
262+
for (int i = 0; i < 100; i++) {
263+
(void)[str1 cStringUsingEncoding: NSUTF8StringEncoding];
264+
}
265+
}
266+
}
267+
for (NSString *str1 in bridgedStrings) {
268+
@autoreleasepool {
269+
for (int i = 0; i < 100; i++) {
270+
(void)[str1 cStringUsingEncoding: NSUnicodeStringEncoding];
271+
}
272+
}
273+
}
274+
}
275+
252276
- (void)testGetUTF8Contents {
253277
for (NSString *str1 in bridgedStrings) {
254278
for (int i = 0; i < 200; i++) {

trunk/include/swift/IRGen/Linking.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ class LinkEntity {
676676
}
677677

678678
static LinkEntity forPropertyDescriptor(AbstractStorageDecl *decl) {
679+
assert(decl->exportsPropertyDescriptor());
679680
LinkEntity entity;
680681
entity.setForDecl(Kind::PropertyDescriptor, decl);
681682
return entity;

trunk/include/swift/SIL/SILLinkage.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ enum class SubclassScope : uint8_t {
118118
/// This class can only be subclassed in this module.
119119
Internal,
120120

121+
/// This class is resilient so even public methods cannot be directly
122+
/// referenced from outside the module.
123+
Resilient,
124+
121125
/// There is no class to subclass, or it is final.
122126
NotApplicable,
123127
};
@@ -250,6 +254,11 @@ inline SILLinkage effectiveLinkageForClassMember(SILLinkage linkage,
250254
return SILLinkage::Hidden;
251255
break;
252256

257+
case SubclassScope::Resilient:
258+
if (isAvailableExternally(linkage))
259+
return SILLinkage::HiddenExternal;
260+
return SILLinkage::Hidden;
261+
253262
case SubclassScope::NotApplicable:
254263
break;
255264
}

trunk/lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5335,6 +5335,9 @@ bool AbstractFunctionDecl::isObjCInstanceMethod() const {
53355335
}
53365336

53375337
static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
5338+
if (!isa<ClassDecl>(decl->getDeclContext()))
5339+
return true;
5340+
53385341
assert(isa<FuncDecl>(decl) || isa<ConstructorDecl>(decl));
53395342

53405343
// Final members are always be called directly.

trunk/lib/IRGen/GenInit.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ using namespace irgen;
3737
/// Emit a global variable.
3838
void IRGenModule::emitSILGlobalVariable(SILGlobalVariable *var) {
3939
auto &ti = getTypeInfo(var->getLoweredType());
40-
41-
// If the variable is empty in all resilience domains, don't actually emit it;
42-
// just return undef.
43-
if (ti.isKnownEmpty(ResilienceExpansion::Minimal)) {
40+
auto expansion = getResilienceExpansionForLayout(var);
41+
42+
// If the variable is empty in all resilience domains that can access this
43+
// variable directly, don't actually emit it; just return undef.
44+
if (ti.isKnownEmpty(expansion)) {
4445
if (DebugInfo && var->getDecl()) {
4546
auto DbgTy = DebugTypeInfo::getGlobal(var, Int8Ty, Size(0), Alignment(1));
4647
DebugInfo->emitGlobalVariableDeclaration(

trunk/lib/SIL/SILDeclRef.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,10 +893,14 @@ SubclassScope SILDeclRef::getSubclassScope() const {
893893
return SubclassScope::NotApplicable;
894894

895895
// If this declaration is a function which goes into a vtable, then it's
896-
// symbol must be as visible as its class. Derived classes even have to put
896+
// symbol must be as visible as its class, because derived classes have to put
897897
// all less visible methods of the base class into their vtables.
898898

899-
auto *FD = dyn_cast<AbstractFunctionDecl>(getDecl());
899+
if (auto *CD = dyn_cast<ConstructorDecl>(getDecl()))
900+
if (!CD->isRequired())
901+
return SubclassScope::NotApplicable;
902+
903+
auto *FD = dyn_cast<FuncDecl>(getDecl());
900904
if (!FD)
901905
return SubclassScope::NotApplicable;
902906

@@ -924,6 +928,9 @@ SubclassScope SILDeclRef::getSubclassScope() const {
924928
assert(FD->getEffectiveAccess() <= classType->getEffectiveAccess() &&
925929
"class must be as visible as its members");
926930

931+
if (classType->isResilient())
932+
return SubclassScope::Resilient;
933+
927934
switch (classType->getEffectiveAccess()) {
928935
case AccessLevel::Private:
929936
case AccessLevel::FilePrivate:
@@ -932,8 +939,6 @@ SubclassScope SILDeclRef::getSubclassScope() const {
932939
case AccessLevel::Public:
933940
return SubclassScope::Internal;
934941
case AccessLevel::Open:
935-
if (classType->isResilient())
936-
return SubclassScope::Internal;
937942
return SubclassScope::External;
938943
}
939944

trunk/lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ SILGlobalVariable *SILGenModule::getSILGlobalVariable(VarDecl *gDecl,
3636
}
3737
}
3838

39+
// Get the linkage for SILGlobalVariable.
40+
FormalLinkage formalLinkage;
41+
if (gDecl->isResilient())
42+
formalLinkage = FormalLinkage::Private;
43+
else
44+
formalLinkage = getDeclLinkage(gDecl);
45+
auto silLinkage = getSILLinkage(formalLinkage, forDef);
46+
3947
// Check if it is already created, and update linkage if necessary.
4048
if (auto gv = M.lookUpGlobalVariable(mangledName)) {
4149
// Update the SILLinkage here if this is a definition.
4250
if (forDef == ForDefinition) {
43-
gv->setLinkage(getSILLinkage(getDeclLinkage(gDecl), ForDefinition));
51+
gv->setLinkage(silLinkage);
4452
gv->setDeclaration(false);
4553
}
4654
return gv;
4755
}
4856

49-
// Get the linkage for SILGlobalVariable.
50-
SILLinkage link = getSILLinkage(getDeclLinkage(gDecl), forDef);
5157
SILType silTy = M.Types.getLoweredTypeOfGlobal(gDecl);
5258

53-
auto *silGlobal = SILGlobalVariable::create(M, link, IsNotSerialized,
59+
auto *silGlobal = SILGlobalVariable::create(M, silLinkage, IsNotSerialized,
5460
mangledName, silTy,
5561
None, gDecl);
5662
silGlobal->setDeclaration(!forDef);

trunk/lib/TBDGen/TBDGen.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,30 @@ void TBDGenVisitor::visitAbstractStorageDecl(AbstractStorageDecl *ASD) {
224224
}
225225

226226
void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
227-
// Non-global variables might have an explicit initializer symbol, in
228-
// non-resilient modules.
229-
if (VD->getAttrs().hasAttribute<HasInitialValueAttr>() &&
230-
SwiftModule->getResilienceStrategy() == ResilienceStrategy::Default &&
231-
!isGlobalOrStaticVar(VD)) {
232-
auto declRef = SILDeclRef(VD, SILDeclRef::Kind::StoredPropertyInitializer);
233-
// Stored property initializers for public properties are currently
234-
// public.
235-
addSymbol(declRef);
236-
}
237-
238-
// statically/globally stored variables have some special handling.
239-
if (VD->hasStorage() && isGlobalOrStaticVar(VD)) {
240-
if (getDeclLinkage(VD) == FormalLinkage::PublicUnique) {
241-
// The actual variable has a symbol.
242-
Mangle::ASTMangler mangler;
243-
addSymbol(mangler.mangleEntity(VD, false));
227+
// Variables inside non-resilient modules have some additional symbols.
228+
if (!VD->isResilient()) {
229+
// Non-global variables might have an explicit initializer symbol, in
230+
// non-resilient modules.
231+
if (VD->getAttrs().hasAttribute<HasInitialValueAttr>() &&
232+
!isGlobalOrStaticVar(VD)) {
233+
auto declRef = SILDeclRef(VD, SILDeclRef::Kind::StoredPropertyInitializer);
234+
// Stored property initializers for public properties are currently
235+
// public.
236+
addSymbol(declRef);
244237
}
245238

246-
if (VD->isLazilyInitializedGlobal())
247-
addSymbol(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
239+
// statically/globally stored variables have some special handling.
240+
if (VD->hasStorage() &&
241+
isGlobalOrStaticVar(VD)) {
242+
if (getDeclLinkage(VD) == FormalLinkage::PublicUnique) {
243+
// The actual variable has a symbol.
244+
Mangle::ASTMangler mangler;
245+
addSymbol(mangler.mangleEntity(VD, false));
246+
}
247+
248+
if (VD->isLazilyInitializedGlobal())
249+
addSymbol(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
250+
}
248251
}
249252

250253
visitAbstractStorageDecl(VD);

trunk/stdlib/public/SwiftShims/CoreFoundationShims.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ SWIFT_RUNTIME_STDLIB_API
125125
_swift_shims_CFHashCode
126126
_swift_stdlib_CFStringHashCString(const _swift_shims_UInt8 * _Nonnull bytes,
127127
_swift_shims_CFIndex length);
128+
129+
SWIFT_RUNTIME_STDLIB_API
130+
const __swift_uint8_t * _Nullable
131+
_swift_stdlib_NSStringCStringUsingEncodingTrampoline(id _Nonnull obj,
132+
unsigned long encoding);
133+
134+
SWIFT_RUNTIME_STDLIB_API
135+
__swift_uint8_t
136+
_swift_stdlib_NSStringGetCStringTrampoline(id _Nonnull obj,
137+
_swift_shims_UInt8 *buffer,
138+
_swift_shims_CFIndex maxLength,
139+
unsigned long encoding);
128140

129141
#endif // __OBJC2__
130142

trunk/stdlib/public/core/StringBridge.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ internal func _cocoaHashASCIIBytes(
9393
return _swift_stdlib_CFStringHashCString(bytes, length)
9494
}
9595

96+
// These "trampolines" are effectively objc_msgSend_super.
97+
// They bypass our implementations to use NSString's
98+
99+
@_effects(readonly)
100+
internal func _cocoaCStringUsingEncodingTrampoline(
101+
_ string: _CocoaString,
102+
_ encoding: UInt)
103+
-> UnsafePointer<UInt8>? {
104+
return _swift_stdlib_NSStringCStringUsingEncodingTrampoline(
105+
string,
106+
encoding)
107+
}
108+
109+
110+
@_effects(releasenone)
111+
internal func _cocoaGetCStringTrampoline(
112+
_ string: _CocoaString,
113+
_ buffer: UnsafeMutablePointer<UInt8>,
114+
_ maxLength: Int,
115+
_ encoding: UInt)
116+
-> Int8 {
117+
return Int8(_swift_stdlib_NSStringGetCStringTrampoline(string,
118+
buffer,
119+
maxLength,
120+
encoding))
121+
}
122+
96123
//
97124
// Conversion from NSString to Swift's native representation
98125
//

0 commit comments

Comments
 (0)