Skip to content

Commit 92b5a4e

Browse files
authored
---
yaml --- r: 278335 b: refs/heads/swift-5.1-old-llvm-branch c: 29fcb2e h: refs/heads/master i: 278333: 506e7b9 278331: ad46375 278327: d147eed 278319: 905ced2 278303: 2eb2f61 278271: 79473d5
1 parent 6003440 commit 92b5a4e

30 files changed

+776
-185
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-01-24-a: b6f62823aa5010b2ae53f15f72a57
12411241
refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e0
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
1244-
refs/heads/swift-5.1-old-llvm-branch: 98ed241ce5c23c5a03be4378110e7aee48dc556e
1244+
refs/heads/swift-5.1-old-llvm-branch: 29fcb2e290e11eebae65bb39eb678d7028f68975
12451245
refs/heads/swift-5.1-branch: 8060872acb4105d9655e020fe047e1ebcd77d0fb
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e

branches/swift-5.1-old-llvm-branch/include/swift/AST/ASTMangler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class ASTMangler : public Mangler {
3838
/// Optimize out protocol names if a type only conforms to one protocol.
3939
bool OptimizeProtocolNames = true;
4040

41+
/// If enabled, use Objective-C runtime names when mangling @objc Swift
42+
/// protocols.
43+
bool UseObjCProtocolNames = false;
44+
4145
/// If enabled, non-canonical types are allowed and type alias types get a
4246
/// special mangling.
4347
bool DWARFMangling;
@@ -187,7 +191,7 @@ class ASTMangler : public Mangler {
187191
};
188192

189193
static Optional<SpecialContext>
190-
getSpecialManglingContext(const ValueDecl *decl);
194+
getSpecialManglingContext(const ValueDecl *decl, bool useObjCProtocolNames);
191195

192196
static const clang::NamedDecl *
193197
getClangDeclForMangling(const ValueDecl *decl);

branches/swift-5.1-old-llvm-branch/include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ struct PrintOptions {
275275
/// '@sil_weak', '@sil_unmanaged'.
276276
bool PrintStorageRepresentationAttrs = false;
277277

278+
/// Whether to print 'static' or 'class' on static decls.
279+
bool PrintStaticKeyword = true;
280+
278281
/// Whether to print 'override' keyword on overridden decls.
279282
bool PrintOverrideKeyword = true;
280283

branches/swift-5.1-old-llvm-branch/include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class CodeCompletionCallbacks {
174174
/// Complete at the beginning of member of a nominal decl member -- no tokens
175175
/// provided by user.
176176
virtual void completeNominalMemberBeginning(
177-
SmallVectorImpl<StringRef> &Keywords) {};
177+
SmallVectorImpl<StringRef> &Keywords, SourceLoc introducerLoc) {};
178178

179179
/// Complete at the beginning of accessor in a accessor block.
180180
virtual void completeAccessorBeginning() {};

branches/swift-5.1-old-llvm-branch/lib/AST/ASTMangler.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
367367
DWARFMangling = true;
368368
OptimizeProtocolNames = false;
369369
beginMangling();
370-
370+
371371
if (DC)
372372
bindGenericParameters(DC);
373373

@@ -601,6 +601,33 @@ static StringRef getPrivateDiscriminatorIfNecessary(const ValueDecl *decl) {
601601
return discriminator.str();
602602
}
603603

604+
/// If the declaration is an @objc protocol defined in Swift and the
605+
/// Objective-C name has been overrridden from the default, return the
606+
/// specified name.
607+
///
608+
/// \param useObjCProtocolNames When false, always returns \c None.
609+
static Optional<std::string> getOverriddenSwiftProtocolObjCName(
610+
const ValueDecl *decl,
611+
bool useObjCProtocolNames) {
612+
if (!useObjCProtocolNames)
613+
return None;
614+
615+
auto proto = dyn_cast<ProtocolDecl>(decl);
616+
if (!proto) return None;
617+
618+
if (!proto->isObjC()) return None;
619+
620+
// If there is an 'objc' attribute with a name, use that name.
621+
if (auto objc = proto->getAttrs().getAttribute<ObjCAttr>()) {
622+
if (auto name = objc->getName()) {
623+
llvm::SmallString<4> buffer;
624+
return std::string(name->getString(buffer));
625+
}
626+
}
627+
628+
return None;
629+
}
630+
604631
void ASTMangler::appendDeclName(const ValueDecl *decl) {
605632
DeclBaseName name = decl->getBaseName();
606633
assert(!name.isSpecial() && "Cannot print special names");
@@ -625,6 +652,11 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
625652
appendOperator("oi");
626653
break;
627654
}
655+
} else if (auto objCName =
656+
getOverriddenSwiftProtocolObjCName(decl, UseObjCProtocolNames)) {
657+
// @objc Swift protocols should be mangled as Objective-C protocols,
658+
// so append the Objective-C runtime name.
659+
appendIdentifier(*objCName);
628660
} else if (!name.empty()) {
629661
appendIdentifier(name.getIdentifier().str());
630662
} else {
@@ -1353,7 +1385,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn) {
13531385
}
13541386

13551387
Optional<ASTMangler::SpecialContext>
1356-
ASTMangler::getSpecialManglingContext(const ValueDecl *decl) {
1388+
ASTMangler::getSpecialManglingContext(const ValueDecl *decl,
1389+
bool useObjCProtocolNames) {
13571390
// Declarations provided by a C module have a special context mangling.
13581391
// known-context ::= 'So'
13591392
//
@@ -1369,6 +1402,11 @@ ASTMangler::getSpecialManglingContext(const ValueDecl *decl) {
13691402
}
13701403
}
13711404

1405+
// If @objc Swift protocols should be mangled as Objective-C protocols,
1406+
// they are defined in the Objective-C context.
1407+
if (getOverriddenSwiftProtocolObjCName(decl, useObjCProtocolNames))
1408+
return ASTMangler::ObjCContext;
1409+
13721410
// Nested types imported from C should also get use the special "So" context.
13731411
if (isa<TypeDecl>(decl)) {
13741412
if (auto *clangDecl = cast_or_null<clang::NamedDecl>(decl->getClangDecl())){
@@ -1394,7 +1432,7 @@ ASTMangler::getSpecialManglingContext(const ValueDecl *decl) {
13941432
/// This is the top-level entrypoint for mangling <context>.
13951433
void ASTMangler::appendContextOf(const ValueDecl *decl) {
13961434
// Check for a special mangling context.
1397-
if (auto context = getSpecialManglingContext(decl)) {
1435+
if (auto context = getSpecialManglingContext(decl, UseObjCProtocolNames)) {
13981436
switch (*context) {
13991437
case ClangImporterContext:
14001438
return appendOperator("SC");

branches/swift-5.1-old-llvm-branch/lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
24112411
printAttributes(decl);
24122412
printAccess(decl);
24132413
if (!Options.SkipIntroducerKeywords) {
2414-
if (decl->isStatic())
2414+
if (decl->isStatic() && Options.PrintStaticKeyword)
24152415
printStaticKeyword(decl->getCorrectStaticSpelling());
24162416
if (decl->getKind() == DeclKind::Var
24172417
|| Options.PrintParameterSpecifiers) {
@@ -2687,7 +2687,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
26872687
printSourceRange(Range, Ctx);
26882688
} else {
26892689
if (!Options.SkipIntroducerKeywords) {
2690-
if (decl->isStatic())
2690+
if (decl->isStatic() && Options.PrintStaticKeyword)
26912691
printStaticKeyword(decl->getCorrectStaticSpelling());
26922692
if (decl->isMutating() && !decl->getAttrs().hasAttribute<MutatingAttr>()) {
26932693
Printer.printKeyword("mutating", Options, " ");

branches/swift-5.1-old-llvm-branch/lib/Driver/DarwinToolChains.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ static bool findXcodeClangPath(llvm::SmallVectorImpl<char> &path) {
169169

170170
auto xcrunPath = llvm::sys::findProgramByName("xcrun");
171171
if (!xcrunPath.getError()) {
172-
const char *args[] = {"-f", "clang", nullptr};
172+
// Explicitly ask for the default toolchain so that we don't find a Clang
173+
// included with an open-source toolchain.
174+
const char *args[] = {"-toolchain", "default", "-f", "clang", nullptr};
173175
sys::TaskQueue queue;
174176
queue.addTask(xcrunPath->c_str(), args, /*Env=*/llvm::None,
175177
/*Context=*/nullptr,

branches/swift-5.1-old-llvm-branch/lib/IDE/CodeCompletion.cpp

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12501250
Optional<StmtKind> ParentStmtKind;
12511251

12521252
SmallVector<StringRef, 3> ParsedKeywords;
1253+
SourceLoc introducerLoc;
12531254

12541255
std::vector<std::pair<std::string, bool>> SubModuleNameVisibilityPairs;
12551256

@@ -1348,7 +1349,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13481349
void completeDeclAttrParam(DeclAttrKind DK, int Index) override;
13491350
void completeInPrecedenceGroup(SyntaxKind SK) override;
13501351
void completeNominalMemberBeginning(
1351-
SmallVectorImpl<StringRef> &Keywords) override;
1352+
SmallVectorImpl<StringRef> &Keywords, SourceLoc introducerLoc) override;
13521353
void completeAccessorBeginning() override;
13531354

13541355
void completePoundAvailablePlatform() override;
@@ -3858,9 +3859,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
38583859

38593860
class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
38603861
CodeCompletionResultSink &Sink;
3862+
ASTContext &Ctx;
38613863
const DeclContext *CurrDeclContext;
38623864
LazyResolver *TypeResolver;
38633865
SmallVectorImpl<StringRef> &ParsedKeywords;
3866+
SourceLoc introducerLoc;
38643867

38653868
bool hasFuncIntroducer = false;
38663869
bool hasVarIntroducer = false;
@@ -3869,13 +3872,15 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
38693872
bool hasAccessModifier = false;
38703873
bool hasOverride = false;
38713874
bool hasOverridabilityModifier = false;
3875+
bool hasStaticOrClass = false;
38723876

38733877
public:
38743878
CompletionOverrideLookup(CodeCompletionResultSink &Sink, ASTContext &Ctx,
38753879
const DeclContext *CurrDeclContext,
3876-
SmallVectorImpl<StringRef> &ParsedKeywords)
3877-
: Sink(Sink),
3878-
CurrDeclContext(CurrDeclContext), ParsedKeywords(ParsedKeywords) {
3880+
SmallVectorImpl<StringRef> &ParsedKeywords,
3881+
SourceLoc introducerLoc)
3882+
: Sink(Sink), Ctx(Ctx), CurrDeclContext(CurrDeclContext),
3883+
ParsedKeywords(ParsedKeywords), introducerLoc(introducerLoc) {
38793884
(void)createTypeChecker(Ctx);
38803885
TypeResolver = Ctx.getLazyResolver();
38813886

@@ -3893,6 +3898,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
38933898
hasOverride = isKeywordSpecified("override");
38943899
hasOverridabilityModifier = isKeywordSpecified("final") ||
38953900
isKeywordSpecified("open");
3901+
hasStaticOrClass = isKeywordSpecified(getTokenText(tok::kw_class)) ||
3902+
isKeywordSpecified(getTokenText(tok::kw_static));
38963903
}
38973904

38983905
bool isKeywordSpecified(StringRef Word) {
@@ -3942,19 +3949,28 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
39423949
Options.setBaseType(transformType);
39433950
Options.PrintImplicitAttrs = false;
39443951
Options.ExclusiveAttrList.push_back(TAK_escaping);
3952+
Options.ExclusiveAttrList.push_back(TAK_autoclosure);
39453953
Options.PrintOverrideKeyword = false;
39463954
Options.PrintPropertyAccessors = false;
3955+
Options.PrintStaticKeyword = !hasStaticOrClass;
39473956
VD->print(Printer, Options);
39483957
NameOffset = Printer.NameOffset.getValue();
39493958
}
39503959

39513960
if (!hasDeclIntroducer && !hasAccessModifier)
39523961
addAccessControl(VD, Builder);
39533962

3954-
// FIXME: if we're missing 'override', but have the decl introducer we
3955-
// should delete it and re-add both in the correct order.
3956-
if (!hasDeclIntroducer && missingOverride(Reason))
3957-
Builder.addOverrideKeyword();
3963+
if (missingOverride(Reason)) {
3964+
if (!hasDeclIntroducer)
3965+
Builder.addOverrideKeyword();
3966+
else {
3967+
auto dist = Ctx.SourceMgr.getByteDistance(
3968+
introducerLoc, Ctx.SourceMgr.getCodeCompletionLoc());
3969+
Builder.setNumBytesToErase(dist);
3970+
Builder.addOverrideKeyword();
3971+
Builder.addDeclIntroducer(DeclStr.str().substr(0, NameOffset));
3972+
}
3973+
}
39583974

39593975
if (!hasDeclIntroducer)
39603976
Builder.addDeclIntroducer(DeclStr.str().substr(0, NameOffset));
@@ -4050,7 +4066,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
40504066
if (D->shouldHideFromEditor())
40514067
return;
40524068

4053-
if (D->getAttrs().hasAttribute<FinalAttr>())
4069+
if (D->getAttrs().hasAttribute<FinalAttr>() ||
4070+
// A 'class' member with an initial value cannot be overriden either.
4071+
(D->isStatic() && D->getAttrs().hasAttribute<HasInitialValueAttr>()))
40544072
return;
40554073

40564074
if (!D->hasInterfaceType())
@@ -4060,6 +4078,15 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
40604078
hasVarIntroducer ||
40614079
hasTypealiasIntroducer;
40624080

4081+
if (hasStaticOrClass && !D->isStatic())
4082+
return;
4083+
4084+
// As per the current convention, only instance members are
4085+
// suggested if an introducer is not accompanied by a 'static' or
4086+
// 'class' modifier.
4087+
if (hasIntroducer && !hasStaticOrClass && D->isStatic())
4088+
return;
4089+
40634090
if (auto *FD = dyn_cast<FuncDecl>(D)) {
40644091
// We cannot override operators as members.
40654092
if (FD->isBinaryOperator() || FD->isUnaryOperator())
@@ -4083,7 +4110,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
40834110
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
40844111
if (!isa<ProtocolDecl>(CD->getDeclContext()))
40854112
return;
4086-
if (hasIntroducer || hasOverride || hasOverridabilityModifier)
4113+
if (hasIntroducer || hasOverride || hasOverridabilityModifier ||
4114+
hasStaticOrClass)
40874115
return;
40884116
if (CD->isRequired() || CD->isDesignatedInit())
40894117
addConstructor(CD, Reason);
@@ -4093,7 +4121,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
40934121

40944122
void addDesignatedInitializers(NominalTypeDecl *NTD) {
40954123
if (hasFuncIntroducer || hasVarIntroducer || hasTypealiasIntroducer ||
4096-
hasOverridabilityModifier)
4124+
hasOverridabilityModifier || hasStaticOrClass)
40974125
return;
40984126

40994127
const auto *CD = dyn_cast<ClassDecl>(NTD);
@@ -4116,7 +4144,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41164144
void addAssociatedTypes(NominalTypeDecl *NTD) {
41174145
if (!hasTypealiasIntroducer &&
41184146
(hasFuncIntroducer || hasVarIntroducer || hasInitializerModifier ||
4119-
hasOverride || hasOverridabilityModifier))
4147+
hasOverride || hasOverridabilityModifier || hasStaticOrClass))
41204148
return;
41214149

41224150
for (auto Conformance : NTD->getAllConformances()) {
@@ -4147,9 +4175,11 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41474175
Type CurrTy = CurrDeclContext->getSelfTypeInContext();
41484176
auto *NTD = CurrDeclContext->getSelfNominalTypeDecl();
41494177
if (CurrTy && !CurrTy->is<ErrorType>()) {
4150-
lookupVisibleMemberDecls(*this, CurrTy, CurrDeclContext,
4178+
// Look for overridable static members too.
4179+
Type Meta = MetatypeType::get(CurrTy);
4180+
lookupVisibleMemberDecls(*this, Meta, CurrDeclContext,
41514181
TypeResolver,
4152-
/*includeInstanceMembers=*/false);
4182+
/*includeInstanceMembers=*/true);
41534183
addDesignatedInitializers(NTD);
41544184
addAssociatedTypes(NTD);
41554185
}
@@ -4471,8 +4501,9 @@ void CodeCompletionCallbacksImpl::completeGenericParams(TypeLoc TL) {
44714501
}
44724502

44734503
void CodeCompletionCallbacksImpl::completeNominalMemberBeginning(
4474-
SmallVectorImpl<StringRef> &Keywords) {
4504+
SmallVectorImpl<StringRef> &Keywords, SourceLoc introducerLoc) {
44754505
assert(!InEnumElementRawValue);
4506+
this->introducerLoc = introducerLoc;
44764507
ParsedKeywords.clear();
44774508
ParsedKeywords.append(Keywords.begin(), Keywords.end());
44784509
Kind = CompletionKind::NominalMemberBeginning;
@@ -4651,10 +4682,11 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
46514682
break;
46524683

46534684
case CompletionKind::NominalMemberBeginning: {
4654-
bool HasDeclIntroducer = llvm::find_if(ParsedKeywords, [](const StringRef kw) {
4685+
bool HasDeclIntroducer = llvm::find_if(ParsedKeywords,
4686+
[this](const StringRef kw) {
46554687
return llvm::StringSwitch<bool>(kw)
46564688
.Case("associatedtype", true)
4657-
.Case("class", true)
4689+
.Case("class", !CurDeclContext || !isa<ClassDecl>(CurDeclContext))
46584690
.Case("deinit", true)
46594691
.Case("enum", true)
46604692
.Case("extension", true)
@@ -5027,7 +5059,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
50275059
case CompletionKind::NominalMemberBeginning: {
50285060
CompletionOverrideLookup OverrideLookup(CompletionContext.getResultSink(),
50295061
P.Context, CurDeclContext,
5030-
ParsedKeywords);
5062+
ParsedKeywords, introducerLoc);
50315063
OverrideLookup.getOverrideCompletions(SourceLoc());
50325064
break;
50335065
}

branches/swift-5.1-old-llvm-branch/lib/IDE/SyntaxModel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ SyntaxModelContext::SyntaxModelContext(SourceFile &SrcFile)
178178
}
179179

180180
case tok::unknown: {
181-
if (Tok.getRawText().startswith("\"")) {
182-
// This is an invalid string literal
181+
if (Tok.getRawText().ltrim('#').startswith("\"")) {
182+
// This is likely an invalid single-line ("), multi-line ("""),
183+
// or raw (#", ##", #""", etc.) string literal.
183184
Kind = SyntaxNodeKind::String;
184185
break;
185186
}

branches/swift-5.1-old-llvm-branch/lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,9 @@ IRGenModule::getAddrOfParentContextDescriptor(DeclContext *from,
747747
// Some types get special treatment.
748748
if (auto Type = dyn_cast<NominalTypeDecl>(from)) {
749749
// Use a special module context if we have one.
750-
if (auto context = Mangle::ASTMangler::getSpecialManglingContext(Type)) {
750+
if (auto context =
751+
Mangle::ASTMangler::getSpecialManglingContext(
752+
Type, /*UseObjCProtocolNames=*/false)) {
751753
switch (*context) {
752754
case Mangle::ASTMangler::ObjCContext:
753755
return {getAddrOfObjCModuleContextDescriptor(),

branches/swift-5.1-old-llvm-branch/lib/IRGen/IRGenMangler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
8383
llvm::function_ref<void ()> body) {
8484
Mod = IGM.getSwiftModule();
8585
OptimizeProtocolNames = false;
86+
UseObjCProtocolNames = true;
8687

8788
llvm::SaveAndRestore<bool>
8889
AllowSymbolicReferencesLocally(AllowSymbolicReferences);

0 commit comments

Comments
 (0)