File tree Expand file tree Collapse file tree 4 files changed +23
-21
lines changed Expand file tree Collapse file tree 4 files changed +23
-21
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2019 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
31
31
namespace swift {
32
32
33
33
class AnyFunctionType ;
34
+ class SourceFile ;
34
35
class SILFunctionType ;
35
36
class TupleType ;
36
37
@@ -392,6 +393,9 @@ class TangentSpace {
392
393
// / derivative generic signature.
393
394
using SILDifferentiabilityWitnessKey = std::pair<StringRef, AutoDiffConfig>;
394
395
396
+ // / Returns `true` iff differentiable programming is enabled.
397
+ bool isDifferentiableProgrammingEnabled (SourceFile &SF);
398
+
395
399
// / Automatic differentiation utility namespace.
396
400
namespace autodiff {
397
401
Original file line number Diff line number Diff line change 13
13
#include " swift/AST/AutoDiff.h"
14
14
#include " swift/AST/ASTContext.h"
15
15
#include " swift/AST/GenericEnvironment.h"
16
+ #include " swift/AST/ImportCache.h"
16
17
#include " swift/AST/Module.h"
17
18
#include " swift/AST/TypeCheckRequests.h"
18
19
#include " swift/AST/Types.h"
@@ -124,6 +125,23 @@ void AutoDiffConfig::print(llvm::raw_ostream &s) const {
124
125
s << ' )' ;
125
126
}
126
127
128
+ bool swift::isDifferentiableProgrammingEnabled (SourceFile &SF) {
129
+ auto &ctx = SF.getASTContext ();
130
+ // Return true if differentiable programming is explicitly enabled.
131
+ if (ctx.LangOpts .EnableExperimentalDifferentiableProgramming )
132
+ return true ;
133
+ // Otherwise, return true iff the `_Differentiation` module is imported in
134
+ // the given source file.
135
+ bool importsDifferentiationModule = false ;
136
+ for (auto import : namelookup::getAllImports (&SF)) {
137
+ if (import .second ->getName () == ctx.Id_Differentiation ) {
138
+ importsDifferentiationModule = true ;
139
+ break ;
140
+ }
141
+ }
142
+ return importsDifferentiationModule;
143
+ }
144
+
127
145
// TODO(TF-874): This helper is inefficient and should be removed. Unwrapping at
128
146
// most once (for curried method types) is sufficient.
129
147
static void unwrapCurryLevels (AnyFunctionType *fnTy,
Original file line number Diff line number Diff line change @@ -410,23 +410,6 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
410
410
#endif
411
411
}
412
412
413
- bool swift::isDifferentiableProgrammingEnabled (SourceFile &SF) {
414
- auto &ctx = SF.getASTContext ();
415
- // Return true if differentiable programming is explicitly enabled.
416
- if (ctx.LangOpts .EnableExperimentalDifferentiableProgramming )
417
- return true ;
418
- // Otherwise, return true iff the `_Differentiation` module is imported in
419
- // the given source file.
420
- bool importsDifferentiationModule = false ;
421
- for (auto import : namelookup::getAllImports (&SF)) {
422
- if (import .second ->getName () == ctx.Id_Differentiation ) {
423
- importsDifferentiationModule = true ;
424
- break ;
425
- }
426
- }
427
- return importsDifferentiationModule;
428
- }
429
-
430
413
bool swift::isAdditiveArithmeticConformanceDerivationEnabled (SourceFile &SF) {
431
414
auto &ctx = SF.getASTContext ();
432
415
// Return true if `AdditiveArithmetic` derived conformances are explicitly
Original file line number Diff line number Diff line change @@ -1520,9 +1520,6 @@ bool isMemberOperator(FuncDecl *decl, Type type);
1520
1520
// / Complain if @objc or dynamic is used without importing Foundation.
1521
1521
void diagnoseAttrsRequiringFoundation (SourceFile &SF);
1522
1522
1523
- // / Returns `true` iff differentiable programming is enabled.
1524
- bool isDifferentiableProgrammingEnabled (SourceFile &SF);
1525
-
1526
1523
// / Returns `true` iff `AdditiveArithmetic` derived conformances are enabled.
1527
1524
bool isAdditiveArithmeticConformanceDerivationEnabled (SourceFile &SF);
1528
1525
You can’t perform that action at this time.
0 commit comments