Skip to content

Commit c17f753

Browse files
Merge pull request #5488 from swiftwasm/main
[pull] swiftwasm from main
2 parents fb5cb05 + 3efdc5a commit c17f753

File tree

101 files changed

+1864
-492
lines changed

Some content is hidden

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

101 files changed

+1864
-492
lines changed

include/swift/AST/Attr.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,25 +1551,28 @@ class SpecializeAttr final
15511551
/// The @_implements attribute, which treats a decl as the implementation for
15521552
/// some named protocol requirement (but otherwise not-visible by that name).
15531553
class ImplementsAttr : public DeclAttribute {
1554-
TypeExpr *ProtocolType;
1554+
TypeRepr *TyR;
15551555
DeclName MemberName;
15561556
DeclNameLoc MemberNameLoc;
15571557

1558-
public:
15591558
ImplementsAttr(SourceLoc atLoc, SourceRange Range,
1560-
TypeExpr *ProtocolType,
1559+
TypeRepr *TyR,
15611560
DeclName MemberName,
15621561
DeclNameLoc MemberNameLoc);
15631562

1563+
public:
15641564
static ImplementsAttr *create(ASTContext &Ctx, SourceLoc atLoc,
15651565
SourceRange Range,
1566-
TypeExpr *ProtocolType,
1566+
TypeRepr *TyR,
15671567
DeclName MemberName,
15681568
DeclNameLoc MemberNameLoc);
15691569

1570-
void setProtocolType(Type ty);
1571-
Type getProtocolType() const;
1572-
TypeRepr *getProtocolTypeRepr() const;
1570+
static ImplementsAttr *create(DeclContext *DC,
1571+
ProtocolDecl *Proto,
1572+
DeclName MemberName);
1573+
1574+
ProtocolDecl *getProtocol(DeclContext *dc) const;
1575+
TypeRepr *getProtocolTypeRepr() const { return TyR; }
15731576

15741577
DeclName getMemberName() const { return MemberName; }
15751578
DeclNameLoc getMemberNameLoc() const { return MemberNameLoc; }

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ ERROR(error_empty_package_name,none,
195195
ERROR(error_stdlib_not_found,Fatal,
196196
"unable to load standard library for target '%0'", (StringRef))
197197
ERROR(error_module_alias_invalid_format,none,
198-
"invalid module alias format \"%0\"; make sure to use the format '-module-alias alias_name=underlying_name'", (StringRef))
198+
"invalid module alias format \"%0\"; make sure to use the format '-module-alias alias_name=real_name'", (StringRef))
199199
ERROR(error_module_alias_forbidden_name,none,
200200
"invalid module alias \"%0\"; make sure the alias differs from the module name, module ABI name, module link name, and a standard library name", (StringRef))
201201
ERROR(error_module_alias_duplicate,none,
202-
"duplicate module alias; the name \"%0\" is already used for a module alias or an underlying name", (StringRef))
202+
"duplicate module alias; the name \"%0\" is already used for an alias or a real name", (StringRef))
203203

204204
ERROR(error_unable_to_load_supplementary_output_file_map, none,
205205
"unable to load supplementary output file map '%0': %1",

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3711,7 +3711,7 @@ class MaterializePackExpr final : public Expr {
37113711
}
37123712

37133713
SourceLoc getEndLoc() const {
3714-
return ElementLoc.isInvalid() ? ElementLoc : FromExpr->getEndLoc();
3714+
return ElementLoc.isValid() ? ElementLoc : FromExpr->getEndLoc();
37153715
}
37163716

37173717
static bool classof(const Expr *E) {

include/swift/AST/NameLookupRequests.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/FileUnit.h"
2323
#include "swift/AST/Identifier.h"
2424
#include "swift/AST/NameLookup.h"
25+
#include "swift/AST/TypeOrExtensionDecl.h"
2526
#include "swift/Basic/Statistic.h"
2627
#include "llvm/ADT/Hashing.h"
2728
#include "llvm/ADT/TinyPtrVector.h"
@@ -37,6 +38,7 @@ class GenericContext;
3738
class GenericParamList;
3839
class LookupResult;
3940
enum class NLKind;
41+
class PotentialMacroExpansions;
4042
class SourceLoc;
4143
class TypeAliasDecl;
4244
class TypeDecl;
@@ -889,6 +891,46 @@ class HasDynamicCallableAttributeRequest
889891
bool isCached() const { return true; }
890892
};
891893

894+
/// Determine the potential macro expansions for a given type or extension
895+
/// context.
896+
class PotentialMacroExpansionsInContextRequest
897+
: public SimpleRequest<
898+
PotentialMacroExpansionsInContextRequest,
899+
PotentialMacroExpansions(TypeOrExtensionDecl),
900+
RequestFlags::Cached> {
901+
public:
902+
using SimpleRequest::SimpleRequest;
903+
904+
private:
905+
friend SimpleRequest;
906+
907+
// Evaluation.
908+
PotentialMacroExpansions evaluate(
909+
Evaluator &evaluator, TypeOrExtensionDecl container) const;
910+
911+
public:
912+
bool isCached() const { return true; }
913+
};
914+
915+
/// Resolves the protocol referenced by an @_implements attribute.
916+
class ImplementsAttrProtocolRequest
917+
: public SimpleRequest<ImplementsAttrProtocolRequest,
918+
ProtocolDecl *(const ImplementsAttr *, DeclContext *),
919+
RequestFlags::Cached> {
920+
public:
921+
using SimpleRequest::SimpleRequest;
922+
923+
private:
924+
friend SimpleRequest;
925+
926+
// Evaluation.
927+
ProtocolDecl *evaluate(Evaluator &evaluator, const ImplementsAttr *attr,
928+
DeclContext *dc) const;
929+
930+
public:
931+
bool isCached() const { return true; }
932+
};
933+
892934
#define SWIFT_TYPEID_ZONE NameLookup
893935
#define SWIFT_TYPEID_HEADER "swift/AST/NameLookupTypeIDZone.def"
894936
#include "swift/Basic/DefineTypeIDZone.h"

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ SWIFT_REQUEST(NameLookup, HasDynamicMemberLookupAttributeRequest,
107107
bool(NominalTypeDecl *), Cached, NoLocationInfo)
108108
SWIFT_REQUEST(NameLookup, HasDynamicCallableAttributeRequest,
109109
bool(NominalTypeDecl *), Cached, NoLocationInfo)
110+
SWIFT_REQUEST(NameLookup, PotentialMacroExpansionsInContextRequest,
111+
PotentialMacroExpansions(TypeOrExtension), Cached, NoLocationInfo)
112+
SWIFT_REQUEST(NameLookup, ImplementsAttrProtocolRequest,
113+
ProtocolDecl *(const ImplementsAttr *, DeclContext *), Cached, NoLocationInfo)
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
//===--- PotentialMacroExpansions.h -----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 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+
// This file defines a structure (\c PotentialMacroExpansions) to track
14+
// potential macro expansions within a given context.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
#ifndef SWIFT_AST_POTENTIAL_MACRO_EXPANSIONS_H
18+
#define SWIFT_AST_POTENTIAL_MACRO_EXPANSIONS_H
19+
20+
#include "swift/AST/Identifier.h"
21+
#include "llvm/ADT/PointerIntPair.h"
22+
#include "llvm/ADT/SmallPtrSet.h"
23+
24+
namespace swift {
25+
26+
/// Describes the potential macro expansions within a given type or
27+
/// extension context.
28+
class PotentialMacroExpansions {
29+
enum {
30+
/// Whether there are any expanded macros.
31+
AnyExpandedMacros = 0x01,
32+
33+
/// Whether any of the expanded macros introduces arbitrary names.
34+
IntroducesArbitraryNames = 0x02,
35+
};
36+
37+
using NameSet = llvm::SmallPtrSet<DeclName, 4>;
38+
39+
/// Storage for the set of potential macro expansions.
40+
llvm::PointerIntPair<NameSet *, 2, unsigned> Storage;
41+
42+
/// Retrieve a pointer to the name set if there is one.
43+
const NameSet *getIntroducedNamesIfAvailable() const {
44+
return Storage.getPointer();
45+
}
46+
47+
/// Get or create a nam
48+
NameSet &getOrCreateIntroducedNames() {
49+
if (auto nameSet = Storage.getPointer())
50+
return *nameSet;
51+
52+
// Allocate a new set of introduced names.
53+
auto nameSet = new NameSet();
54+
Storage.setPointer(nameSet);
55+
return *nameSet;
56+
}
57+
58+
public:
59+
PotentialMacroExpansions() : Storage() { }
60+
61+
PotentialMacroExpansions(const PotentialMacroExpansions &other)
62+
: Storage(nullptr, other.Storage.getInt())
63+
{
64+
if (auto otherNameSet = other.getIntroducedNamesIfAvailable()) {
65+
Storage.setPointer(new NameSet(*otherNameSet));
66+
}
67+
}
68+
69+
PotentialMacroExpansions(PotentialMacroExpansions &&other)
70+
: Storage(other.Storage)
71+
{
72+
other.Storage.setPointer(nullptr);
73+
}
74+
75+
PotentialMacroExpansions &operator=(const PotentialMacroExpansions &other) {
76+
PotentialMacroExpansions tmp(other);
77+
swap(tmp, *this);
78+
return *this;
79+
}
80+
81+
PotentialMacroExpansions &operator=(PotentialMacroExpansions &&other) {
82+
if (&other != this) {
83+
Storage = other.Storage;
84+
other.Storage.setPointer(nullptr);
85+
}
86+
return *this;
87+
}
88+
89+
~PotentialMacroExpansions() {
90+
delete getIntroducedNamesIfAvailable();
91+
}
92+
93+
/// Whether there are any expanded macros in this context.
94+
explicit operator bool() const { return hasAnyExpandedMacro(); }
95+
96+
/// Whether there are any expanded macros in this context.
97+
bool hasAnyExpandedMacro() const {
98+
return Storage.getInt() & AnyExpandedMacros;
99+
}
100+
101+
/// Note that we have expanded a macro.
102+
void noteExpandedMacro() {
103+
Storage.setInt(Storage.getInt() | AnyExpandedMacros);
104+
}
105+
106+
/// Whether any expanded macro introduces arbitrary names.
107+
bool introducesArbitraryNames() const {
108+
return Storage.getInt() & IntroducesArbitraryNames;
109+
}
110+
111+
/// Note that a macro expanded here introduced arbitrary names.
112+
void noteIntroducesArbitraryNames() {
113+
Storage.setInt(Storage.getInt() | IntroducesArbitraryNames);
114+
}
115+
116+
/// Add a new introduced macro name.
117+
void addIntroducedMacroName(DeclName name) {
118+
getOrCreateIntroducedNames().insert(name.getBaseName());
119+
}
120+
121+
/// Determine whether one should expand any macros in this context because
122+
/// they could introduce a declaration with the given name.
123+
bool shouldExpandForName(DeclName name) const {
124+
// If any macro produces arbitraty names, we need to expand it.
125+
if (introducesArbitraryNames())
126+
return true;
127+
128+
auto introducedNames = getIntroducedNamesIfAvailable();
129+
if (!introducedNames)
130+
return false;
131+
132+
return introducedNames->count(name.getBaseName());
133+
}
134+
135+
friend bool operator==(const PotentialMacroExpansions &lhs,
136+
const PotentialMacroExpansions &rhs) {
137+
// Check has-any-expanded-macro and introduces-arbitrary-names together.
138+
if (lhs.Storage.getInt() != rhs.Storage.getInt())
139+
return false;
140+
141+
// If they introduced arbitrary names, ignore the name sets... they are
142+
// the same.
143+
if (lhs.introducesArbitraryNames())
144+
return true;
145+
146+
// Both expanded macros and did not introduce arbitrary names, so we need
147+
// to check the actual names.
148+
auto lhsIntroducedNames = lhs.getIntroducedNamesIfAvailable();
149+
auto rhsIntroducedNames = rhs.getIntroducedNamesIfAvailable();
150+
151+
auto lhsIntroducedNamesCount =
152+
lhsIntroducedNames ? lhsIntroducedNames->size() : 0;
153+
auto rhsIntroducedNamesCount =
154+
rhsIntroducedNames ? rhsIntroducedNames->size() : 0;
155+
if (lhsIntroducedNamesCount != rhsIntroducedNamesCount)
156+
return false;
157+
158+
// Check whether both are empty.
159+
if (lhsIntroducedNamesCount == 0)
160+
return true;
161+
162+
// Make sure all of the names of one are in the other.
163+
for (auto lhsName : *lhsIntroducedNames) {
164+
if (rhsIntroducedNames->count(lhsName) == 0)
165+
return false;
166+
}
167+
168+
return true;
169+
}
170+
171+
friend bool operator!=(const PotentialMacroExpansions &lhs,
172+
const PotentialMacroExpansions &rhs) {
173+
return !(lhs == rhs);
174+
}
175+
176+
friend void swap(
177+
PotentialMacroExpansions &lhs, PotentialMacroExpansions &rhs) {
178+
auto tmpStorage = lhs.Storage;
179+
lhs.Storage = rhs.Storage;
180+
rhs.Storage = tmpStorage;
181+
}
182+
};
183+
184+
}
185+
186+
#endif // SWIFT_AST_POTENTIAL_MACRO_EXPANSIONS_H

include/swift/AST/TypeOrExtensionDecl.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
#include "swift/AST/TypeAlignments.h"
2222
#include "llvm/ADT/PointerUnion.h"
2323

24+
namespace llvm {
25+
class raw_ostream;
26+
}
27+
2428
namespace swift {
2529

30+
class SourceLoc;
2631
class DeclContext;
2732
class IterableDeclContext;
2833

@@ -51,11 +56,23 @@ struct TypeOrExtensionDecl {
5156
bool isNull() const;
5257
explicit operator bool() const { return !isNull(); }
5358

54-
bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; }
55-
bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; }
56-
bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; }
59+
friend bool operator==(TypeOrExtensionDecl lhs, TypeOrExtensionDecl rhs) {
60+
return lhs.Decl == rhs.Decl;
61+
}
62+
friend bool operator!=(TypeOrExtensionDecl lhs, TypeOrExtensionDecl rhs) {
63+
return lhs.Decl != rhs.Decl;
64+
}
65+
friend bool operator<(TypeOrExtensionDecl lhs, TypeOrExtensionDecl rhs) {
66+
return lhs.Decl < rhs.Decl;
67+
}
68+
friend llvm::hash_code hash_value(TypeOrExtensionDecl decl) {
69+
return llvm::hash_value(decl.getAsDecl());
70+
}
5771
};
5872

73+
void simple_display(llvm::raw_ostream &out, TypeOrExtensionDecl container);
74+
SourceLoc extractNearestSourceLoc(TypeOrExtensionDecl container);
75+
5976
} // end namespace swift
6077

6178
#endif

include/swift/AST/Types.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6414,7 +6414,7 @@ class PackArchetypeType final
64146414
LayoutConstraint Layout);
64156415

64166416
// Returns the reduced shape type for this pack archetype.
6417-
CanType getReducedShape() const;
6417+
CanType getReducedShape();
64186418

64196419
static bool classof(const TypeBase *T) {
64206420
return T->getKind() == TypeKind::PackArchetype;
@@ -7098,16 +7098,6 @@ inline bool TypeBase::isTypeParameter() {
70987098
return t->is<GenericTypeParamType>();
70997099
}
71007100

7101-
inline bool TypeBase::isParameterPack() {
7102-
Type t(this);
7103-
7104-
while (auto *memberTy = t->getAs<DependentMemberType>())
7105-
t = memberTy->getBase();
7106-
7107-
return t->is<GenericTypeParamType>() &&
7108-
t->castTo<GenericTypeParamType>()->isParameterPack();
7109-
}
7110-
71117101
// TODO: This will become redundant once InOutType is removed.
71127102
inline bool TypeBase::isMaterializable() {
71137103
return !(hasLValueType() || is<InOutType>());

include/swift/Basic/Features.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ UPCOMING_FEATURE(ExistentialAny, 335, 6)
116116
UPCOMING_FEATURE(ImportObjcForwardDeclarations, 384, 6)
117117

118118
EXPERIMENTAL_FEATURE(StaticAssert, false)
119-
EXPERIMENTAL_FEATURE(VariadicGenerics, false)
120119
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
121120
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
122121
EXPERIMENTAL_FEATURE(CodeItemMacros, true)

0 commit comments

Comments
 (0)