Skip to content

Commit 39e43d7

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents a355af2 + 16fdf88 commit 39e43d7

File tree

295 files changed

+15437
-9541
lines changed

Some content is hidden

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

295 files changed

+15437
-9541
lines changed

include/swift/ABI/Metadata.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,12 @@ struct TargetProtocolConformanceDescriptor final
23402340
return TypeRef.getTypeDescriptor(getTypeKind());
23412341
}
23422342

2343+
const TargetContextDescriptor<Runtime> **_getTypeDescriptorLocation() const {
2344+
if (getTypeKind() != TypeReferenceKind::IndirectTypeDescriptor)
2345+
return nullptr;
2346+
return TypeRef.IndirectTypeDescriptor.get();
2347+
}
2348+
23432349
/// Retrieve the context of a retroactive conformance.
23442350
const TargetContextDescriptor<Runtime> *getRetroactiveContext() const {
23452351
if (!Flags.isRetroactive()) return nullptr;

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,6 @@ class ASTContext final {
829829
/// \param IDC The context whose member decls should be lazily parsed.
830830
void parseMembers(IterableDeclContext *IDC);
831831

832-
/// Use the lazy parsers associated with the context to check whether the decl
833-
/// context has been parsed.
834-
bool hasUnparsedMembers(const IterableDeclContext *IDC) const;
835-
836832
/// Get the lazy function data for the given generic context.
837833
///
838834
/// \param lazyLoader If non-null, the lazy loader to use when creating the

include/swift/AST/ASTScope.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ class ASTScopeImpl {
177177
void addChild(ASTScopeImpl *child, ASTContext &);
178178
std::vector<ASTScopeImpl *> rescueYoungestChildren(unsigned count);
179179

180-
virtual std::vector<ASTScopeImpl *> rescueScopesToReuse();
181-
virtual void addReusedScopes(ArrayRef<ASTScopeImpl *>);
180+
/// When reexpanding, do we always create a new body?
181+
virtual NullablePtr<ASTScopeImpl> getParentOfRescuedScopes();
182+
std::vector<ASTScopeImpl *> rescueScopesToReuse();
183+
void addReusedScopes(ArrayRef<ASTScopeImpl *>);
182184

183185
private:
184186
void removeChildren();
@@ -201,7 +203,8 @@ class ASTScopeImpl {
201203
/// InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
202204
/// getSourceRange with the starting point. But we might be asked to lookup an
203205
/// identifer within one of them. So, find the real source range of them here.
204-
/// /// FIXME: Alter how these are parsed so getSourceRange is enough.
206+
///
207+
/// FIXME: Alter how these are parsed so getSourceRange is enough.
205208
SourceRange getEffectiveSourceRange(ASTNode) const;
206209

207210
void cacheSourceRangeOfMeAndDescendants(bool omitAssertions = false) const;
@@ -303,6 +306,12 @@ class ASTScopeImpl {
303306
virtual void beCurrent();
304307
virtual bool isCurrent() const;
305308

309+
/// Some scopes can be expanded lazily.
310+
/// Such scopes must: not change their source ranges after expansion, and
311+
/// their expansion must return an insertion point outside themselves.
312+
virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion();
313+
virtual SourceRange sourceRangeForDeferredExpansion() const;
314+
306315
public:
307316
// Some nodes (VarDecls and Accessors) are created directly from
308317
// pattern scope code and should neither be deferred nor should
@@ -548,6 +557,10 @@ class Portion {
548557

549558
virtual void beCurrent(IterableTypeScope *) const;
550559
virtual bool isCurrent(const IterableTypeScope *) const;
560+
virtual NullablePtr<ASTScopeImpl>
561+
insertionPointForDeferredExpansion(IterableTypeScope *) const;
562+
virtual SourceRange
563+
sourceRangeForDeferredExpansion(const IterableTypeScope *) const;
551564
};
552565

553566
// For the whole Decl scope of a GenericType or an Extension
@@ -623,6 +636,10 @@ class IterableTypeBodyPortion final
623636

624637
void beCurrent(IterableTypeScope *) const override;
625638
bool isCurrent(const IterableTypeScope *) const override;
639+
NullablePtr<ASTScopeImpl>
640+
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
641+
SourceRange
642+
sourceRangeForDeferredExpansion(const IterableTypeScope *) const override;
626643
};
627644

628645
/// GenericType or Extension scope
@@ -702,7 +719,6 @@ class IterableTypeScope : public GenericTypeScope {
702719
/// Because of \c parseDelayedDecl members can get added after the tree is
703720
/// constructed, and they can be out of order. Detect this happening by
704721
/// remembering the member count.
705-
/// TODO: unify with \c numberOfDeclsAlreadySeen
706722
unsigned memberCount = 0;
707723

708724
public:
@@ -721,6 +737,8 @@ class IterableTypeScope : public GenericTypeScope {
721737
public:
722738
void makeBodyCurrent();
723739
bool isBodyCurrent() const;
740+
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
741+
SourceRange sourceRangeForDeferredExpansion() const override;
724742
};
725743

726744
class NominalTypeScope final : public IterableTypeScope {
@@ -958,8 +976,7 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
958976
Decl *getDecl() const { return decl; }
959977
static bool isAMethod(const AbstractFunctionDecl *);
960978

961-
std::vector<ASTScopeImpl *> rescueScopesToReuse() override;
962-
void addReusedScopes(ArrayRef<ASTScopeImpl *>) override;
979+
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
963980

964981
protected:
965982
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
@@ -1122,7 +1139,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
11221139
SourceRange
11231140
getChildlessSourceRange(bool omitAssertions = false) const override;
11241141

1125-
static bool isHandledSpecially(const ASTNode n);
11261142
NullablePtr<const void> getReferrent() const override;
11271143

11281144
protected:
@@ -1372,8 +1388,7 @@ class TopLevelCodeScope final : public ASTScopeImpl {
13721388
Decl *getDecl() const { return decl; }
13731389
NullablePtr<const void> getReferrent() const override;
13741390

1375-
std::vector<ASTScopeImpl *> rescueScopesToReuse() override;
1376-
void addReusedScopes(ArrayRef<ASTScopeImpl *>) override;
1391+
NullablePtr<ASTScopeImpl> getParentOfRescuedScopes() override;
13771392
};
13781393

13791394
/// The \c _@specialize attribute.

include/swift/AST/Attr.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,7 @@ DECL_ATTR(_restatedObjCConformance, RestatedObjCConformance,
348348
LongAttribute | RejectByParser |
349349
NotSerialized, 70)
350350
// NOTE: 71 is unused
351-
SIMPLE_DECL_ATTR(_implicitly_unwrapped_optional, ImplicitlyUnwrappedOptional,
352-
OnFunc | OnAccessor | OnVar | OnParam | OnSubscript | OnConstructor |
353-
RejectByParser,
354-
72)
351+
// NOTE: 72 is unused
355352
DECL_ATTR(_optimize, Optimize,
356353
OnAbstractFunction | OnSubscript | OnVar |
357354
UserInaccessible,

include/swift/AST/ClangModuleLoader.h

Lines changed: 23 additions & 10 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,22 +68,23 @@ 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
///
6577
/// \param name The name we're searching for.
66-
virtual void lookupValue(DeclName name, VisibleDeclConsumer &consumer) {}
78+
virtual void lookupValue(DeclName name, VisibleDeclConsumer &consumer) = 0;
6779

6880
/// Look up a type declaration by its Clang name.
6981
///
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,
74-
llvm::function_ref<void(TypeDecl *)> receiver) {}
85+
virtual void
86+
lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
87+
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
7588

7689
/// Look up type a declaration synthesized by the Clang importer itself, using
7790
/// a "related entity kind" to determine which type it should be. For example,
@@ -82,11 +95,11 @@ class ClangModuleLoader : public ModuleLoader {
8295
/// module, it returns it. This is intended for use in reflection / debugging
8396
/// contexts where access is not a problem.
8497
virtual void
85-
lookupRelatedEntity(StringRef clangName, StringRef relatedEntityKind,
86-
llvm::function_ref<void(TypeDecl *)> receiver) {}
98+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
99+
StringRef relatedEntityKind,
100+
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
87101
};
88102

89103
} // namespace swift
90104

91105
#endif // LLVM_SWIFT_AST_CLANG_MODULE_LOADER_H
92-

include/swift/AST/Decl.h

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,16 @@ class alignas(1 << DeclAlignInBits) Decl {
456456
IsTransparentComputed : 1
457457
);
458458

459-
SWIFT_INLINE_BITFIELD(ConstructorDecl, AbstractFunctionDecl, 3+2+1,
459+
SWIFT_INLINE_BITFIELD(ConstructorDecl, AbstractFunctionDecl, 3+1+1,
460460
/// The body initialization kind (+1), or zero if not yet computed.
461461
///
462462
/// This value is cached but is not serialized, because it is a property
463463
/// of the definition of the constructor that is useful only to semantic
464464
/// analysis and SIL generation.
465465
ComputedBodyInitKind : 3,
466466

467-
/// The failability of this initializer, which is an OptionalTypeKind.
468-
Failability : 2,
467+
/// Whether this constructor can fail, by building an Optional type.
468+
Failable : 1,
469469

470470
/// Whether this initializer is a stub placed into a subclass to
471471
/// catch invalid delegations to a designated initializer not
@@ -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.
@@ -2401,12 +2412,20 @@ class ValueDecl : public Decl {
24012412
/// Whether this declaration is 'final'. A final class can't be subclassed,
24022413
/// a final class member can't be overriden.
24032414
unsigned isFinal : 1;
2415+
2416+
/// Whether the "isIUO" bit" has been computed yet.
2417+
unsigned isIUOComputed : 1;
2418+
2419+
/// Whether this declaration produces an implicitly unwrapped
2420+
/// optional result.
2421+
unsigned isIUO : 1;
24042422
} LazySemanticInfo = { };
24052423

24062424
friend class OverriddenDeclsRequest;
24072425
friend class IsObjCRequest;
24082426
friend class IsFinalRequest;
24092427
friend class IsDynamicRequest;
2428+
friend class IsImplicitlyUnwrappedOptionalRequest;
24102429

24112430
protected:
24122431
ValueDecl(DeclKind K,
@@ -2675,6 +2694,21 @@ class ValueDecl : public Decl {
26752694
/// Returns true if this decl can be found by id-style dynamic lookup.
26762695
bool canBeAccessedByDynamicLookup() const;
26772696

2697+
/// Returns true if this declaration has an implicitly unwrapped optional
2698+
/// result. The precise meaning depends on the declaration kind:
2699+
/// - for properties, the value is IUO
2700+
/// - for subscripts, the element type is IUO
2701+
/// - for functions, the result type is IUO
2702+
/// - for constructors, the failability kind is IUO
2703+
bool isImplicitlyUnwrappedOptional() const;
2704+
2705+
/// Should only be set on imported and deserialized declarations; parsed
2706+
/// declarations compute this lazily via a request.
2707+
void setImplicitlyUnwrappedOptional(bool isIUO) {
2708+
LazySemanticInfo.isIUOComputed = 1;
2709+
LazySemanticInfo.isIUO = isIUO;
2710+
}
2711+
26782712
/// Returns the protocol requirements that this decl conforms to.
26792713
ArrayRef<ValueDecl *>
26802714
getSatisfiedProtocolRequirements(bool Sorted = false) const;
@@ -3187,19 +3221,6 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
31873221

31883222
class MemberLookupTable;
31893223
class ConformanceLookupTable;
3190-
3191-
/// Kinds of optional types.
3192-
enum OptionalTypeKind : unsigned {
3193-
/// The type is not an optional type.
3194-
OTK_None = 0,
3195-
3196-
/// The type is Optional<T>.
3197-
OTK_Optional,
3198-
3199-
/// The type is ImplicitlyUnwrappedOptional<T>.
3200-
OTK_ImplicitlyUnwrappedOptional
3201-
};
3202-
enum { NumOptionalTypeKinds = 2 };
32033224

32043225
// Kinds of pointer types.
32053226
enum PointerTypeKind : unsigned {
@@ -5913,7 +5934,7 @@ class OperatorDecl;
59135934
enum class SelfAccessKind : uint8_t {
59145935
NonMutating,
59155936
Mutating,
5916-
__Consuming,
5937+
Consuming,
59175938
};
59185939

59195940
/// Diagnostic printing of \c SelfAccessKind.
@@ -6016,7 +6037,7 @@ class FuncDecl : public AbstractFunctionDecl {
60166037
return getSelfAccessKind() == SelfAccessKind::NonMutating;
60176038
}
60186039
bool isConsuming() const {
6019-
return getSelfAccessKind() == SelfAccessKind::__Consuming;
6040+
return getSelfAccessKind() == SelfAccessKind::Consuming;
60206041
}
60216042

60226043
SelfAccessKind getSelfAccessKind() const;
@@ -6484,7 +6505,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
64846505

64856506
public:
64866507
ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
6487-
OptionalTypeKind Failability, SourceLoc FailabilityLoc,
6508+
bool Failable, SourceLoc FailabilityLoc,
64886509
bool Throws, SourceLoc ThrowsLoc,
64896510
ParameterList *BodyParams,
64906511
GenericParamList *GenericParams,
@@ -6584,9 +6605,9 @@ class ConstructorDecl : public AbstractFunctionDecl {
65846605
llvm_unreachable("bad CtorInitializerKind");
65856606
}
65866607

6587-
/// Determine the failability of the initializer.
6588-
OptionalTypeKind getFailability() const {
6589-
return static_cast<OptionalTypeKind>(Bits.ConstructorDecl.Failability);
6608+
/// Determine if this is a failable initializer.
6609+
bool isFailable() const {
6610+
return Bits.ConstructorDecl.Failable;
65906611
}
65916612

65926613
/// Retrieve the location of the '!' or '?' in a failable initializer.

0 commit comments

Comments
 (0)