@@ -6839,6 +6839,7 @@ void simple_display(llvm::raw_ostream &out, BodyAndFingerprint value);
68396839// / Base class for function-like declarations.
68406840class AbstractFunctionDecl : public GenericContext , public ValueDecl {
68416841 friend class NeedsNewVTableEntryRequest ;
6842+ friend class ThrownTypeRequest ;
68426843
68436844public:
68446845 // / records the kind of SILGen-synthesized body this decl represents
@@ -6950,6 +6951,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
69506951 // / Location of the 'throws' token.
69516952 SourceLoc ThrowsLoc;
69526953
6954+ // / The error type that is being thrown.
6955+ TypeLoc ThrownType;
6956+
69536957 struct {
69546958 unsigned NeedsNewVTableEntryComputed : 1 ;
69556959 unsigned NeedsNewVTableEntry : 1 ;
@@ -6958,12 +6962,13 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
69586962 AbstractFunctionDecl (DeclKind Kind, DeclContext *Parent, DeclName Name,
69596963 SourceLoc NameLoc, bool Async, SourceLoc AsyncLoc,
69606964 bool Throws, SourceLoc ThrowsLoc,
6965+ TypeLoc ThrownTy,
69616966 bool HasImplicitSelfDecl,
69626967 GenericParamList *GenericParams)
69636968 : GenericContext(DeclContextKind::AbstractFunctionDecl, Parent,
69646969 GenericParams),
69656970 ValueDecl (Kind, Parent, Name, NameLoc), BodyAndFP(), AsyncLoc(AsyncLoc),
6966- ThrowsLoc(ThrowsLoc) {
6971+ ThrowsLoc(ThrowsLoc), ThrownType(ThrownTy) {
69676972 setBodyKind (BodyKind::None);
69686973 Bits.AbstractFunctionDecl .HasImplicitSelfDecl = HasImplicitSelfDecl;
69696974 Bits.AbstractFunctionDecl .Overridden = false ;
@@ -7069,6 +7074,21 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
70697074 // / Returns true if the function body throws.
70707075 bool hasThrows () const { return Bits.AbstractFunctionDecl .Throws ; }
70717076
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+
70727092 // / Returns if the function throws or is async.
70737093 bool hasEffect (EffectKind kind) const ;
70747094
@@ -7441,12 +7461,13 @@ class FuncDecl : public AbstractFunctionDecl {
74417461 DeclName Name, SourceLoc NameLoc,
74427462 bool Async, SourceLoc AsyncLoc,
74437463 bool Throws, SourceLoc ThrowsLoc,
7464+ TypeLoc ThrownTy,
74447465 bool HasImplicitSelfDecl,
74457466 GenericParamList *GenericParams, DeclContext *Parent)
74467467 : AbstractFunctionDecl(Kind, Parent,
74477468 Name, NameLoc,
74487469 Async, AsyncLoc,
7449- Throws, ThrowsLoc,
7470+ Throws, ThrowsLoc, ThrownTy,
74507471 HasImplicitSelfDecl, GenericParams),
74517472 StaticLoc (StaticLoc), FuncLoc(FuncLoc) {
74527473 assert (!Name.getBaseName ().isSpecial ());
@@ -7471,6 +7492,7 @@ class FuncDecl : public AbstractFunctionDecl {
74717492 DeclName Name, SourceLoc NameLoc,
74727493 bool Async, SourceLoc AsyncLoc,
74737494 bool Throws, SourceLoc ThrowsLoc,
7495+ TypeLoc ThrownTy,
74747496 GenericParamList *GenericParams,
74757497 DeclContext *Parent,
74767498 ClangNode ClangN);
@@ -7494,27 +7516,31 @@ class FuncDecl : public AbstractFunctionDecl {
74947516 static FuncDecl *createDeserialized (ASTContext &Context,
74957517 StaticSpellingKind StaticSpelling,
74967518 DeclName Name, bool Async, bool Throws,
7519+ Type ThrownType,
74977520 GenericParamList *GenericParams,
74987521 Type FnRetType, DeclContext *Parent);
74997522
75007523 static FuncDecl *create (ASTContext &Context, SourceLoc StaticLoc,
75017524 StaticSpellingKind StaticSpelling, SourceLoc FuncLoc,
75027525 DeclName Name, SourceLoc NameLoc, bool Async,
75037526 SourceLoc AsyncLoc, bool Throws, SourceLoc ThrowsLoc,
7527+ TypeRepr *ThrownTyR,
75047528 GenericParamList *GenericParams,
75057529 ParameterList *BodyParams, TypeRepr *ResultTyR,
75067530 DeclContext *Parent);
75077531
75087532 static FuncDecl *createImplicit (ASTContext &Context,
75097533 StaticSpellingKind StaticSpelling,
75107534 DeclName Name, SourceLoc NameLoc, bool Async,
7511- bool Throws, GenericParamList *GenericParams,
7535+ bool Throws, Type ThrownType,
7536+ GenericParamList *GenericParams,
75127537 ParameterList *BodyParams, Type FnRetType,
75137538 DeclContext *Parent);
75147539
75157540 static FuncDecl *createImported (ASTContext &Context, SourceLoc FuncLoc,
75167541 DeclName Name, SourceLoc NameLoc, bool Async,
7517- bool Throws, ParameterList *BodyParams,
7542+ bool Throws, Type ThrownType,
7543+ ParameterList *BodyParams,
75187544 Type FnRetType,
75197545 GenericParamList *GenericParams,
75207546 DeclContext *Parent, ClangNode ClangN);
@@ -7647,11 +7673,12 @@ class AccessorDecl final : public FuncDecl {
76477673 AccessorKind accessorKind, AbstractStorageDecl *storage,
76487674 SourceLoc staticLoc, StaticSpellingKind staticSpelling,
76497675 bool async, SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7676+ TypeLoc thrownTy,
76507677 bool hasImplicitSelfDecl, DeclContext *parent)
76517678 : FuncDecl(DeclKind::Accessor, staticLoc, staticSpelling,
76527679 /* func loc*/ declLoc,
76537680 /* name*/ Identifier(), /* name loc*/ declLoc, async, asyncLoc,
7654- throws, throwsLoc, hasImplicitSelfDecl,
7681+ throws, throwsLoc, thrownTy, hasImplicitSelfDecl,
76557682 /* genericParams*/ nullptr , parent),
76567683 AccessorKeywordLoc (accessorKeywordLoc), Storage(storage) {
76577684 assert (!async || accessorKind == AccessorKind::Get
@@ -7664,6 +7691,7 @@ class AccessorDecl final : public FuncDecl {
76647691 AccessorKind accessorKind, AbstractStorageDecl *storage,
76657692 SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
76667693 SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7694+ TypeLoc thrownTy,
76677695 DeclContext *parent, ClangNode clangNode);
76687696
76697697 llvm::Optional<bool > getCachedIsTransparent () const {
@@ -7680,14 +7708,16 @@ class AccessorDecl final : public FuncDecl {
76807708 AbstractStorageDecl *storage,
76817709 StaticSpellingKind staticSpelling,
76827710 bool async, bool throws,
7711+ Type thrownType,
76837712 Type fnRetType, DeclContext *parent);
76847713
76857714 static AccessorDecl *
76867715 create (ASTContext &ctx, SourceLoc declLoc, SourceLoc accessorKeywordLoc,
76877716 AccessorKind accessorKind, AbstractStorageDecl *storage,
76887717 SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
76897718 SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7690- ParameterList *parameterList, Type fnRetType, DeclContext *parent,
7719+ TypeLoc thrownType, ParameterList *parameterList, Type fnRetType,
7720+ DeclContext *parent,
76917721 ClangNode clangNode = ClangNode());
76927722
76937723 SourceLoc getAccessorKeywordLoc () const { return AccessorKeywordLoc; }
@@ -8050,6 +8080,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
80508080 bool Failable, SourceLoc FailabilityLoc,
80518081 bool Async, SourceLoc AsyncLoc,
80528082 bool Throws, SourceLoc ThrowsLoc,
8083+ TypeLoc thrownTy,
80538084 ParameterList *BodyParams,
80548085 GenericParamList *GenericParams,
80558086 DeclContext *Parent);
@@ -8060,6 +8091,7 @@ class ConstructorDecl : public AbstractFunctionDecl {
80608091 bool failable, SourceLoc failabilityLoc,
80618092 bool async, SourceLoc asyncLoc,
80628093 bool throws, SourceLoc throwsLoc,
8094+ Type thrownTy,
80638095 ParameterList *bodyParams, GenericParamList *genericParams,
80648096 DeclContext *parent);
80658097
0 commit comments