Skip to content

Commit ec44276

Browse files
author
David Ungar
authored
---
yaml --- r: 326551 b: refs/heads/tensorflow c: 6efcff6 h: refs/heads/master i: 326549: 5592f02 326547: 3ad12e4 326543: 6b1f30f
1 parent ad44368 commit ec44276

File tree

15 files changed

+183
-161
lines changed

15 files changed

+183
-161
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: b02b4b00efc6d98cc761671e64926a61aa338b43
819+
refs/heads/tensorflow: 6efcff628010ad4aeffc3d26fc451db682da8314
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/include/swift/AST/ClangModuleLoader.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define SWIFT_AST_CLANG_MODULE_LOADER_H
1515

1616
#include "swift/AST/ModuleLoader.h"
17-
#include "swift/Demangling/Demangle.h"
1817

1918
namespace clang {
2019
class ASTContext;
@@ -28,11 +27,24 @@ namespace swift {
2827
class DeclContext;
2928
class VisibleDeclConsumer;
3029

30+
/// Represents the different namespaces for types in C.
31+
///
32+
/// A simplified version of clang::Sema::LookupKind.
33+
enum class ClangTypeKind {
34+
Typedef,
35+
ObjCClass = Typedef,
36+
/// Structs, enums, and unions.
37+
Tag,
38+
ObjCProtocol,
39+
};
40+
3141
class ClangModuleLoader : public ModuleLoader {
3242
private:
3343
virtual void anchor();
44+
3445
protected:
3546
using ModuleLoader::ModuleLoader;
47+
3648
public:
3749
virtual clang::ASTContext &getClangASTContext() const = 0;
3850
virtual clang::Preprocessor &getClangPreprocessor() const = 0;
@@ -56,9 +68,9 @@ class ClangModuleLoader : public ModuleLoader {
5668
///
5769
/// This routine is used for various hacks that are only permitted within
5870
/// overlays of imported modules, e.g., Objective-C bridging conformances.
59-
virtual bool isInOverlayModuleForImportedModule(
60-
const DeclContext *overlayDC,
61-
const DeclContext *importedDC) = 0;
71+
virtual bool
72+
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
73+
const DeclContext *importedDC) = 0;
6274

6375
/// Look for declarations associated with the given name.
6476
///
@@ -70,7 +82,7 @@ class ClangModuleLoader : public ModuleLoader {
7082
/// Note that this method does no filtering. If it finds the type in a loaded
7183
/// module, it returns it. This is intended for use in reflection / debugging
7284
/// contexts where access is not a problem.
73-
virtual void lookupTypeDecl(StringRef clangName, Demangle::Node::Kind kind,
85+
virtual void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
7486
llvm::function_ref<void(TypeDecl *)> receiver) {}
7587

7688
/// Look up type a declaration synthesized by the Clang importer itself, using
@@ -82,11 +94,11 @@ class ClangModuleLoader : public ModuleLoader {
8294
/// module, it returns it. This is intended for use in reflection / debugging
8395
/// contexts where access is not a problem.
8496
virtual void
85-
lookupRelatedEntity(StringRef clangName, StringRef relatedEntityKind,
97+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
98+
StringRef relatedEntityKind,
8699
llvm::function_ref<void(TypeDecl *)> receiver) {}
87100
};
88101

89102
} // namespace swift
90103

91104
#endif // LLVM_SWIFT_AST_CLANG_MODULE_LOADER_H
92-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,17 @@ class GenericContext : private _GenericContext, public DeclContext {
15231523

15241524
/// Determine whether this context has generic parameters
15251525
/// of its own.
1526+
///
1527+
/// \code
1528+
/// class C<T> {
1529+
/// func f1() {} // isGeneric == false
1530+
/// func f2<T>() {} // isGeneric == true
1531+
/// }
1532+
///
1533+
/// protocol P { // isGeneric == true due to implicit Self param
1534+
/// func p() // isGeneric == false
1535+
/// }
1536+
/// \endcode
15261537
bool isGeneric() const { return GenericParams != nullptr; }
15271538

15281539
/// Retrieve the trailing where clause for this extension, if any.

branches/tensorflow/include/swift/ClangImporter/ClangImporter.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ class TypeDecl;
6060
class VisibleDeclConsumer;
6161
enum class SelectorSplitKind;
6262

63-
/// Represents the different namespaces for types in C.
64-
///
65-
/// A simplified version of clang::Sema::LookupKind.
66-
enum class ClangTypeKind {
67-
Typedef,
68-
ObjCClass = Typedef,
69-
/// Structs, enums, and unions.
70-
Tag,
71-
ObjCProtocol,
72-
};
73-
7463
/// Class that imports Clang modules into Swift, mapping directly
7564
/// from Clang ASTs over to Swift ASTs.
7665
class ClangImporter final : public ClangModuleLoader {
@@ -168,8 +157,8 @@ class ClangImporter final : public ClangModuleLoader {
168157
/// Note that this method does no filtering. If it finds the type in a loaded
169158
/// module, it returns it. This is intended for use in reflection / debugging
170159
/// contexts where access is not a problem.
171-
void lookupTypeDecl(StringRef clangName, Demangle::Node::Kind kind,
172-
llvm::function_ref<void(TypeDecl*)> receiver) override;
160+
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
161+
llvm::function_ref<void(TypeDecl *)> receiver) override;
173162

174163
/// Look up type a declaration synthesized by the Clang importer itself, using
175164
/// a "related entity kind" to determine which type it should be. For example,
@@ -180,7 +169,8 @@ class ClangImporter final : public ClangModuleLoader {
180169
/// module, it returns it. This is intended for use in reflection / debugging
181170
/// contexts where access is not a problem.
182171
void
183-
lookupRelatedEntity(StringRef clangName, StringRef relatedEntityKind,
172+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
173+
StringRef relatedEntityKind,
184174
llvm::function_ref<void(TypeDecl *)> receiver) override;
185175

186176
/// Look for textually included declarations from the bridging header.

branches/tensorflow/include/swift/DWARFImporter/DWARFImporter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "swift/AST/ClangModuleLoader.h"
2121
#include "swift/AST/Module.h"
22-
#include "swift/Demangling/Demangle.h"
2322

2423
namespace llvm {
2524
}
@@ -43,8 +42,7 @@ class DWARFImporterDelegate {
4342
virtual ~DWARFImporterDelegate() = default;
4443
/// Perform a qualified lookup of a Clang type with this name.
4544
/// \param kind Only return results with this type kind.
46-
virtual void lookupValue(StringRef name,
47-
llvm::Optional<Demangle::Node::Kind> kind,
45+
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
4846
SmallVectorImpl<clang::Decl *> &results) {}
4947
};
5048

@@ -111,7 +109,7 @@ class DWARFImporter final : public ClangModuleLoader {
111109
NLKind lookupKind, SmallVectorImpl<ValueDecl *> &results);
112110
/// Perform a qualified lookup of a Clang type with this name and only return
113111
/// results with the specified type kind.
114-
void lookupTypeDecl(StringRef rawName, Demangle::Node::Kind kind,
112+
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
115113
llvm::function_ref<void(TypeDecl *)> receiver) override;
116114
bool
117115
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,

branches/tensorflow/lib/AST/ASTDemangler.cpp

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/Types.h"
3333
#include "swift/Demangling/Demangler.h"
3434
#include "swift/Demangling/ManglingMacros.h"
35+
#include "llvm/ADT/StringSwitch.h"
3536

3637
using namespace swift;
3738

@@ -838,22 +839,45 @@ CanGenericSignature ASTBuilder::demangleGenericSignature(
838839
break;
839840
}
840841
case Demangle::Node::Kind::DependentGenericLayoutRequirement: {
841-
// FIXME: Other layout constraints
842-
LayoutConstraint constraint;
843842
auto kindChild = child->getChild(1);
844843
if (kindChild->getKind() != Demangle::Node::Kind::Identifier)
845844
return CanGenericSignature();
846845

847-
if (kindChild->getText() == "C") {
848-
auto kind = LayoutConstraintKind::Class;
849-
auto layout = LayoutConstraint::getLayoutConstraint(kind, Ctx);
850-
builder.addRequirement(
851-
Requirement(RequirementKind::Layout, subjectType, layout),
852-
source, nullptr);
853-
break;
846+
auto kind = llvm::StringSwitch<Optional<
847+
LayoutConstraintKind>>(kindChild->getText())
848+
.Case("U", LayoutConstraintKind::UnknownLayout)
849+
.Case("R", LayoutConstraintKind::RefCountedObject)
850+
.Case("N", LayoutConstraintKind::NativeRefCountedObject)
851+
.Case("C", LayoutConstraintKind::Class)
852+
.Case("D", LayoutConstraintKind::NativeClass)
853+
.Case("T", LayoutConstraintKind::Trivial)
854+
.Cases("E", "e", LayoutConstraintKind::TrivialOfExactSize)
855+
.Cases("M", "m", LayoutConstraintKind::TrivialOfAtMostSize)
856+
.Default(None);
857+
858+
if (!kind)
859+
return CanGenericSignature();
860+
861+
LayoutConstraint layout;
862+
863+
if (kind != LayoutConstraintKind::TrivialOfExactSize &&
864+
kind != LayoutConstraintKind::TrivialOfAtMostSize) {
865+
layout = LayoutConstraint::getLayoutConstraint(*kind, Ctx);
866+
} else {
867+
auto size = child->getChild(2)->getIndex();
868+
auto alignment = 0;
869+
870+
if (child->getNumChildren() == 4)
871+
alignment = child->getChild(3)->getIndex();
872+
873+
layout = LayoutConstraint::getLayoutConstraint(*kind, size, alignment,
874+
Ctx);
854875
}
855876

856-
return CanGenericSignature();
877+
builder.addRequirement(
878+
Requirement(RequirementKind::Layout, subjectType, layout),
879+
source, nullptr);
880+
break;
857881
}
858882
default:
859883
return CanGenericSignature();
@@ -1023,6 +1047,23 @@ ASTBuilder::findTypeDecl(DeclContext *dc,
10231047
return result;
10241048
}
10251049

1050+
static Optional<ClangTypeKind>
1051+
getClangTypeKindForNodeKind(Demangle::Node::Kind kind) {
1052+
switch (kind) {
1053+
case Demangle::Node::Kind::Protocol:
1054+
return ClangTypeKind::ObjCProtocol;
1055+
case Demangle::Node::Kind::Class:
1056+
return ClangTypeKind::ObjCClass;
1057+
case Demangle::Node::Kind::TypeAlias:
1058+
return ClangTypeKind::Typedef;
1059+
case Demangle::Node::Kind::Structure:
1060+
case Demangle::Node::Kind::Enum:
1061+
return ClangTypeKind::Tag;
1062+
default:
1063+
return None;
1064+
}
1065+
}
1066+
10261067
GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10271068
StringRef relatedEntityKind,
10281069
ForeignModuleKind foreignKind,
@@ -1060,23 +1101,28 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10601101
consumer.foundDecl(found, DeclVisibilityKind::VisibleAtTopLevel);
10611102
};
10621103

1104+
Optional<ClangTypeKind> lookupKind = getClangTypeKindForNodeKind(kind);
1105+
if (!lookupKind)
1106+
return nullptr;
1107+
10631108
switch (foreignKind) {
10641109
case ForeignModuleKind::SynthesizedByImporter:
10651110
if (!relatedEntityKind.empty()) {
1066-
importer->lookupRelatedEntity(name, relatedEntityKind, found);
1111+
importer->lookupRelatedEntity(name, *lookupKind, relatedEntityKind,
1112+
found);
10671113
break;
10681114
}
10691115
importer->lookupValue(Ctx.getIdentifier(name), consumer);
10701116
if (consumer.Result)
10711117
consumer.Result = getAcceptableTypeDeclCandidate(consumer.Result, kind);
10721118
break;
10731119
case ForeignModuleKind::Imported:
1074-
importer->lookupTypeDecl(name, kind, found);
1120+
importer->lookupTypeDecl(name, *lookupKind, found);
10751121

10761122
// Try the DWARFImporter if it exists.
10771123
if (!consumer.Result)
10781124
if (auto *dwarf_importer = Ctx.getDWARFModuleLoader())
1079-
dwarf_importer->lookupTypeDecl(name, kind, found);
1125+
dwarf_importer->lookupTypeDecl(name, *lookupKind, found);
10801126
}
10811127

10821128
return consumer.Result;

branches/tensorflow/lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,34 +2495,14 @@ void ClangImporter::lookupValue(DeclName name, VisibleDeclConsumer &consumer){
24952495
});
24962496
}
24972497

2498-
static Optional<ClangTypeKind>
2499-
getClangTypeKindForNodeKind(Demangle::Node::Kind kind) {
2500-
switch (kind) {
2501-
case Demangle::Node::Kind::Protocol:
2502-
return ClangTypeKind::ObjCProtocol;
2503-
case Demangle::Node::Kind::Class:
2504-
return ClangTypeKind::ObjCClass;
2505-
case Demangle::Node::Kind::TypeAlias:
2506-
return ClangTypeKind::Typedef;
2507-
case Demangle::Node::Kind::Structure:
2508-
case Demangle::Node::Kind::Enum:
2509-
return ClangTypeKind::Tag;
2510-
default:
2511-
return None;
2512-
}
2513-
}
2514-
25152498
void ClangImporter::lookupTypeDecl(
2516-
StringRef rawName, Demangle::Node::Kind kind,
2499+
StringRef rawName, ClangTypeKind kind,
25172500
llvm::function_ref<void(TypeDecl *)> receiver) {
25182501
clang::DeclarationName clangName(
25192502
&Impl.Instance->getASTContext().Idents.get(rawName));
25202503

25212504
clang::Sema::LookupNameKind lookupKind;
2522-
auto clang_kind = getClangTypeKindForNodeKind(kind);
2523-
if (!clang_kind)
2524-
return;
2525-
switch (*clang_kind) {
2505+
switch (kind) {
25262506
case ClangTypeKind::Typedef:
25272507
lookupKind = clang::Sema::LookupOrdinaryName;
25282508
break;
@@ -2553,17 +2533,17 @@ void ClangImporter::lookupTypeDecl(
25532533
}
25542534

25552535
void ClangImporter::lookupRelatedEntity(
2556-
StringRef rawName, StringRef relatedEntityKind,
2536+
StringRef rawName, ClangTypeKind kind, StringRef relatedEntityKind,
25572537
llvm::function_ref<void(TypeDecl *)> receiver) {
25582538
using CISTAttr = ClangImporterSynthesizedTypeAttr;
25592539
if (relatedEntityKind ==
25602540
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapper) ||
25612541
relatedEntityKind ==
25622542
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapperAnon)) {
2563-
auto underlyingKind = Demangle::Node::Kind::Structure;
2543+
auto underlyingKind = ClangTypeKind::Tag;
25642544
if (relatedEntityKind ==
25652545
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapperAnon)) {
2566-
underlyingKind = Demangle::Node::Kind::TypeAlias;
2546+
underlyingKind = ClangTypeKind::Typedef;
25672547
}
25682548
lookupTypeDecl(rawName, underlyingKind,
25692549
[this, receiver] (const TypeDecl *foundType) {

branches/tensorflow/lib/DWARFImporter/DWARFImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class DWARFImporter::Implementation {
177177
}
178178
}
179179

180-
void lookupTypeDecl(StringRef rawName, Demangle::Node::Kind kind,
180+
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
181181
llvm::function_ref<void(TypeDecl *)> receiver) {
182182
SmallVector<clang::Decl *, 1> decls;
183183
delegate->lookupValue(rawName, kind, decls);
@@ -250,7 +250,7 @@ void DWARFImporter::lookupValue(ModuleDecl::AccessPathTy accessPath,
250250
}
251251

252252
void DWARFImporter::lookupTypeDecl(
253-
StringRef rawName, Demangle::Node::Kind kind,
253+
StringRef rawName, ClangTypeKind kind,
254254
llvm::function_ref<void(TypeDecl *)> receiver) {
255255
Impl.lookupTypeDecl(rawName, kind, receiver);
256256
}

branches/tensorflow/lib/Sema/CodeSynthesis.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,27 @@ createDesignatedInitOverride(ClassDecl *classDecl,
648648
// Determine the initializer parameters.
649649

650650
// Create the initializer parameter patterns.
651-
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
652-
options |= ParameterList::Inherited;
653-
auto *bodyParams = superclassCtor->getParameters()->clone(ctx, options);
651+
OptionSet<ParameterList::CloneFlags> options
652+
= (ParameterList::Implicit |
653+
ParameterList::Inherited |
654+
ParameterList::WithoutTypes);
655+
auto *superclassParams = superclassCtor->getParameters();
656+
auto *bodyParams = superclassParams->clone(ctx, options);
654657

655658
// If the superclass is generic, we need to map the superclass constructor's
656659
// parameter types into the generic context of our class.
657660
//
658661
// We might have to apply substitutions, if for example we have a declaration
659662
// like 'class A : B<Int>'.
660-
for (auto *decl : *bodyParams) {
661-
auto paramTy = decl->getInterfaceType();
663+
for (unsigned idx : range(superclassParams->size())) {
664+
auto *superclassParam = superclassParams->get(idx);
665+
auto *bodyParam = bodyParams->get(idx);
666+
667+
auto paramTy = superclassParam->getInterfaceType();
662668
auto substTy = paramTy.subst(subMap, SubstFlags::UseErrorType);
663-
decl->setInterfaceType(substTy);
664-
decl->getTypeLoc() = TypeLoc::withoutLoc(substTy);
669+
670+
bodyParam->setInterfaceType(substTy);
671+
bodyParam->getTypeLoc() = TypeLoc::withoutLoc(substTy);
665672
}
666673

667674
// Create the initializer declaration, inheriting the name,

0 commit comments

Comments
 (0)