Skip to content

Commit afa5a88

Browse files
committed
AST: Add AnyFunctionType::hasEffect()
1 parent dcd3c6f commit afa5a88

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class TypeAliasDecl;
7676
class TypeDecl;
7777
class NominalTypeDecl;
7878
class GenericTypeDecl;
79+
enum class EffectKind : uint8_t;
7980
class EnumDecl;
8081
class EnumElementDecl;
8182
class SILFunctionType;
@@ -3159,6 +3160,8 @@ class AnyFunctionType : public TypeBase {
31593160

31603161
bool isThrowing() const { return getExtInfo().isThrowing(); }
31613162

3163+
bool hasEffect(EffectKind kind) const;
3164+
31623165
bool isDifferentiable() const { return getExtInfo().isDifferentiable(); }
31633166
DifferentiabilityKind getDifferentiabilityKind() const {
31643167
return getExtInfo().getDifferentiabilityKind();

lib/AST/Effects.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@
2020
#include "swift/AST/Decl.h"
2121
#include "swift/AST/ProtocolConformanceRef.h"
2222
#include "swift/AST/Type.h"
23+
#include "swift/AST/Types.h"
2324
#include "swift/AST/TypeCheckRequests.h"
2425
#include "llvm/ADT/ArrayRef.h"
2526
#include "llvm/Support/raw_ostream.h"
2627

2728
using namespace swift;
2829

30+
bool AnyFunctionType::hasEffect(EffectKind kind) const {
31+
switch (kind) {
32+
case EffectKind::Throws: return getExtInfo().isThrowing();
33+
case EffectKind::Async: return getExtInfo().isAsync();
34+
}
35+
llvm_unreachable("Bad effect kind");
36+
}
37+
2938
void swift::simple_display(llvm::raw_ostream &out, const EffectKind kind) {
3039
switch (kind) {
3140
case EffectKind::Throws: out << "throws"; return;

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ static bool hasFunctionParameterWithEffect(EffectKind kind, Type type) {
3535

3636
// Only consider function types with this effect.
3737
if (auto fnType = type->getAs<AnyFunctionType>()) {
38-
auto extInfo = fnType->getExtInfo();
39-
switch (kind) {
40-
case EffectKind::Throws: return extInfo.isThrowing();
41-
case EffectKind::Async: return extInfo.isAsync();
42-
}
43-
llvm_unreachable("Bad effect kind");
38+
return fnType->hasEffect(kind);
4439
}
4540

4641
// Look through tuples.

0 commit comments

Comments
 (0)