@@ -5904,6 +5904,38 @@ class ImportAsMemberStatus {
59045904 }
59055905};
59065906
5907+ class BodyAndFingerprint {
5908+ llvm::PointerIntPair<BraceStmt *, 1 , bool > BodyAndHasFp;
5909+ Fingerprint Fp;
5910+
5911+ public:
5912+ BodyAndFingerprint (BraceStmt *body, Optional<Fingerprint> fp)
5913+ : BodyAndHasFp(body, fp.hasValue()),
5914+ Fp (fp.hasValue() ? *fp : Fingerprint::ZERO()) {}
5915+ BodyAndFingerprint () : BodyAndFingerprint(nullptr , None) {}
5916+
5917+ BraceStmt *getBody () const { return BodyAndHasFp.getPointer (); }
5918+
5919+ Optional<Fingerprint> getFingerprint () const {
5920+ if (BodyAndHasFp.getInt ())
5921+ return Fp;
5922+ else
5923+ return None;
5924+ }
5925+
5926+ void setFingerprint (Optional<Fingerprint> fp) {
5927+ if (fp.hasValue ()) {
5928+ Fp = *fp;
5929+ BodyAndHasFp.setInt (true );
5930+ } else {
5931+ Fp = Fingerprint::ZERO ();
5932+ BodyAndHasFp.setInt (false );
5933+ }
5934+ }
5935+ };
5936+
5937+ void simple_display (llvm::raw_ostream &out, BodyAndFingerprint value);
5938+
59075939// / Base class for function-like declarations.
59085940class AbstractFunctionDecl : public GenericContext , public ValueDecl {
59095941 friend class NeedsNewVTableEntryRequest ;
@@ -5986,7 +6018,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59866018 union {
59876019 // / This enum member is active if getBodyKind() is BodyKind::Parsed or
59886020 // / BodyKind::TypeChecked.
5989- BraceStmt *Body ;
6021+ BodyAndFingerprint BodyAndFP ;
59906022
59916023 // / This enum member is active if getBodyKind() is BodyKind::Deserialized.
59926024 StringRef BodyStringRepresentation;
@@ -6022,9 +6054,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
60226054 bool Throws, SourceLoc ThrowsLoc,
60236055 bool HasImplicitSelfDecl,
60246056 GenericParamList *GenericParams)
6025- : GenericContext(DeclContextKind::AbstractFunctionDecl, Parent, GenericParams),
6026- ValueDecl (Kind, Parent, Name, NameLoc),
6027- Body(nullptr ), AsyncLoc(AsyncLoc), ThrowsLoc(ThrowsLoc) {
6057+ : GenericContext(DeclContextKind::AbstractFunctionDecl, Parent,
6058+ GenericParams),
6059+ ValueDecl (Kind, Parent, Name, NameLoc), BodyAndFP(), AsyncLoc(AsyncLoc),
6060+ ThrowsLoc(ThrowsLoc) {
60286061 setBodyKind (BodyKind::None);
60296062 Bits.AbstractFunctionDecl .HasImplicitSelfDecl = HasImplicitSelfDecl;
60306063 Bits.AbstractFunctionDecl .Overridden = false ;
@@ -6195,8 +6228,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
61956228 void setBodyToBeReparsed (SourceRange bodyRange);
61966229
61976230 // / Provide the parsed body for the function.
6198- void setBodyParsed (BraceStmt *S) {
6231+ void setBodyParsed (BraceStmt *S, Optional<Fingerprint> fp = None ) {
61996232 setBody (S, BodyKind::Parsed);
6233+ BodyAndFP.setFingerprint (fp);
62006234 }
62016235
62026236 // / Was there a nested type declaration detected when parsing this
@@ -6286,6 +6320,15 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
62866320 // / itself.
62876321 void keepOriginalBodySourceRange ();
62886322
6323+ // / Retrieve the fingerprint of the body. Note that this is not affected by
6324+ // / the body of the local functions or the members of the local types in this
6325+ // / function.
6326+ Optional<Fingerprint> getBodyFingerprint () const ;
6327+
6328+ // / Retrieve the fingerprint of the body including the local type members and
6329+ // / the local funcition bodies.
6330+ Optional<Fingerprint> getBodyFingerprintIncludingLocalTypeMembers () const ;
6331+
62896332 // / Retrieve the source range of the *original* function body.
62906333 // /
62916334 // / This may be different from \c getBodySourceRange() that returns the source
0 commit comments