Skip to content

Commit 2836d9d

Browse files
authored
---
yaml --- r: 343518 b: refs/heads/master-rebranch c: 99c6521 h: refs/heads/master
1 parent 0233402 commit 2836d9d

File tree

71 files changed

+1164
-907
lines changed

Some content is hidden

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

71 files changed

+1164
-907
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 9612f447c1ad09783cf9dcc8ba325ae7858e8ecb
1458+
refs/heads/master-rebranch: 99c65211e6452692790779210759a5da29a83229
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/docs/ABI/Mangling.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ Types
551551
type ::= assoc-type-name 'Qz' // shortcut for 'Qyz'
552552
type ::= assoc-type-list 'QY' GENERIC-PARAM-INDEX // associated type at depth
553553
type ::= assoc-type-list 'QZ' // shortcut for 'QYz'
554+
555+
#if SWIFT_RUNTIME_VERSION >= 5.2
556+
type ::= type assoc-type-name 'Qx' // associated type relative to base `type`
557+
type ::= type assoc-type-list 'QX' // associated type relative to base `type`
558+
#endif
554559

555560
protocol-list ::= protocol '_' protocol*
556561
protocol-list ::= empty-list

branches/master-rebranch/include/swift/AST/ASTContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef SWIFT_AST_ASTCONTEXT_H
1818
#define SWIFT_AST_ASTCONTEXT_H
1919

20-
#include "swift/AST/ClangModuleLoader.h"
2120
#include "swift/AST/Evaluator.h"
2221
#include "swift/AST/GenericSignature.h"
2322
#include "swift/AST/Identifier.h"
@@ -32,6 +31,7 @@
3231
#include "llvm/ADT/MapVector.h"
3332
#include "llvm/ADT/PointerIntPair.h"
3433
#include "llvm/ADT/SetVector.h"
34+
#include "llvm/ADT/SmallPtrSet.h"
3535
#include "llvm/ADT/StringMap.h"
3636
#include "llvm/ADT/TinyPtrVector.h"
3737
#include "llvm/Support/Allocator.h"
@@ -49,10 +49,12 @@ namespace clang {
4949
}
5050

5151
namespace swift {
52+
class AbstractFunctionDecl;
5253
class ASTContext;
5354
enum class Associativity : unsigned char;
5455
class AvailabilityContext;
5556
class BoundGenericType;
57+
class ClangModuleLoader;
5658
class ClangNode;
5759
class ConcreteDeclRef;
5860
class ConstructorDecl;

branches/master-rebranch/include/swift/AST/Decl.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class alignas(1 << DeclAlignInBits) Decl {
543543
NumRequirementsInSignature : 16
544544
);
545545

546-
SWIFT_INLINE_BITFIELD(ClassDecl, NominalTypeDecl, 2+1+2+1+7+1+1+1+1,
546+
SWIFT_INLINE_BITFIELD(ClassDecl, NominalTypeDecl, 2+1+2+1+7+1+1+1+1+1+1,
547547
/// The stage of the inheritance circularity check for this class.
548548
Circularity : 2,
549549

@@ -557,7 +557,10 @@ class alignas(1 << DeclAlignInBits) Decl {
557557
HasForcedEmittedMembers : 1,
558558

559559
HasMissingDesignatedInitializers : 1,
560+
ComputedHasMissingDesignatedInitializers : 1,
561+
560562
HasMissingVTableEntries : 1,
563+
ComputedHasMissingVTableEntries : 1,
561564

562565
/// Whether instances of this class are incompatible
563566
/// with weak and unowned references.
@@ -3272,7 +3275,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32723275
llvm::PointerIntPair<MemberLookupTable *, 1, bool> LookupTable;
32733276

32743277
/// Prepare the lookup table to make it ready for lookups.
3275-
void prepareLookupTable(bool ignoreNewExtensions);
3278+
void prepareLookupTable();
32763279

32773280
/// True if the entries in \c LookupTable are complete--that is, if a
32783281
/// name is present, it contains all members with that name.
@@ -3378,24 +3381,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33783381
/// Retrieve the set of extensions of this type.
33793382
ExtensionRange getExtensions();
33803383

3381-
/// Make a member of this nominal type, or one of its extensions,
3382-
/// immediately visible in the lookup table.
3383-
///
3384-
/// A member of a nominal type or extension thereof will become
3385-
/// visible to name lookup as soon as it is added. However, if the
3386-
/// addition of a member is delayed---for example, because it's
3387-
/// being introduced in response to name lookup---this method can be
3388-
/// called to make it immediately visible.
3389-
void makeMemberVisible(ValueDecl *member);
3390-
33913384
/// Special-behaviour flags passed to lookupDirect()
33923385
enum class LookupDirectFlags {
3393-
/// Whether to avoid loading any new extension.
3394-
/// Used by the module loader to break recursion.
3395-
IgnoreNewExtensions = 1 << 0,
33963386
/// Whether to include @_implements members.
33973387
/// Used by conformance-checking to find special @_implements members.
3398-
IncludeAttrImplements = 1 << 1,
3388+
IncludeAttrImplements = 1 << 0,
33993389
};
34003390

34013391
/// Find all of the declarations with the given name within this nominal type
@@ -3879,6 +3869,7 @@ class ClassDecl final : public NominalTypeDecl {
38793869
bool hasMissingDesignatedInitializers() const;
38803870

38813871
void setHasMissingDesignatedInitializers(bool newValue = true) {
3872+
Bits.ClassDecl.ComputedHasMissingDesignatedInitializers = 1;
38823873
Bits.ClassDecl.HasMissingDesignatedInitializers = newValue;
38833874
}
38843875

@@ -3889,6 +3880,7 @@ class ClassDecl final : public NominalTypeDecl {
38893880
bool hasMissingVTableEntries() const;
38903881

38913882
void setHasMissingVTableEntries(bool newValue = true) {
3883+
Bits.ClassDecl.ComputedHasMissingVTableEntries = 1;
38923884
Bits.ClassDecl.HasMissingVTableEntries = newValue;
38933885
}
38943886

@@ -4195,6 +4187,14 @@ class ProtocolDecl final : public NominalTypeDecl {
41954187
/// a protocol having nested types (ObjC protocols).
41964188
llvm::TinyPtrVector<AssociatedTypeDecl *> getAssociatedTypeMembers() const;
41974189

4190+
/// Returns a protocol requirement with the given name, or nullptr if the
4191+
/// name has multiple overloads, or no overloads at all.
4192+
ValueDecl *getSingleRequirement(DeclName name) const;
4193+
4194+
/// Returns an associated type with the given name, or nullptr if one does
4195+
/// not exist.
4196+
AssociatedTypeDecl *getAssociatedType(Identifier name) const;
4197+
41984198
/// Walk this protocol and all of the protocols inherited by this protocol,
41994199
/// transitively, invoking the callback function for each protocol.
42004200
///
@@ -4338,7 +4338,7 @@ class ProtocolDecl final : public NominalTypeDecl {
43384338
/// with the Objective-C runtime.
43394339
StringRef getObjCRuntimeName(llvm::SmallVectorImpl<char> &buffer) const;
43404340

4341-
/// Create the generic parameters of this protocol if the haven't been
4341+
/// Create the generic parameters of this protocol if they haven't been
43424342
/// created yet.
43434343
void createGenericParamsIfMissing();
43444344

branches/master-rebranch/include/swift/ClangImporter/ClangImporter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class ClangModuleUnit;
5151
class ClangNode;
5252
class Decl;
5353
class DeclContext;
54+
class EnumDecl;
5455
class ImportDecl;
5556
class IRGenOptions;
5657
class LazyResolver;
5758
class ModuleDecl;
5859
class NominalTypeDecl;
60+
class StructDecl;
5961
class TypeDecl;
6062
class VisibleDeclConsumer;
6163
enum class SelectorSplitKind;
@@ -213,6 +215,9 @@ class ClangImporter final : public ClangModuleLoader {
213215
StringRef relatedEntityKind,
214216
llvm::function_ref<void(TypeDecl *)> receiver) override;
215217

218+
/// Look up the nested 'Code' enum for an error wrapper struct.
219+
EnumDecl *lookupErrorCodeEnum(const StructDecl *errorWrapper) const;
220+
216221
/// Look for textually included declarations from the bridging header.
217222
///
218223
/// \param filter returns true if the given clang decl/macro should be
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//===--- SILInstructionWorklist.h -------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
///
13+
/// \file
14+
///
15+
/// When visiting the instructions in a function/basic block, one often modifies
16+
/// the list of instructions to be visited. That fact introduces complexity in
17+
/// the form of ensuring that no effort is wasted moving items down in the list
18+
/// when an item is removed from it and also in the form of ensuring that no
19+
/// instructions which have been modified/deleted are visited.
20+
///
21+
/// The SILInstructionWorklist manages that complexity. It is responsible for
22+
/// ensuring that removing an instruction is not unnecessarily expensive and
23+
/// that only valid instructions are removed from the list.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#include "swift/SIL/SILInstruction.h"
28+
#include "swift/SIL/SILValue.h"
29+
#include "llvm/ADT/DenseMap.h"
30+
#include "llvm/ADT/SmallVector.h"
31+
32+
namespace swift {
33+
34+
/// Manages a list of instructions awaiting visitation.
35+
class SILInstructionWorklist final {
36+
llvm::SmallVector<SILInstruction *, 256> worklist;
37+
llvm::DenseMap<SILInstruction *, unsigned> worklistMap;
38+
StringRef loggingName;
39+
40+
void operator=(const SILInstructionWorklist &rhs) = delete;
41+
SILInstructionWorklist(const SILInstructionWorklist &worklist) = delete;
42+
43+
public:
44+
SILInstructionWorklist(const char *loggingName = "InstructionWorklist")
45+
: loggingName(loggingName) {}
46+
47+
/// Returns true if the worklist is empty.
48+
bool isEmpty() const { return worklist.empty(); }
49+
50+
/// Add the specified instruction to the worklist if it isn't already in it.
51+
void add(SILInstruction *instruction);
52+
53+
/// If the given ValueBase is a SILInstruction add it to the worklist.
54+
void addValue(ValueBase *value) {
55+
if (auto *instruction = value->getDefiningInstruction())
56+
add(instruction);
57+
}
58+
59+
/// Add the given list of instructions in reverse order to the worklist. This
60+
/// routine assumes that the worklist is empty and the given list has no
61+
/// duplicates.
62+
void addInitialGroup(ArrayRef<SILInstruction *> list);
63+
64+
// If instruction is in the worklist, remove it.
65+
void remove(SILInstruction *instruction) {
66+
auto iterator = worklistMap.find(instruction);
67+
if (iterator == worklistMap.end())
68+
return; // Not in worklist.
69+
70+
// Don't bother moving everything down, just null out the slot. We will
71+
// check before we process any instruction if it is null.
72+
worklist[iterator->second] = nullptr;
73+
worklistMap.erase(iterator);
74+
}
75+
76+
/// Remove the top element from the worklist.
77+
SILInstruction *removeOne() {
78+
SILInstruction *instruction = worklist.pop_back_val();
79+
worklistMap.erase(instruction);
80+
return instruction;
81+
}
82+
83+
/// When an instruction has been simplified, add all of its users to the
84+
/// worklist, since additional simplifications of its users may have been
85+
/// exposed.
86+
void addUsersToWorklist(ValueBase *instruction) {
87+
for (auto *use : instruction->getUses())
88+
add(use->getUser());
89+
}
90+
91+
void addUsersToWorklist(SILValue value) {
92+
for (auto *use : value->getUses())
93+
add(use->getUser());
94+
}
95+
96+
/// When an instruction has been simplified, add all of its users to the
97+
/// worklist, since additional simplifications of its users may have been
98+
/// exposed.
99+
void addUsersOfAllResultsToWorklist(SILInstruction *instruction) {
100+
for (auto result : instruction->getResults()) {
101+
addUsersToWorklist(result);
102+
}
103+
}
104+
105+
/// Check that the worklist is empty and nuke the backing store for the map if
106+
/// it is large.
107+
void zap() {
108+
assert(worklistMap.empty() && "Worklist empty, but the map is not?");
109+
110+
// Do an explicit clear, this shrinks the map if needed.
111+
worklistMap.clear();
112+
}
113+
};
114+
115+
} // end namespace swift

branches/master-rebranch/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/ASTContext.h"
1818
#include "ForeignRepresentationInfo.h"
1919
#include "SubstitutionMapStorage.h"
20+
#include "swift/AST/ClangModuleLoader.h"
2021
#include "swift/AST/ConcreteDeclRef.h"
2122
#include "swift/AST/DiagnosticEngine.h"
2223
#include "swift/AST/DiagnosticsSema.h"

branches/master-rebranch/lib/AST/ASTDemangler.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
8484
return nullptr;
8585

8686
auto name = Ctx.getIdentifier(node->getChild(1)->getText());
87-
auto results = proto->lookupDirect(name);
88-
if (results.size() != 1)
89-
return nullptr;
90-
91-
return dyn_cast<AssociatedTypeDecl>(results[0]);
87+
return proto->getAssociatedType(name);
9288
}
9389

9490
auto *DC = findDeclContext(node);
@@ -585,13 +581,8 @@ Type ASTBuilder::createDependentMemberType(StringRef member,
585581
if (!base->isTypeParameter())
586582
return Type();
587583

588-
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
589-
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
590-
for (auto member : protocol->lookupDirect(Ctx.getIdentifier(member),
591-
flags)) {
592-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member))
593-
return DependentMemberType::get(base, assocType);
594-
}
584+
if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
585+
return DependentMemberType::get(base, assocType);
595586

596587
return Type();
597588
}

branches/master-rebranch/lib/AST/ASTMangler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,22 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
10051005

10061006
case TypeKind::NestedArchetype: {
10071007
auto nestedType = cast<NestedArchetypeType>(tybase);
1008+
1009+
// Mangle associated types of opaque archetypes like dependent member
1010+
// types, so that they can be accurately demangled at runtime.
1011+
if (auto opaque =
1012+
dyn_cast<OpaqueTypeArchetypeType>(nestedType->getRoot())) {
1013+
if (tryMangleTypeSubstitution(nestedType))
1014+
return;
1015+
1016+
appendType(opaque);
1017+
bool isAssocTypeAtDepth = false;
1018+
appendAssocType(nestedType->getInterfaceType(), isAssocTypeAtDepth);
1019+
appendOperator(isAssocTypeAtDepth ? "QX" : "Qx");
1020+
addTypeSubstitution(nestedType);
1021+
return;
1022+
}
1023+
10081024
appendType(nestedType->getParent());
10091025
appendIdentifier(nestedType->getName().str());
10101026
appendOperator("Qa");

0 commit comments

Comments
 (0)