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 22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2019 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
3131namespace swift {
3232
3333class AnyFunctionType ;
34+ class SourceFile ;
3435class SILFunctionType ;
3536class TupleType ;
3637
@@ -392,6 +393,9 @@ class TangentSpace {
392393// / derivative generic signature.
393394using SILDifferentiabilityWitnessKey = std::pair<StringRef, AutoDiffConfig>;
394395
396+ // / Returns `true` iff differentiable programming is enabled.
397+ bool isDifferentiableProgrammingEnabled (SourceFile &SF);
398+
395399// / Automatic differentiation utility namespace.
396400namespace autodiff {
397401
Original file line number Diff line number Diff line change 1313#include " swift/AST/AutoDiff.h"
1414#include " swift/AST/ASTContext.h"
1515#include " swift/AST/GenericEnvironment.h"
16+ #include " swift/AST/ImportCache.h"
1617#include " swift/AST/Module.h"
1718#include " swift/AST/TypeCheckRequests.h"
1819#include " swift/AST/Types.h"
@@ -124,6 +125,23 @@ void AutoDiffConfig::print(llvm::raw_ostream &s) const {
124125 s << ' )' ;
125126}
126127
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+
127145// TODO(TF-874): This helper is inefficient and should be removed. Unwrapping at
128146// most once (for curried method types) is sufficient.
129147static void unwrapCurryLevels (AnyFunctionType *fnTy,
Original file line number Diff line number Diff line change @@ -410,23 +410,6 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
410410#endif
411411}
412412
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-
430413bool swift::isAdditiveArithmeticConformanceDerivationEnabled (SourceFile &SF) {
431414 auto &ctx = SF.getASTContext ();
432415 // 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);
15201520// / Complain if @objc or dynamic is used without importing Foundation.
15211521void diagnoseAttrsRequiringFoundation (SourceFile &SF);
15221522
1523- // / Returns `true` iff differentiable programming is enabled.
1524- bool isDifferentiableProgrammingEnabled (SourceFile &SF);
1525-
15261523// / Returns `true` iff `AdditiveArithmetic` derived conformances are enabled.
15271524bool isAdditiveArithmeticConformanceDerivationEnabled (SourceFile &SF);
15281525
You can’t perform that action at this time.
0 commit comments