-
Notifications
You must be signed in to change notification settings - Fork 10.5k
AsyncSequence and protocol conformance rethrows #35224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b7e579
a23038a
ea8d396
db778e7
9096c48
ae676a8
faa1da7
df70e94
d8cef33
0bf5969
f3f7b4f
c0b9d39
de8ddbe
8e5b1dd
92229b6
e8c4cd0
019d8ad
10feb16
d0f2e06
3faaf3c
2c8e6b1
51fec5b
d682168
7431ec4
8aa204b
307630f
0763e2d
0d940e7
6a640a2
0f2422d
ac18c22
21ce9b7
48d4bb5
a0f6236
d4d9249
b25ccab
1821182
b186a7d
e07ad11
dafe88e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3870,6 +3870,66 @@ enum class KnownDerivableProtocolKind : uint8_t { | |
Actor, | ||
}; | ||
|
||
class ProtocolRethrowsRequirementList { | ||
public: | ||
typedef std::pair<Type, ValueDecl *> Entry; | ||
|
||
private: | ||
ArrayRef<Entry> entries; | ||
|
||
public: | ||
ProtocolRethrowsRequirementList(ArrayRef<Entry> entries) : entries(entries) {} | ||
ProtocolRethrowsRequirementList() : entries() {} | ||
|
||
typedef const Entry *const_iterator; | ||
typedef const_iterator iterator; | ||
|
||
const_iterator begin() const { return entries.begin(); } | ||
const_iterator end() const { return entries.end(); } | ||
|
||
size_t size() const { return entries.size(); } | ||
|
||
void print(raw_ostream &OS) const; | ||
|
||
SWIFT_DEBUG_DUMP; | ||
|
||
friend bool operator==(const ProtocolRethrowsRequirementList &lhs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I landed some changes that mean request results no longer have to overload == or hash_value(), so you can remove these if you want |
||
const ProtocolRethrowsRequirementList &rhs) { | ||
if (lhs.size() != rhs.size()) { | ||
return false; | ||
} | ||
auto lhsIter = lhs.begin(); | ||
auto rhsIter = rhs.begin(); | ||
while (lhsIter != lhs.end() && rhsIter != rhs.end()) { | ||
if (lhsIter->first->isEqual(rhsIter->first)) { | ||
return false; | ||
} | ||
if (lhsIter->second != rhsIter->second) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
friend bool operator!=(const ProtocolRethrowsRequirementList &lhs, | ||
const ProtocolRethrowsRequirementList &rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
friend llvm::hash_code hash_value( | ||
const ProtocolRethrowsRequirementList &list) { | ||
return llvm::hash_combine(list.size()); // it is good enought for | ||
// llvm::hash_code hash; | ||
// for (auto entry : list) { | ||
// hash = llvm::hash_combine(hash, entry.first->getCanonicalType()); | ||
// hash = llvm::hash_combine(hash, entry.second); | ||
// } | ||
// return hash; | ||
} | ||
}; | ||
|
||
void simple_display(raw_ostream &out, const ProtocolRethrowsRequirementList reqs); | ||
|
||
/// ProtocolDecl - A declaration of a protocol, for example: | ||
/// | ||
/// protocol Drawable { | ||
|
@@ -4051,6 +4111,9 @@ class ProtocolDecl final : public NominalTypeDecl { | |
/// contain 'Self' in 'parameter' or 'other' position. | ||
bool existentialTypeSupported() const; | ||
|
||
ProtocolRethrowsRequirementList getRethrowingRequirements() const; | ||
bool isRethrowingProtocol() const; | ||
|
||
private: | ||
void computeKnownProtocolKind() const; | ||
|
||
|
@@ -5460,6 +5523,23 @@ class ImportAsMemberStatus { | |
} | ||
}; | ||
|
||
enum class FunctionRethrowingKind : uint8_t { | ||
/// The function is not throwing | ||
None, | ||
|
||
/// The function rethrows by closure | ||
ByClosure, | ||
|
||
/// The function rethrows by conformance | ||
ByConformance, | ||
|
||
/// The function throws | ||
Throws, | ||
|
||
/// The function throwing determinate is invalid | ||
Invalid | ||
}; | ||
|
||
/// Base class for function-like declarations. | ||
class AbstractFunctionDecl : public GenericContext, public ValueDecl { | ||
friend class NeedsNewVTableEntryRequest; | ||
|
@@ -5663,6 +5743,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl { | |
/// Returns true if the function body throws. | ||
bool hasThrows() const { return Bits.AbstractFunctionDecl.Throws; } | ||
|
||
FunctionRethrowingKind getRethrowingKind() const; | ||
|
||
// FIXME: Hack that provides names with keyword arguments for accessors. | ||
DeclName getEffectiveFullName() const; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2981,6 +2981,8 @@ ERROR(override_rethrows_with_non_rethrows,none, | |
"be 'rethrows'", (bool)) | ||
ERROR(rethrows_without_throwing_parameter,none, | ||
"'rethrows' function must take a throwing function argument", ()) | ||
ERROR(rethrows_attr_on_non_protocol,none, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary because you annotated the attribute with OnProtocol in Attrs.def There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so that means the other code:
should change to this?
|
||
"@rethrows may only be used on 'protocol' declarations", ()) | ||
|
||
ERROR(autoclosure_function_type,none, | ||
"@autoclosure attribute only applies to function types", | ||
|
@@ -4052,6 +4054,8 @@ NOTE(because_rethrows_argument_throws,none, | |
NOTE(because_rethrows_default_argument_throws,none, | ||
"call is to 'rethrows' function, but a defaulted argument function" | ||
" can throw", ()) | ||
NOTE(because_rethrows_default_conformance_throws,none, | ||
"call is to 'rethrows' function, but a conformance has a throwing witness", ()) | ||
|
||
ERROR(throwing_call_in_nonthrowing_autoclosure,none, | ||
"call can throw, but it is executed in a non-throwing " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's API-stable to remove, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm good point, yea this is not API stable to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm so the previous annotation btw marks regular
rethrows
API stable to remove, isn't that wrong?