Skip to content

Commit 8e5753f

Browse files
authored
Merge pull request #2357 from swiftwasm/main
[pull] swiftwasm from main
2 parents 4b0d5e7 + bb705ce commit 8e5753f

39 files changed

+604
-273
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,7 @@ ERROR(rethrowing_function_type,none,
732732
"only function declarations may be marked 'rethrows'; "
733733
"did you mean 'throws'?", ())
734734
ERROR(async_or_throws_in_wrong_position,none,
735-
"%select{'throws'|'rethrows'|'async'}0 may only occur before '->'",
736-
(unsigned))
735+
"'%0' may only occur before '->'", (StringRef))
737736
ERROR(throw_in_function_type,none,
738737
"expected throwing specifier; did you mean 'throws'?", ())
739738
ERROR(expected_type_before_arrow,none,
@@ -748,6 +747,8 @@ ERROR(expected_dynamic_func_attr,none,
748747
ERROR(async_after_throws,none,
749748
"'async' must precede %select{'throws'|'rethrows'}0", (bool))
750749
ERROR(async_init,none, "initializer cannot be marked 'async'", ())
750+
ERROR(duplicate_effects_specifier,none,
751+
"'%0' has already been specified", (StringRef))
751752

752753
// Enum Types
753754
ERROR(expected_expr_enum_case_raw_value,PointsToFirstBadToken,

include/swift/AST/FileUnit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class FileUnit : public DeclContext {
183183
/// The order of the results is not guaranteed to be meaningful.
184184
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {}
185185

186+
virtual void
187+
getExportedPrespecializations(SmallVectorImpl<Decl *> &results) const {}
188+
186189
/// Finds top-level decls in this file filtered by their attributes.
187190
///
188191
/// This does a simple local lookup, not recursively looking through imports.

include/swift/AST/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ class ModuleDecl : public DeclContext, public TypeDecl {
632632
/// The order of the results is not guaranteed to be meaningful.
633633
void getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const;
634634

635+
void getExportedPrespecializations(SmallVectorImpl<Decl *> &results) const;
636+
635637
/// Finds top-level decls of this module filtered by their attributes.
636638
///
637639
/// This does a simple local lookup, not recursively looking through imports.

include/swift/Basic/Fingerprint.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,53 +60,51 @@ namespace swift {
6060
class Fingerprint final {
6161
public:
6262
/// The size (in bytes) of the raw value of all fingerprints.
63-
///
64-
/// This constant's value is justified by a static assertion in the
65-
/// corresponding cpp file.
6663
constexpr static size_t DIGEST_LENGTH = 32;
6764

65+
using Core = std::pair<uint64_t, uint64_t>;
6866
private:
69-
std::string Core;
67+
Core core;
7068

7169
public:
70+
/// Creates a fingerprint value from a pair of 64-bit integers.
71+
explicit Fingerprint(Fingerprint::Core value) : core(value) {}
72+
7273
/// Creates a fingerprint value from the given input string that is known to
7374
/// be a 32-byte hash value.
7475
///
7576
/// In +asserts builds, strings that violate this invariant will crash. If a
7677
/// fingerprint value is needed to represent an "invalid" state, use a
7778
/// vocabulary type like \c Optional<Fingerprint> instead.
78-
explicit Fingerprint(std::string value) : Core(std::move(value)) {
79-
assert(Core.size() == Fingerprint::DIGEST_LENGTH &&
80-
"Only supports 32-byte hash values!");
81-
}
79+
static Fingerprint fromString(llvm::StringRef value);
8280

8381
/// Creates a fingerprint value from the given input string literal.
8482
template <std::size_t N>
8583
explicit Fingerprint(const char (&literal)[N])
86-
: Core{literal, N-1} {
84+
: Fingerprint{Fingerprint::fromString({literal, N-1}).core} {
8785
static_assert(N == Fingerprint::DIGEST_LENGTH + 1,
8886
"String literal must be 32 bytes in length!");
8987
}
9088

9189
/// Creates a fingerprint value by consuming the given \c MD5Result from LLVM.
9290
explicit Fingerprint(llvm::MD5::MD5Result &&MD5Value)
93-
: Core{MD5Value.digest().str()} {}
91+
: core{MD5Value.words()} {}
9492

9593
public:
9694
/// Retrieve the raw underlying bytes of this fingerprint.
97-
llvm::StringRef getRawValue() const { return Core; }
95+
llvm::SmallString<Fingerprint::DIGEST_LENGTH> getRawValue() const;
9896

9997
public:
10098
friend bool operator==(const Fingerprint &lhs, const Fingerprint &rhs) {
101-
return lhs.Core == rhs.Core;
99+
return lhs.core == rhs.core;
102100
}
103101

104102
friend bool operator!=(const Fingerprint &lhs, const Fingerprint &rhs) {
105-
return lhs.Core != rhs.Core;
103+
return lhs.core != rhs.core;
106104
}
107105

108106
friend llvm::hash_code hash_value(const Fingerprint &fp) {
109-
return llvm::hash_value(fp.Core);
107+
return llvm::hash_value(fp.core);
110108
}
111109

112110
public:
@@ -115,7 +113,7 @@ class Fingerprint final {
115113
/// This fingerprint is a perfectly fine value for an MD5 hash, but it is
116114
/// completely arbitrary.
117115
static Fingerprint ZERO() {
118-
return Fingerprint("00000000000000000000000000000000");
116+
return Fingerprint(Fingerprint::Core{0, 0});
119117
}
120118

121119
private:
@@ -124,7 +122,7 @@ class Fingerprint final {
124122
///
125123
/// Very well, LLVM. A default value you shall have.
126124
friend class llvm::yaml::IO;
127-
Fingerprint() : Core(DIGEST_LENGTH, '0') {}
125+
Fingerprint() : core{Fingerprint::Core{0, 0}} {}
128126
};
129127

130128
void simple_display(llvm::raw_ostream &out, const Fingerprint &fp);

include/swift/IDE/CodeCompletion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ enum class CompletionKind {
549549
AccessorBeginning,
550550
AttributeBegin,
551551
AttributeDeclParen,
552+
EffectsSpecifier,
552553
PoundAvailablePlatform,
553554
CallArg,
554555
LabeledTrailingClosure,

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class CodeCompletionCallbacks {
181181
/// @available.
182182
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) {};
183183

184+
/// Complete 'async' and 'throws' at effects specifier position.
185+
virtual void completeEffectsSpecifier(bool hasAsync, bool hasThrows) {};
186+
184187
/// Complete within a precedence group decl or after a colon in an
185188
/// operator decl.
186189
virtual void completeInPrecedenceGroup(SyntaxKind SK) {};

include/swift/Parse/Parser.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,12 @@ class Parser {
13531353
///
13541354
/// \param rethrows If non-NULL, will also parse the 'rethrows' keyword in
13551355
/// lieu of 'throws'.
1356-
void parseAsyncThrows(
1357-
SourceLoc existingArrowLoc, SourceLoc &asyncLoc, SourceLoc &throwsLoc,
1358-
bool *rethrows);
1356+
ParserStatus parseEffectsSpecifiers(SourceLoc existingArrowLoc,
1357+
SourceLoc &asyncLoc, SourceLoc &throwsLoc,
1358+
bool *rethrows);
1359+
1360+
/// Returns 'true' if \p T is considered effects specifier.
1361+
bool isEffectsSpecifier(const Token &T);
13591362

13601363
//===--------------------------------------------------------------------===//
13611364
// Pattern Parsing
@@ -1433,6 +1436,15 @@ class Parser {
14331436
/// \endverbatim
14341437
bool canParseBaseTypeForQualifiedDeclName();
14351438

1439+
/// Returns true if the current token is '->' or effects specifiers followed
1440+
/// by '->'.
1441+
///
1442+
/// e.g.
1443+
/// throws -> // true
1444+
/// async throws -> // true
1445+
/// throws { // false
1446+
bool isAtFunctionTypeArrow();
1447+
14361448
//===--------------------------------------------------------------------===//
14371449
// Expression Parsing
14381450
ParserResult<Expr> parseExpr(Diag<> ID) {
@@ -1554,8 +1566,9 @@ class Parser {
15541566
/// \param explicitResultType The explicit result type, if specified.
15551567
/// \param inLoc The location of the 'in' keyword, if present.
15561568
///
1557-
/// \returns true if an error occurred, false otherwise.
1558-
bool parseClosureSignatureIfPresent(
1569+
/// \returns ParserStatus error if an error occurred. Success if no signature
1570+
/// is present or succssfully parsed.
1571+
ParserStatus parseClosureSignatureIfPresent(
15591572
SourceRange &bracketRange,
15601573
SmallVectorImpl<CaptureListEntry> &captureList,
15611574
VarDecl *&capturedSelfParamDecl,

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ class SerializedASTFile final : public LoadedFile {
398398

399399
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
400400

401+
virtual void getExportedPrespecializations(
402+
SmallVectorImpl<Decl *> &results) const override;
403+
401404
virtual void
402405
getTopLevelDeclsWhereAttributesMatch(
403406
SmallVectorImpl<Decl*> &Results,

lib/AST/FineGrainedDependencyFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool Deserializer::readFineGrainedDependencyGraph(SourceFileDepGraph &g,
232232
if (node == nullptr)
233233
llvm::report_fatal_error("Unexpected FINGERPRINT_NODE record");
234234

235-
node->setFingerprint(Fingerprint{BlobData.str()});
235+
node->setFingerprint(Fingerprint::fromString(BlobData));
236236
break;
237237
}
238238

lib/AST/Module.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
792792
FORWARD(getTopLevelDecls, (Results));
793793
}
794794

795+
void ModuleDecl::getExportedPrespecializations(
796+
SmallVectorImpl<Decl *> &Results) const {
797+
FORWARD(getExportedPrespecializations, (Results));
798+
}
799+
795800
void ModuleDecl::getTopLevelDeclsWhereAttributesMatch(
796801
SmallVectorImpl<Decl*> &Results,
797802
llvm::function_ref<bool(DeclAttributes)> matchAttributes) const {

0 commit comments

Comments
 (0)