Skip to content

Commit b8683f8

Browse files
Merge pull request swiftlang#4553 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 5ea676a + 8b19bae commit b8683f8

File tree

49 files changed

+834
-166
lines changed

Some content is hidden

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

49 files changed

+834
-166
lines changed

cmake/caches/Windows-arm64.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ set(LLVM_TOOL_LLVM_SHLIB_BUILD NO CACHE BOOL "")
6666
# Avoid swig dependency for lldb
6767
set(LLDB_ALLOW_STATIC_BINDINGS YES CACHE BOOL "")
6868
set(LLDB_USE_STATIC_BINDINGS YES CACHE BOOL "")
69+
set(LLDB_ENABLE_PYTHON YES CACHE BOOL "")
70+
set(LLDB_EMBED_PYTHON_HOME NO CACHE BOOL "")
6971

7072
# This requires perl which may not be available on Windows
7173
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")

cmake/caches/Windows-x86_64.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ set(LLVM_TOOL_LLVM_SHLIB_BUILD NO CACHE BOOL "")
6666
# Avoid swig dependency for lldb
6767
set(LLDB_ALLOW_STATIC_BINDINGS YES CACHE BOOL "")
6868
set(LLDB_USE_STATIC_BINDINGS YES CACHE BOOL "")
69+
set(LLDB_ENABLE_PYTHON YES CACHE BOOL "")
70+
set(LLDB_EMBED_PYTHON_HOME NO CACHE BOOL "")
6971

7072
# This requires perl which may not be available on Windows
7173
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")

include/swift/AST/ExtInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ class ASTExtInfoBuilder {
358358

359359
constexpr Representation getRepresentation() const {
360360
unsigned rawRep = bits & RepresentationMask;
361-
assert(rawRep <= unsigned(Representation::Last) &&
362-
"unexpected SIL representation");
363361
return Representation(rawRep);
364362
}
365363

include/swift/Basic/SourceManager.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/Basic/FileSystem.h"
1717
#include "swift/Basic/SourceLoc.h"
1818
#include "clang/Basic/FileManager.h"
19+
#include "llvm/ADT/DenseSet.h"
1920
#include "llvm/ADT/Optional.h"
2021
#include "llvm/Support/SourceMgr.h"
2122
#include <map>
@@ -55,6 +56,10 @@ class SourceManager {
5556
/// reusing compilation.
5657
llvm::DenseMap<SourceRange, SourceRange> ReplacedRanges;
5758

59+
/// The starting source locations of regex literals written in source. This
60+
/// is an unfortunate hack needed to allow for correct re-lexing.
61+
llvm::DenseSet<SourceLoc> RegexLiteralStartLocs;
62+
5863
std::map<const char *, VirtualFile> VirtualFiles;
5964
mutable std::pair<const char *, const VirtualFile*> CachedVFile = {nullptr, nullptr};
6065

@@ -107,6 +112,17 @@ class SourceManager {
107112
ReplacedRanges[Orig] = New;
108113
}
109114

115+
/// Record the starting source location of a regex literal.
116+
void recordRegexLiteralStartLoc(SourceLoc loc) {
117+
RegexLiteralStartLocs.insert(loc);
118+
}
119+
120+
/// Checks whether a given source location is for the start of a regex
121+
/// literal.
122+
bool isRegexLiteralStart(SourceLoc loc) const {
123+
return RegexLiteralStartLocs.contains(loc);
124+
}
125+
110126
/// Returns true if \c LHS is before \c RHS in the source buffer.
111127
bool isBeforeInBuffer(SourceLoc LHS, SourceLoc RHS) const {
112128
return LHS.Value.getPointer() < RHS.Value.getPointer();

include/swift/IDE/CodeCompletionResultType.h

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
namespace swift {
2222
namespace ide {
2323

24+
enum class CustomAttributeKind : uint8_t {
25+
/// A type that can be used as a property wrapper.
26+
PropertyWrapper = 1 << 0,
27+
/// A type that can be used as a result builder.
28+
ResultBuilder = 1 << 1,
29+
/// A type that can be used as a global actor.
30+
GlobalActor = 1 << 2,
31+
};
32+
2433
/// The expected contextual type(s) for code-completion.
2534
class ExpectedTypeContext {
2635
/// Possible types of the code completion expression.
@@ -37,6 +46,11 @@ class ExpectedTypeContext {
3746
bool IsImplicitSingleExpressionReturn = false;
3847
bool PreferNonVoid = false;
3948

49+
/// If not empty, \c PossibleTypes are ignored and types that have an
50+
/// attribute kind that is contained in this list will be reported as
51+
/// 'Convertible'. All other types are related as 'Invalid'.
52+
OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
53+
4054
public:
4155
ExpectedTypeContext() = default;
4256

@@ -82,6 +96,15 @@ class ExpectedTypeContext {
8296
void setPreferNonVoid(bool PreferNonVoid) {
8397
this->PreferNonVoid = PreferNonVoid;
8498
}
99+
100+
OptionSet<CustomAttributeKind> getExpectedCustomAttributeKinds() const {
101+
return ExpectedCustomAttributeKinds;
102+
}
103+
104+
void setExpectedCustomAttributeKinds(
105+
OptionSet<CustomAttributeKind> ExpectedAttributeKinds) {
106+
this->ExpectedCustomAttributeKinds = ExpectedAttributeKinds;
107+
}
85108
};
86109

87110
/// Describes the relationship between the type of the completion results and
@@ -174,6 +197,9 @@ class USRBasedTypeContext {
174197

175198
SmallVector<ContextualType, 4> ContextualTypes;
176199

200+
/// See \c ExpectedTypeContext::ExpectedAttributeKinds.
201+
OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
202+
177203
public:
178204
/// Create a USR-based equivalent of the \p TypeContext.
179205
USRBasedTypeContext(const ExpectedTypeContext *TypeContext,
@@ -203,10 +229,15 @@ class USRBasedType {
203229
/// declared in the same module that the type was defined.
204230
ArrayRef<const USRBasedType *> Supertypes;
205231

232+
/// The kinds of attributes this type can be used as.
233+
OptionSet<CustomAttributeKind> CustomAttributeKinds;
234+
206235
/// Memberwise initializer. \p USR and \p Supertypes need to be allocated in
207236
/// the same arena as this \c USRBasedType.
208-
USRBasedType(StringRef USR, ArrayRef<const USRBasedType *> Supertypes)
209-
: USR(USR), Supertypes(Supertypes) {}
237+
USRBasedType(StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
238+
OptionSet<CustomAttributeKind> CustomAttributeKinds)
239+
: USR(USR), Supertypes(Supertypes),
240+
CustomAttributeKinds(CustomAttributeKinds) {}
210241

211242
/// Implementation of \c typeRelation. \p VisistedTypes keeps track which
212243
/// types have already been visited.
@@ -225,13 +256,18 @@ class USRBasedType {
225256

226257
/// Construct as \c USRBasedType from a USR and its supertypes. This method
227258
/// takes care of copying \p USR and \p Supertypes to \p Arena.
228-
static const USRBasedType *fromUSR(StringRef USR,
229-
ArrayRef<const USRBasedType *> Supertypes,
230-
USRBasedTypeArena &Arena);
259+
static const USRBasedType *
260+
fromUSR(StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
261+
OptionSet<CustomAttributeKind> CustomAttributeKinds,
262+
USRBasedTypeArena &Arena);
231263

232264
StringRef getUSR() const { return USR; }
233265
ArrayRef<const USRBasedType *> getSupertypes() const { return Supertypes; }
234266

267+
OptionSet<CustomAttributeKind> getCustomAttributeKinds() const {
268+
return CustomAttributeKinds;
269+
}
270+
235271
/// Compute the relation of \c ResultType when to this contextual type.
236272
CodeCompletionResultTypeRelation
237273
typeRelation(const USRBasedType *ResultType,

include/swift/IDE/CompletionLookup.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,16 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
240240

241241
void setIsStaticMetatype(bool value) { IsStaticMetatype = value; }
242242

243-
void setExpectedTypes(ArrayRef<Type> Types,
244-
bool isImplicitSingleExpressionReturn,
245-
bool preferNonVoid = false) {
243+
void setExpectedTypes(
244+
ArrayRef<Type> Types, bool isImplicitSingleExpressionReturn,
245+
bool preferNonVoid = false,
246+
OptionSet<CustomAttributeKind> expectedCustomAttributeKinds = {}) {
246247
expectedTypeContext.setIsImplicitSingleExpressionReturn(
247248
isImplicitSingleExpressionReturn);
248249
expectedTypeContext.setPreferNonVoid(preferNonVoid);
249250
expectedTypeContext.setPossibleTypes(Types);
251+
expectedTypeContext.setExpectedCustomAttributeKinds(
252+
expectedCustomAttributeKinds);
250253
}
251254

252255
void setIdealExpectedType(Type Ty) { expectedTypeContext.setIdealType(Ty); }

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ class ReflectionSectionIteratorBase
100100
: OriginalSize(Size), Cur(Cur), Size(Size), Name(Name) {
101101
if (Size != 0) {
102102
auto NextRecord = this->operator*();
103+
if (!NextRecord) {
104+
// NULL record pointer, don't attempt to proceed. Setting size to 0 will
105+
// make this iterator compare equal to the end iterator.
106+
this->Size = 0;
107+
return;
108+
}
103109
auto NextSize = Self::getCurrentRecordSize(NextRecord);
104110
if (NextSize > Size) {
105111
std::cerr << "!!! Reflection section too small to contain first record\n" << std::endl;
@@ -109,7 +115,9 @@ class ReflectionSectionIteratorBase
109115
<< ", size of first record: "
110116
<< NextSize
111117
<< std::endl;
112-
abort();
118+
// Set this iterator equal to the end. This section is effectively
119+
// empty.
120+
this->Size = 0;
113121
}
114122
}
115123
}
@@ -149,14 +157,18 @@ class ReflectionSectionIteratorBase
149157
std::cerr << std::hex << std::setw(2) << (int)p[i] << " ";
150158
}
151159
std::cerr << std::endl;
152-
abort();
160+
Size = 0; // Set this iterator equal to the end.
153161
}
154162
}
155163

156164
return asImpl();
157165
}
158166

159167
bool operator==(const Self &other) const {
168+
// Size = 0 means we're at the end even if Cur doesn't match. This allows
169+
// iterators that encounter an incorrect size to safely end iteration.
170+
if (Size == 0 && other.Size == 0)
171+
return true;
160172
return Cur == other.Cur && Size == other.Size;
161173
}
162174

lib/AST/ASTContext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/DiagnosticsSema.h"
2525
#include "swift/AST/DistributedDecl.h"
2626
#include "swift/AST/ExistentialLayout.h"
27+
#include "swift/AST/ExtInfo.h"
2728
#include "swift/AST/FileUnit.h"
2829
#include "swift/AST/ForeignAsyncConvention.h"
2930
#include "swift/AST/ForeignErrorConvention.h"
@@ -3683,6 +3684,16 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
36833684
auto properties = getFunctionRecursiveProperties(params, result, globalActor);
36843685
auto arena = getArena(properties);
36853686

3687+
if (info.hasValue()) {
3688+
// Canonicalize all thin functions to be escaping (to keep compatibility
3689+
// with generic parameters). Note that one can pass SIL-level representation
3690+
// here, so we need additional check for maximum non-SIL value.
3691+
Representation rep = info.getValue().getRepresentation();
3692+
if (rep <= FunctionTypeRepresentation::Last &&
3693+
isThinRepresentation(rep))
3694+
info = info->withNoEscape(false);
3695+
}
3696+
36863697
llvm::FoldingSetNodeID id;
36873698
FunctionType::Profile(id, params, result, info);
36883699

@@ -4100,6 +4111,10 @@ CanSILFunctionType SILFunctionType::get(
41004111
ext = ext.intoBuilder().withClangFunctionType(nullptr).build();
41014112
}
41024113

4114+
// Canonicalize all thin functions to be escaping (to keep compatibility
4115+
// with generic parameters)
4116+
if (isThinRepresentation(ext.getRepresentation()))
4117+
ext = ext.intoBuilder().withNoEscape(false);
41034118

41044119
llvm::FoldingSetNodeID id;
41054120
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee, params,

lib/IDE/CodeCompletion.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,35 @@ void CodeCompletionCallbacksImpl::doneParsing() {
17011701

17021702
case CompletionKind::AttributeBegin: {
17031703
Lookup.getAttributeDeclCompletions(IsInSil, AttTargetDK);
1704+
OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
1705+
if (AttTargetDK) {
1706+
switch (*AttTargetDK) {
1707+
case DeclKind::Var:
1708+
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
1709+
LLVM_FALLTHROUGH;
1710+
case DeclKind::Param:
1711+
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
1712+
ExpectedCustomAttributeKinds |= CustomAttributeKind::PropertyWrapper;
1713+
break;
1714+
case DeclKind::Func:
1715+
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
1716+
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
1717+
break;
1718+
default:
1719+
break;
1720+
}
1721+
}
1722+
if (!ExpectedCustomAttributeKinds) {
1723+
// If we don't know on which decl kind we are completing, suggest all
1724+
// attribute kinds.
1725+
ExpectedCustomAttributeKinds |= CustomAttributeKind::PropertyWrapper;
1726+
ExpectedCustomAttributeKinds |= CustomAttributeKind::ResultBuilder;
1727+
ExpectedCustomAttributeKinds |= CustomAttributeKind::GlobalActor;
1728+
}
1729+
Lookup.setExpectedTypes(/*Types=*/{},
1730+
/*isImplicitSingleExpressionReturn=*/false,
1731+
/*preferNonVoid=*/false,
1732+
ExpectedCustomAttributeKinds);
17041733

17051734
// TypeName at attribute position after '@'.
17061735
// - VarDecl: Property Wrappers.

lib/IDE/CodeCompletionCache.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
103103
///
104104
/// This should be incremented any time we commit a change to the format of the
105105
/// cached results. This isn't expected to change very often.
106-
static constexpr uint32_t onDiskCompletionCacheVersion = 6; // Store completion item result types in the cache
106+
static constexpr uint32_t onDiskCompletionCacheVersion = 7; // Store whether a type can be used as attribute
107107

108108
/// Deserializes CodeCompletionResults from \p in and stores them in \p V.
109109
/// \see writeCacheModule.
@@ -193,8 +193,9 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
193193
auto supertypeIndex = read32le(p);
194194
supertypes.push_back(getType(supertypeIndex));
195195
}
196-
const USRBasedType *res =
197-
USRBasedType::fromUSR(usr, supertypes, V.USRTypeArena);
196+
auto customAttributeKinds = OptionSet<CustomAttributeKind, uint8_t>(*p++);
197+
const USRBasedType *res = USRBasedType::fromUSR(
198+
usr, supertypes, customAttributeKinds, V.USRTypeArena);
198199
knownTypes[index] = res;
199200
return res;
200201
};
@@ -381,6 +382,9 @@ static void writeCachedModule(llvm::raw_ostream &out,
381382
for (auto supertypeIndex : supertypeIndicies) {
382383
LE.write(static_cast<uint32_t>(supertypeIndex));
383384
}
385+
OptionSet<CustomAttributeKind, uint8_t> customAttributeKinds =
386+
type->getCustomAttributeKinds();
387+
LE.write(static_cast<uint8_t>(customAttributeKinds.toRaw()));
384388
knownTypes[type] = size;
385389
return static_cast<uint32_t>(size);
386390
};

0 commit comments

Comments
 (0)