@@ -6839,6 +6839,7 @@ void simple_display(llvm::raw_ostream &out, BodyAndFingerprint value);
6839
6839
/// Base class for function-like declarations.
6840
6840
class AbstractFunctionDecl : public GenericContext, public ValueDecl {
6841
6841
friend class NeedsNewVTableEntryRequest;
6842
+ friend class ThrownTypeRequest;
6842
6843
6843
6844
public:
6844
6845
/// records the kind of SILGen-synthesized body this decl represents
@@ -6950,6 +6951,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
6950
6951
/// Location of the 'throws' token.
6951
6952
SourceLoc ThrowsLoc;
6952
6953
6954
+ /// The error type that is being thrown.
6955
+ TypeLoc ThrownType;
6956
+
6953
6957
struct {
6954
6958
unsigned NeedsNewVTableEntryComputed : 1;
6955
6959
unsigned NeedsNewVTableEntry : 1;
@@ -6958,12 +6962,13 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
6958
6962
AbstractFunctionDecl(DeclKind Kind, DeclContext *Parent, DeclName Name,
6959
6963
SourceLoc NameLoc, bool Async, SourceLoc AsyncLoc,
6960
6964
bool Throws, SourceLoc ThrowsLoc,
6965
+ TypeLoc ThrownTy,
6961
6966
bool HasImplicitSelfDecl,
6962
6967
GenericParamList *GenericParams)
6963
6968
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent,
6964
6969
GenericParams),
6965
6970
ValueDecl(Kind, Parent, Name, NameLoc), BodyAndFP(), AsyncLoc(AsyncLoc),
6966
- ThrowsLoc(ThrowsLoc) {
6971
+ ThrowsLoc(ThrowsLoc), ThrownType(ThrownTy) {
6967
6972
setBodyKind(BodyKind::None);
6968
6973
Bits.AbstractFunctionDecl.HasImplicitSelfDecl = HasImplicitSelfDecl;
6969
6974
Bits.AbstractFunctionDecl.Overridden = false;
@@ -7069,6 +7074,21 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
7069
7074
/// Returns true if the function body throws.
7070
7075
bool hasThrows() const { return Bits.AbstractFunctionDecl.Throws; }
7071
7076
7077
+ /// Retrieves the type representation for the thrown type.
7078
+ TypeRepr *getThrownTypeRepr() const {
7079
+ return ThrownType.getTypeRepr();
7080
+ }
7081
+
7082
+ /// Retrieves the thrown interface type.
7083
+ Type getThrownInterfaceType() const;
7084
+
7085
+ /// Retrieve the "effective" thrown interface type, or llvm::None if
7086
+ /// this function cannot throw.
7087
+ ///
7088
+ /// Functions with untyped throws will produce "any Error", functions that
7089
+ /// cannot throw or are specified to throw "Never" will return llvm::None.
7090
+ llvm::Optional<Type> getEffectiveThrownInterfaceType() const;
7091
+
7072
7092
/// Returns if the function throws or is async.
7073
7093
bool hasEffect(EffectKind kind) const;
7074
7094
@@ -7441,12 +7461,13 @@ class FuncDecl : public AbstractFunctionDecl {
7441
7461
DeclName Name, SourceLoc NameLoc,
7442
7462
bool Async, SourceLoc AsyncLoc,
7443
7463
bool Throws, SourceLoc ThrowsLoc,
7464
+ TypeLoc ThrownTy,
7444
7465
bool HasImplicitSelfDecl,
7445
7466
GenericParamList *GenericParams, DeclContext *Parent)
7446
7467
: AbstractFunctionDecl(Kind, Parent,
7447
7468
Name, NameLoc,
7448
7469
Async, AsyncLoc,
7449
- Throws, ThrowsLoc,
7470
+ Throws, ThrowsLoc, ThrownTy,
7450
7471
HasImplicitSelfDecl, GenericParams),
7451
7472
StaticLoc(StaticLoc), FuncLoc(FuncLoc) {
7452
7473
assert(!Name.getBaseName().isSpecial());
@@ -7471,6 +7492,7 @@ class FuncDecl : public AbstractFunctionDecl {
7471
7492
DeclName Name, SourceLoc NameLoc,
7472
7493
bool Async, SourceLoc AsyncLoc,
7473
7494
bool Throws, SourceLoc ThrowsLoc,
7495
+ TypeLoc ThrownTy,
7474
7496
GenericParamList *GenericParams,
7475
7497
DeclContext *Parent,
7476
7498
ClangNode ClangN);
@@ -7494,27 +7516,31 @@ class FuncDecl : public AbstractFunctionDecl {
7494
7516
static FuncDecl *createDeserialized(ASTContext &Context,
7495
7517
StaticSpellingKind StaticSpelling,
7496
7518
DeclName Name, bool Async, bool Throws,
7519
+ Type ThrownType,
7497
7520
GenericParamList *GenericParams,
7498
7521
Type FnRetType, DeclContext *Parent);
7499
7522
7500
7523
static FuncDecl *create(ASTContext &Context, SourceLoc StaticLoc,
7501
7524
StaticSpellingKind StaticSpelling, SourceLoc FuncLoc,
7502
7525
DeclName Name, SourceLoc NameLoc, bool Async,
7503
7526
SourceLoc AsyncLoc, bool Throws, SourceLoc ThrowsLoc,
7527
+ TypeRepr *ThrownTyR,
7504
7528
GenericParamList *GenericParams,
7505
7529
ParameterList *BodyParams, TypeRepr *ResultTyR,
7506
7530
DeclContext *Parent);
7507
7531
7508
7532
static FuncDecl *createImplicit(ASTContext &Context,
7509
7533
StaticSpellingKind StaticSpelling,
7510
7534
DeclName Name, SourceLoc NameLoc, bool Async,
7511
- bool Throws, GenericParamList *GenericParams,
7535
+ bool Throws, Type ThrownType,
7536
+ GenericParamList *GenericParams,
7512
7537
ParameterList *BodyParams, Type FnRetType,
7513
7538
DeclContext *Parent);
7514
7539
7515
7540
static FuncDecl *createImported(ASTContext &Context, SourceLoc FuncLoc,
7516
7541
DeclName Name, SourceLoc NameLoc, bool Async,
7517
- bool Throws, ParameterList *BodyParams,
7542
+ bool Throws, Type ThrownType,
7543
+ ParameterList *BodyParams,
7518
7544
Type FnRetType,
7519
7545
GenericParamList *GenericParams,
7520
7546
DeclContext *Parent, ClangNode ClangN);
@@ -7647,11 +7673,12 @@ class AccessorDecl final : public FuncDecl {
7647
7673
AccessorKind accessorKind, AbstractStorageDecl *storage,
7648
7674
SourceLoc staticLoc, StaticSpellingKind staticSpelling,
7649
7675
bool async, SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7676
+ TypeLoc thrownTy,
7650
7677
bool hasImplicitSelfDecl, DeclContext *parent)
7651
7678
: FuncDecl(DeclKind::Accessor, staticLoc, staticSpelling,
7652
7679
/*func loc*/ declLoc,
7653
7680
/*name*/ Identifier(), /*name loc*/ declLoc, async, asyncLoc,
7654
- throws, throwsLoc, hasImplicitSelfDecl,
7681
+ throws, throwsLoc, thrownTy, hasImplicitSelfDecl,
7655
7682
/*genericParams*/ nullptr, parent),
7656
7683
AccessorKeywordLoc(accessorKeywordLoc), Storage(storage) {
7657
7684
assert(!async || accessorKind == AccessorKind::Get
@@ -7664,6 +7691,7 @@ class AccessorDecl final : public FuncDecl {
7664
7691
AccessorKind accessorKind, AbstractStorageDecl *storage,
7665
7692
SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
7666
7693
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7694
+ TypeLoc thrownTy,
7667
7695
DeclContext *parent, ClangNode clangNode);
7668
7696
7669
7697
llvm::Optional<bool> getCachedIsTransparent() const {
@@ -7680,14 +7708,16 @@ class AccessorDecl final : public FuncDecl {
7680
7708
AbstractStorageDecl *storage,
7681
7709
StaticSpellingKind staticSpelling,
7682
7710
bool async, bool throws,
7711
+ Type thrownType,
7683
7712
Type fnRetType, DeclContext *parent);
7684
7713
7685
7714
static AccessorDecl *
7686
7715
create(ASTContext &ctx, SourceLoc declLoc, SourceLoc accessorKeywordLoc,
7687
7716
AccessorKind accessorKind, AbstractStorageDecl *storage,
7688
7717
SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
7689
7718
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7690
- ParameterList *parameterList, Type fnRetType, DeclContext *parent,
7719
+ TypeLoc thrownType, ParameterList *parameterList, Type fnRetType,
7720
+ DeclContext *parent,
7691
7721
ClangNode clangNode = ClangNode());
7692
7722
7693
7723
SourceLoc getAccessorKeywordLoc() const { return AccessorKeywordLoc; }
@@ -8050,6 +8080,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
8050
8080
bool Failable, SourceLoc FailabilityLoc,
8051
8081
bool Async, SourceLoc AsyncLoc,
8052
8082
bool Throws, SourceLoc ThrowsLoc,
8083
+ TypeLoc thrownTy,
8053
8084
ParameterList *BodyParams,
8054
8085
GenericParamList *GenericParams,
8055
8086
DeclContext *Parent);
@@ -8060,6 +8091,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
8060
8091
bool failable, SourceLoc failabilityLoc,
8061
8092
bool async, SourceLoc asyncLoc,
8062
8093
bool throws, SourceLoc throwsLoc,
8094
+ Type thrownTy,
8063
8095
ParameterList *bodyParams, GenericParamList *genericParams,
8064
8096
DeclContext *parent);
8065
8097
0 commit comments