Skip to content

Commit 946eee9

Browse files
authored
Merge pull request swiftlang#29102 from DougGregor/function-builder-via-constraint-system
[Constraint solver] Use a constraint system to apply all function builders
2 parents 5c04e0d + 142b3ad commit 946eee9

16 files changed

+308
-93
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ class AnyFunctionRef {
216216
return lhs.TheFunction != rhs.TheFunction;
217217
}
218218

219+
friend llvm::hash_code hash_value(AnyFunctionRef fn) {
220+
using llvm::hash_value;
221+
return hash_value(fn.TheFunction.getOpaqueValue());
222+
}
223+
224+
friend SourceLoc extractNearestSourceLoc(AnyFunctionRef fn) {
225+
return fn.getLoc();
226+
}
227+
219228
private:
220229
ArrayRef<AnyFunctionType::Yield>
221230
getYieldResultsImpl(SmallVectorImpl<AnyFunctionType::Yield> &buffer,
@@ -243,6 +252,8 @@ class AnyFunctionRef {
243252
#pragma warning(pop)
244253
#endif
245254

255+
void simple_display(llvm::raw_ostream &out, AnyFunctionRef fn);
256+
246257
} // namespace swift
247258

248259
namespace llvm {

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,6 +4815,13 @@ NOTE(previous_function_builder_here, none,
48154815
"previous function builder specified here", ())
48164816
ERROR(function_builder_arguments, none,
48174817
"function builder attributes cannot have arguments", ())
4818+
WARNING(function_builder_disabled_by_return, none,
4819+
"application of function builder %0 disabled by explicit 'return' "
4820+
"statement", (Type))
4821+
NOTE(function_builder_remove_attr, none,
4822+
"remove the attribute to explicitly disable the function builder", ())
4823+
NOTE(function_builder_remove_returns, none,
4824+
"remove 'return' statements to apply the function builder", ())
48184825

48194826
//------------------------------------------------------------------------------
48204827
// MARK: differentiable programming diagnostics

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef SWIFT_TYPE_CHECK_REQUESTS_H
1717
#define SWIFT_TYPE_CHECK_REQUESTS_H
1818

19+
#include "swift/AST/AnyFunctionRef.h"
1920
#include "swift/AST/ASTTypeIDs.h"
2021
#include "swift/AST/GenericSignature.h"
2122
#include "swift/AST/Type.h"
@@ -1760,7 +1761,7 @@ enum class FunctionBuilderClosurePreCheck : uint8_t {
17601761

17611762
class PreCheckFunctionBuilderRequest
17621763
: public SimpleRequest<PreCheckFunctionBuilderRequest,
1763-
FunctionBuilderClosurePreCheck(ClosureExpr *),
1764+
FunctionBuilderClosurePreCheck(AnyFunctionRef),
17641765
CacheKind::Cached> {
17651766
public:
17661767
using SimpleRequest::SimpleRequest;
@@ -1770,7 +1771,7 @@ class PreCheckFunctionBuilderRequest
17701771

17711772
// Evaluation.
17721773
llvm::Expected<FunctionBuilderClosurePreCheck>
1773-
evaluate(Evaluator &evaluator, ClosureExpr *closure) const;
1774+
evaluate(Evaluator &evaluator, AnyFunctionRef fn) const;
17741775

17751776
public:
17761777
// Separate caching.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ SWIFT_REQUEST(TypeChecker, HasUserDefinedDesignatedInitRequest,
196196
SWIFT_REQUEST(TypeChecker, HasMemberwiseInitRequest,
197197
bool(StructDecl *), Cached, NoLocationInfo)
198198
SWIFT_REQUEST(TypeChecker, PreCheckFunctionBuilderRequest,
199-
FunctionBuilderClosurePreCheck(ClosureExpr *),
199+
FunctionBuilderClosurePreCheck(AnyFunctionRef),
200200
Cached, NoLocationInfo)
201201
SWIFT_REQUEST(TypeChecker, ResolveImplicitMemberRequest,
202202
bool(NominalTypeDecl *, ImplicitMemberAction), Uncached,

lib/AST/Decl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7903,3 +7903,10 @@ void ParseAbstractFunctionBodyRequest::cacheResult(BraceStmt *value) const {
79037903
}
79047904

79057905
}
7906+
7907+
void swift::simple_display(llvm::raw_ostream &out, AnyFunctionRef fn) {
7908+
if (auto func = fn.getAbstractFunctionDecl())
7909+
simple_display(out, func);
7910+
else
7911+
out << "closure";
7912+
}

0 commit comments

Comments
 (0)