Skip to content

Commit dea9a91

Browse files
author
Nathan Hawes
committed
---
yaml --- r: 326599 b: refs/heads/tensorflow c: 4641792 h: refs/heads/master i: 326597: b64473a 326595: 029db96 326591: 14b4b3d
1 parent 93fcaa3 commit dea9a91

File tree

16 files changed

+81
-112
lines changed

16 files changed

+81
-112
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: 9f6b3e2c658d711e252c9583671842469dd97439
819+
refs/heads/tensorflow: 4641792fe1903fffddfa8dfb2244d63d9536b34d
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: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,6 @@ class ClangModuleLoader : public ModuleLoader {
7171
virtual bool
7272
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
7373
const DeclContext *importedDC) = 0;
74-
75-
/// Look for declarations associated with the given name.
76-
///
77-
/// \param name The name we're searching for.
78-
virtual void lookupValue(DeclName name, VisibleDeclConsumer &consumer) = 0;
79-
80-
/// Look up a type declaration by its Clang name.
81-
///
82-
/// Note that this method does no filtering. If it finds the type in a loaded
83-
/// module, it returns it. This is intended for use in reflection / debugging
84-
/// contexts where access is not a problem.
85-
virtual void
86-
lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
87-
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
88-
89-
/// Look up type a declaration synthesized by the Clang importer itself, using
90-
/// a "related entity kind" to determine which type it should be. For example,
91-
/// this can be used to find the synthesized error struct for an
92-
/// NS_ERROR_ENUM.
93-
///
94-
/// Note that this method does no filtering. If it finds the type in a loaded
95-
/// module, it returns it. This is intended for use in reflection / debugging
96-
/// contexts where access is not a problem.
97-
virtual void
98-
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
99-
StringRef relatedEntityKind,
100-
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
10174
};
10275

10376
} // namespace swift

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

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ class Type {
374374
class CanType : public Type {
375375
bool isActuallyCanonicalOrNull() const;
376376

377-
static bool isReferenceTypeImpl(CanType type, GenericSignature *sig,
378-
bool functionsCount);
377+
static bool isReferenceTypeImpl(CanType type, bool functionsCount);
379378
static bool isExistentialTypeImpl(CanType type);
380379
static bool isAnyExistentialTypeImpl(CanType type);
381380
static bool isObjCExistentialTypeImpl(CanType type);
@@ -409,26 +408,8 @@ class CanType : public Type {
409408
// Provide a few optimized accessors that are really type-class queries.
410409

411410
/// Do values of this type have reference semantics?
412-
///
413-
/// This includes isAnyClassReferenceType(), as well as function types.
414411
bool hasReferenceSemantics() const {
415-
return isReferenceTypeImpl(*this,
416-
/*signature*/ nullptr,
417-
/*functions count*/ true);
418-
}
419-
420-
/// Are variables of this type permitted to have
421-
/// ownership attributes?
422-
///
423-
/// This includes:
424-
/// - class types, generic or not
425-
/// - archetypes with class or class protocol bounds
426-
/// - existentials with class or class protocol bounds
427-
/// But not:
428-
/// - function types
429-
bool allowsOwnership(GenericSignature *sig) const {
430-
return isReferenceTypeImpl(*this, sig,
431-
/*functions count*/ false);
412+
return isReferenceTypeImpl(*this, /*functions count*/ true);
432413
}
433414

434415
/// Are values of this type essentially just class references,
@@ -438,13 +419,10 @@ class CanType : public Type {
438419
/// - a class type
439420
/// - a bound generic class type
440421
/// - a class-bounded archetype type
441-
/// - a class-bounded type parameter
442422
/// - a class-bounded existential type
443423
/// - a dynamic Self type
444424
bool isAnyClassReferenceType() const {
445-
return isReferenceTypeImpl(*this,
446-
/*signature*/ nullptr,
447-
/*functions count*/ false);
425+
return isReferenceTypeImpl(*this, /*functions count*/ false);
448426
}
449427

450428
/// Is this type existential?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
541541

542542
/// allowsOwnership() - Are variables of this type permitted to have
543543
/// ownership attributes?
544-
bool allowsOwnership(GenericSignature *sig=nullptr);
544+
bool allowsOwnership();
545545

546546
/// Determine whether this type involves a type variable.
547547
bool hasTypeVariable() const {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ enum class SelectorSplitKind;
7171
/// Clang AST to ClangImporter to import the type into Swift.
7272
class DWARFImporterDelegate {
7373
public:
74-
virtual ~DWARFImporterDelegate() = default;
74+
virtual ~DWARFImporterDelegate() {}
7575
/// Perform a qualified lookup of a Clang type with this name.
7676
/// \param kind Only return results with this type kind.
7777
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
7878
SmallVectorImpl<clang::Decl *> &results) {}
79-
/// vtable anchor.
80-
virtual void anchor();
8179
};
8280

8381
/// Class that imports Clang modules into Swift, mapping directly
@@ -174,15 +172,15 @@ class ClangImporter final : public ClangModuleLoader {
174172
/// Look for declarations associated with the given name.
175173
///
176174
/// \param name The name we're searching for.
177-
void lookupValue(DeclName name, VisibleDeclConsumer &consumer) override;
175+
void lookupValue(DeclName name, VisibleDeclConsumer &consumer);
178176

179177
/// Look up a type declaration by its Clang name.
180178
///
181179
/// Note that this method does no filtering. If it finds the type in a loaded
182180
/// module, it returns it. This is intended for use in reflection / debugging
183181
/// contexts where access is not a problem.
184182
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
185-
llvm::function_ref<void(TypeDecl *)> receiver) override;
183+
llvm::function_ref<void(TypeDecl *)> receiver);
186184

187185
/// Look up type a declaration synthesized by the Clang importer itself, using
188186
/// a "related entity kind" to determine which type it should be. For example,
@@ -195,7 +193,7 @@ class ClangImporter final : public ClangModuleLoader {
195193
void
196194
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
197195
StringRef relatedEntityKind,
198-
llvm::function_ref<void(TypeDecl *)> receiver) override;
196+
llvm::function_ref<void(TypeDecl *)> receiver);
199197

200198
/// Look for textually included declarations from the bridging header.
201199
///

branches/tensorflow/lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#include "swift/AST/ASTDemangler.h"
2323

2424
#include "swift/AST/ASTContext.h"
25-
#include "swift/AST/ClangModuleLoader.h"
2625
#include "swift/AST/Decl.h"
2726
#include "swift/AST/GenericSignature.h"
2827
#include "swift/AST/GenericSignatureBuilder.h"
2928
#include "swift/AST/Module.h"
3029
#include "swift/AST/NameLookup.h"
3130
#include "swift/AST/Type.h"
3231
#include "swift/AST/Types.h"
32+
#include "swift/ClangImporter/ClangImporter.h"
3333
#include "swift/Demangling/Demangler.h"
3434
#include "swift/Demangling/ManglingMacros.h"
3535
#include "llvm/ADT/StringSwitch.h"
@@ -1069,7 +1069,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10691069
ForeignModuleKind foreignKind,
10701070
Demangle::Node::Kind kind) {
10711071
// Check to see if we have an importer loaded.
1072-
auto importer = Ctx.getClangModuleLoader();
1072+
auto importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
10731073
if (!importer)
10741074
return nullptr;
10751075

branches/tensorflow/lib/AST/Type.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ bool TypeBase::isAnyClassReferenceType() {
161161
return getCanonicalType().isAnyClassReferenceType();
162162
}
163163

164-
bool CanType::isReferenceTypeImpl(CanType type, GenericSignature *sig,
165-
bool functionsCount) {
164+
bool CanType::isReferenceTypeImpl(CanType type, bool functionsCount) {
166165
switch (type->getKind()) {
167166
#define SUGARED_TYPE(id, parent) case TypeKind::id:
168167
#define TYPE(id, parent)
@@ -181,7 +180,7 @@ bool CanType::isReferenceTypeImpl(CanType type, GenericSignature *sig,
181180
// For Self types, recur on the underlying type.
182181
case TypeKind::DynamicSelf:
183182
return isReferenceTypeImpl(cast<DynamicSelfType>(type).getSelfType(),
184-
sig, functionsCount);
183+
functionsCount);
185184

186185
// Archetypes and existentials are only class references if class-bounded.
187186
case TypeKind::PrimaryArchetype:
@@ -232,14 +231,13 @@ bool CanType::isReferenceTypeImpl(CanType type, GenericSignature *sig,
232231

233232
case TypeKind::GenericTypeParam:
234233
case TypeKind::DependentMember:
235-
assert(sig && "dependent types can't answer reference semantics query");
236-
return sig->requiresClass(type);
234+
llvm_unreachable("Dependent types can't answer reference-semantics query");
237235
}
238236

239237
llvm_unreachable("Unhandled type kind!");
240238
}
241239

242-
/// Are variables of this type permitted to have
240+
/// hasOwnership - Are variables of this type permitted to have
243241
/// ownership attributes?
244242
///
245243
/// This includes:
@@ -248,8 +246,8 @@ bool CanType::isReferenceTypeImpl(CanType type, GenericSignature *sig,
248246
/// - existentials with class or class protocol bounds
249247
/// But not:
250248
/// - function types
251-
bool TypeBase::allowsOwnership(GenericSignature *sig) {
252-
return getCanonicalType().allowsOwnership(sig);
249+
bool TypeBase::allowsOwnership() {
250+
return getCanonicalType().isAnyClassReferenceType();
253251
}
254252

255253
ExistentialLayout::ExistentialLayout(ProtocolType *type) {

branches/tensorflow/lib/ClangImporter/DWARFImporter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
using namespace swift;
1717

18-
void DWARFImporterDelegate::anchor() {}
19-
2018
/// Represents a Clang module that was "imported" from debug info. Since all the
2119
/// loading of types is done on demand, this class is effectively empty.
2220
class DWARFModuleUnit final : public LoadedFile {

branches/tensorflow/lib/Parse/SyntaxParsingContext.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,10 @@ ParsedRawSyntaxNode SyntaxParsingContext::finalizeSourceFile() {
258258
Parts = Parts.drop_back();
259259

260260
for (auto RawNode : Parts) {
261-
if (RawNode.getKind() != SyntaxKind::CodeBlockItem) {
261+
if (RawNode.getKind() != SyntaxKind::CodeBlockItem)
262262
// FIXME: Skip toplevel garbage nodes for now. we shouldn't emit them in
263263
// the first place.
264-
if (RawNode.isRecorded())
265-
getSyntaxCreator().finalizeNode(RawNode.getOpaqueNode());
266264
continue;
267-
}
268265

269266
AllTopLevel.push_back(RawNode);
270267
}

branches/tensorflow/lib/Sema/TypeCheckAttr.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
133133
IGNORED_ATTR(DisfavoredOverload)
134134
IGNORED_ATTR(FunctionBuilder)
135135
IGNORED_ATTR(ProjectedValueProperty)
136-
IGNORED_ATTR(ReferenceOwnership)
137136
#undef IGNORED_ATTR
138137

139138
void visitAlignmentAttr(AlignmentAttr *attr) {
@@ -176,6 +175,10 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
176175
void visitConsumingAttr(ConsumingAttr *attr) { visitMutationAttr(attr); }
177176
void visitDynamicAttr(DynamicAttr *attr);
178177

178+
void visitReferenceOwnershipAttr(ReferenceOwnershipAttr *attr) {
179+
TC.checkReferenceOwnershipAttr(cast<VarDecl>(D), attr);
180+
}
181+
179182
void visitFinalAttr(FinalAttr *attr) {
180183
// Reject combining 'final' with 'open'.
181184
if (auto accessAttr = D->getAttrs().getAttribute<AccessControlAttr>()) {
@@ -2639,13 +2642,26 @@ void TypeChecker::checkDeclAttributes(Decl *D) {
26392642
}
26402643
}
26412644

2642-
Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
2645+
void TypeChecker::checkTypeModifyingDeclAttributes(VarDecl *var) {
2646+
if (!var->hasType())
2647+
return;
2648+
2649+
if (auto *attr = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
2650+
checkReferenceOwnershipAttr(var, attr);
2651+
}
2652+
2653+
void TypeChecker::checkReferenceOwnershipAttr(VarDecl *var,
26432654
ReferenceOwnershipAttr *attr) {
2644-
auto *dc = var->getDeclContext();
2655+
// Don't check ownership attribute if the declaration is already marked invalid.
2656+
if (var->isInvalid())
2657+
return;
26452658

2646-
// Don't check ownership attribute if the type is invalid.
2647-
if (attr->isInvalid() || type->is<ErrorType>())
2648-
return type;
2659+
Type type = var->getType();
2660+
Type interfaceType = var->getInterfaceType();
2661+
2662+
// Just stop if we've already processed this declaration.
2663+
if (type->is<ReferenceStorageType>())
2664+
return;
26492665

26502666
auto ownershipKind = attr->get();
26512667

@@ -2697,12 +2713,11 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
26972713
if (!underlyingType)
26982714
underlyingType = type;
26992715

2700-
auto *sig = var->getDeclContext()->getGenericSignatureOfContext();
2701-
if (!underlyingType->allowsOwnership(sig)) {
2716+
if (!underlyingType->allowsOwnership()) {
27022717
auto D = diag::invalid_ownership_type;
27032718

27042719
if (underlyingType->isExistentialType() ||
2705-
underlyingType->isTypeParameter()) {
2720+
underlyingType->is<ArchetypeType>()) {
27062721
// Suggest the possibility of adding a class bound.
27072722
D = diag::invalid_ownership_protocol_type;
27082723
}
@@ -2720,7 +2735,7 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
27202735
attr->setInvalid();
27212736
}
27222737

2723-
auto PDC = dyn_cast<ProtocolDecl>(dc);
2738+
auto PDC = dyn_cast<ProtocolDecl>((var->getDeclContext()));
27242739
if (PDC && !PDC->isObjC()) {
27252740
// Ownership does not make sense in protocols, except for "weak" on
27262741
// properties of Objective-C protocols.
@@ -2733,10 +2748,13 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
27332748
}
27342749

27352750
if (attr->isInvalid())
2736-
return type;
2751+
return;
27372752

27382753
// Change the type to the appropriate reference storage type.
2739-
return ReferenceStorageType::get(type, ownershipKind, Context);
2754+
var->setType(ReferenceStorageType::get(
2755+
type, ownershipKind, Context));
2756+
var->setInterfaceType(ReferenceStorageType::get(
2757+
interfaceType, ownershipKind, Context));
27402758
}
27412759

27422760
Optional<Diag<>>

branches/tensorflow/lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3501,7 +3501,9 @@ void bindFuncDeclToOperator(TypeChecker &TC, FuncDecl *FD) {
35013501
for (DeclContext *CurContext = FD->getLocalContext();
35023502
!isa<SourceFile>(CurContext);
35033503
CurContext = CurContext->getParent()) {
3504-
insertionLoc = CurContext->getAsDecl()->getStartLoc();
3504+
// Skip over non-decl contexts (e.g. closure expresssions)
3505+
if (auto *D = CurContext->getAsDecl())
3506+
insertionLoc = D->getStartLoc();
35053507
}
35063508
}
35073509

0 commit comments

Comments
 (0)