Skip to content

Commit 5c3508b

Browse files
authored
[AutoDiff] Enable cross-file derivative registration by default. (#31249)
Enable cross-file derivative registration by default on tensorflow branch. Cross-file derivative registration is already enabled on master branch. Remove `-enable-experimental-cross-file-derivative-registration` flag, which was never upstreamed to master. Resolves TF-1097.
1 parent ece42ab commit 5c3508b

File tree

12 files changed

+9
-50
lines changed

12 files changed

+9
-50
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,6 @@ namespace swift {
336336
bool EnableExperimentalDifferentiableProgramming = true;
337337
// SWIFT_ENABLE_TENSORFLOW END
338338

339-
// SWIFT_ENABLE_TENSORFLOW
340-
/// Whether to enable cross-file derivative registration.
341-
bool EnableExperimentalCrossFileDerivativeRegistration = false;
342-
// SWIFT_ENABLE_TENSORFLOW END
343-
344339
/// Whether to enable forward mode differentiation.
345340
bool EnableExperimentalForwardModeDifferentiation = false;
346341

include/swift/Option/Options.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,6 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
502502

503503
// Experimental feature options
504504

505-
// SWIFT_ENABLE_TENSORFLOW
506-
// TODO(TF-1097): Remove this flag and always enable cross-file derivative registration.
507-
def enable_experimental_cross_file_derivative_registration :
508-
Flag<["-"], "enable-experimental-cross-file-derivative-registration">,
509-
Flags<[FrontendOption, ModuleInterfaceOption]>,
510-
HelpText<"Enable experimental cross-file derivative registration">;
511-
// SWIFT_ENABLE_TENSORFLOW END
512-
513505
// Note: this flag will be removed when JVP/differential generation in the
514506
// differentiation transform is robust.
515507
def enable_experimental_forward_mode_differentiation :

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
449449
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
450450
Opts.EnableExperimentalAdditiveArithmeticDerivedConformances = true;
451451

452-
// SWIFT_ENABLE_TENSORFLOW
453-
// TODO(TF-1097): Remove this flag.
454-
Opts.EnableExperimentalCrossFileDerivativeRegistration |=
455-
Args.hasArg(OPT_enable_experimental_cross_file_derivative_registration);
456-
// SWIFT_ENABLE_TENSORFLOW END
457-
458452
Opts.EnableExperimentalForwardModeDifferentiation |=
459453
Args.hasArg(OPT_enable_experimental_forward_mode_differentiation);
460454

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,17 +4441,6 @@ static bool typeCheckDerivativeAttr(ASTContext &Ctx, Decl *D,
44414441
return true;
44424442
}
44434443

4444-
// SWIFT_ENABLE_TENSORFLOW
4445-
// Reject different-file derivative registration.
4446-
// TODO(TF-1021): Lift same-file derivative registration restriction.
4447-
if (!Ctx.LangOpts.EnableExperimentalCrossFileDerivativeRegistration &&
4448-
originalAFD->getParentSourceFile() != derivative->getParentSourceFile()) {
4449-
diags.diagnose(attr->getLocation(),
4450-
diag::derivative_attr_not_in_same_file_as_original);
4451-
return true;
4452-
}
4453-
// SWIFT_ENABLE_TENSORFLOW END
4454-
44554444
// Reject duplicate `@derivative` attributes.
44564445
auto &derivativeAttrs = Ctx.DerivativeAttrs[std::make_tuple(
44574446
originalAFD, resolvedDiffParamIndices, kind)];

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,11 +1733,6 @@ function(add_swift_target_library name)
17331733
endif()
17341734
endif()
17351735

1736-
# SWIFT_ENABLE_TENSORFLOW
1737-
list(APPEND swiftlib_swift_compile_flags_all
1738-
-Xfrontend -enable-experimental-cross-file-derivative-registration)
1739-
# SWIFT_ENABLE_TENSORFLOW END
1740-
17411736
# Collect architecture agnostic SDK linker flags
17421737
set(swiftlib_link_flags_all ${SWIFTLIB_LINK_FLAGS})
17431738
if(${sdk} STREQUAL IOS_SIMULATOR AND ${name} STREQUAL swiftMediaPlayer)

test/AutoDiff/Sema/DerivativeRegistrationCrossModule/main.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -primary-file %S/Inputs/a.swift -emit-module-path %t/a.swiftmodule
3-
// SWIFT_ENABLE_TENSORFLOW
4-
// Use `-enable-experimental-cross-file-derivative-registration` flag. To be removed soon.
5-
// RUN: %target-swift-frontend -enable-experimental-cross-file-derivative-registration -emit-module -primary-file %S/Inputs/b.swift -emit-module-path %t/b.swiftmodule -I %t
6-
// SWIFT_ENABLE_TENSORFLOW END
3+
// RUN: %target-swift-frontend -emit-module -primary-file %S/Inputs/b.swift -emit-module-path %t/b.swiftmodule -I %t
74
// "-verify-ignore-unknown" is for "<unknown>:0: note: 'init()' declared here"
85
// RUN: %target-swift-frontend-typecheck -verify -verify-ignore-unknown -I %t %s
96

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,6 @@ extension InoutParameters {
756756
// Test cross-file derivative registration.
757757

758758
extension FloatingPoint where Self: Differentiable {
759-
// expected-error @+1 {{derivative not in the same file as the original function}}
760759
@derivative(of: rounded)
761760
func vjpRounded() -> (
762761
value: Self,

test/AutoDiff/downstream/always_emit_into_client_multi_file.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// cross_module_derivative_attr_e2e.swift.
33

44
// RUN: %empty-directory(%t)
5-
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -parse-as-library -emit-module -module-name MultiFileModule -emit-module-path %t/MultiFileModule.swiftmodule -emit-library -o %t/%target-library-name(MultiFileModule) %S/Inputs/always_emit_into_client/MultiFileModule/file1.swift %S/Inputs/always_emit_into_client/MultiFileModule/file2.swift
5+
// RUN: %target-build-swift -parse-as-library -emit-module -module-name MultiFileModule -emit-module-path %t/MultiFileModule.swiftmodule -emit-library -o %t/%target-library-name(MultiFileModule) %S/Inputs/always_emit_into_client/MultiFileModule/file1.swift %S/Inputs/always_emit_into_client/MultiFileModule/file2.swift
66
// RUN: not %target-build-swift -I%t -L%t %s -o %t/a.out -lm -lMultiFileModule 2>&1 | %FileCheck %s
77

88
import StdlibUnittest

test/AutoDiff/downstream/always_emit_into_client_single_file.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// cross_module_derivative_attr_e2e.swift.
33

44
// RUN: %empty-directory(%t)
5-
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -parse-as-library -emit-module -module-name SingleFileModule -emit-module-path %t/SingleFileModule.swiftmodule -emit-library -o %t/%target-library-name(SingleFileModule) %S/Inputs/always_emit_into_client/SingleFileModule/file.swift
5+
// RUN: %target-build-swift -Xfrontend -parse-as-library -emit-module -module-name SingleFileModule -emit-module-path %t/SingleFileModule.swiftmodule -emit-library -o %t/%target-library-name(SingleFileModule) %S/Inputs/always_emit_into_client/SingleFileModule/file.swift
66
// RUN: not %target-build-swift -I%t -L%t %s -o %t/a.out -lm -lSingleFileModule 2>&1 | %FileCheck %s
77

88
import StdlibUnittest
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -working-directory %t -I%t -parse-as-library -emit-module -module-name module1 -emit-module-path %t/module1.swiftmodule -emit-library -static %S/Inputs/cross_module_derivative_attr_e2e/module1/module1.swift %S/Inputs/cross_module_derivative_attr_e2e/module1/module1_other_file.swift -Xfrontend -enable-experimental-cross-file-derivative-registration -Xfrontend -validate-tbd-against-ir=none
3-
// RUN: %target-build-swift -I%t -L%t %S/Inputs/cross_module_derivative_attr_e2e/main/main.swift -o %t/a.out -lm -lmodule1 -Xfrontend -enable-experimental-cross-file-derivative-registration -Xfrontend -validate-tbd-against-ir=none
2+
// RUN: %target-build-swift -working-directory %t -I%t -parse-as-library -emit-module -module-name module1 -emit-module-path %t/module1.swiftmodule -emit-library -static %S/Inputs/cross_module_derivative_attr_e2e/module1/module1.swift %S/Inputs/cross_module_derivative_attr_e2e/module1/module1_other_file.swift -Xfrontend -validate-tbd-against-ir=none
3+
// RUN: %target-build-swift -I%t -L%t %S/Inputs/cross_module_derivative_attr_e2e/main/main.swift -o %t/a.out -lm -lmodule1 -Xfrontend -validate-tbd-against-ir=none
44
// RUN: %target-run %t/a.out
55
// REQUIRES: executable_test

test/AutoDiff/downstream/derivative_attr_type_checking.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@ func vjpFooExtraGenericRequirements<T : FloatingPoint & Differentiable & BinaryI
151151
return (x, { $0 })
152152
}
153153

154-
// Test cross-file derivative registration. Currently unsupported.
155-
// TODO(TF-1021): Lift this restriction.
154+
// Test cross-file derivative registration.
156155
extension FloatingPoint where Self: Differentiable {
157-
// expected-error @+1 {{derivative not in the same file as the original function}}
158156
@derivative(of: rounded)
159157
func vjpRounded() -> (value: Self, pullback: (TangentVector) -> TangentVector) {
160158
fatalError()

test/AutoDiff/downstream/derivative_registration_foreign/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %clang -c %S/Inputs/Foreign.c -fmodules -o %t/CForeign.o
3-
// RUN: %target-swift-emit-silgen -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SILGEN --check-prefix=CHECK
4-
// RUN: %target-swift-emit-sil -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SIL --check-prefix=CHECK
5-
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s %t/CForeign.o
3+
// RUN: %target-swift-emit-silgen -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SILGEN --check-prefix=CHECK
4+
// RUN: %target-swift-emit-sil -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SIL --check-prefix=CHECK
5+
// RUN: %target-build-swift -I %S/Inputs -I %t %s %t/CForeign.o
66

77
import CForeign
88

0 commit comments

Comments
 (0)