Skip to content

Commit b72aca9

Browse files
committed
Merge branch 'master' of https://github.com/apple/swift
2 parents f07ae89 + 41cc3f3 commit b72aca9

File tree

54 files changed

+2296
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2296
-51
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ macro(configure_sdks)
166166
endif()
167167
endmacro()
168168

169-
function (add_swift_benchmark_library objfile_out sibfile_out)
169+
function (add_swift_benchmark_library objfile_out sibfile_out swiftmodule_out)
170170
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS" ${ARGN})
171171

172172
precondition(BENCHLIB_MODULE_PATH)
@@ -197,6 +197,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
197197
"-o" "${objfile}"
198198
${sources})
199199
set(${objfile_out} "${objfile}" PARENT_SCOPE)
200+
set(${swiftmodule_out} "${swiftmodule}" PARENT_SCOPE)
200201

201202
if(SWIFT_BENCHMARK_EMIT_SIB)
202203
precondition(sibfile_out)
@@ -401,19 +402,21 @@ function (swift_benchmark_compile_archopts)
401402
endif()
402403
set(bench_library_objects)
403404
set(bench_library_sibfiles)
405+
set(bench_library_swiftmodules)
404406
set(opt_view_dirs)
405407
# Build libraries used by the driver and benchmarks.
406408
foreach(module_name_path ${BENCH_LIBRARY_MODULES})
407409
set(sources "${srcdir}/${module_name_path}.swift")
408410

409-
add_swift_benchmark_library(objfile_out sibfile_out
411+
add_swift_benchmark_library(objfile_out sibfile_out swiftmodule_out
410412
MODULE_PATH "${module_name_path}"
411413
SOURCE_DIR "${srcdir}"
412414
OBJECT_DIR "${objdir}"
413415
SOURCES ${sources}
414416
LIBRARY_FLAGS ${common_swift4_options})
415417
precondition(objfile_out)
416418
list(APPEND bench_library_objects "${objfile_out}")
419+
list(APPEND bench_library_swiftmodules "${swiftmodule_out}")
417420
if (SWIFT_BENCHMARK_EMIT_SIB)
418421
precondition(sibfile_out)
419422
list(APPEND bench_library_sibfiles "${sibfile_out}")
@@ -433,7 +436,7 @@ function (swift_benchmark_compile_archopts)
433436

434437
set(objfile_out)
435438
set(sibfile_out)
436-
add_swift_benchmark_library(objfile_out sibfile_out
439+
add_swift_benchmark_library(objfile_out sibfile_out swiftmodule_out
437440
MODULE_PATH "${module_name_path}"
438441
SOURCE_DIR "${srcdir}"
439442
OBJECT_DIR "${objdir}"
@@ -442,6 +445,7 @@ function (swift_benchmark_compile_archopts)
442445
DEPENDS ${bench_library_objects})
443446
precondition(objfile_out)
444447
list(APPEND bench_driver_objects "${objfile_out}")
448+
list(APPEND bench_library_swiftmodules "${swiftmodule_out}")
445449
if (SWIFT_BENCHMARK_EMIT_SIB)
446450
precondition(sibfile_out)
447451
list(APPEND bench_driver_sibfiles "${sibfile_out}")
@@ -464,6 +468,7 @@ function (swift_benchmark_compile_archopts)
464468
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
465469
set(source "${srcdir}/${module_name_path}.swift")
466470
list(APPEND SWIFT_BENCH_OBJFILES "${objfile}")
471+
list(APPEND bench_library_swiftmodules "${swiftmodule}")
467472

468473
if ("${bench_flags}" MATCHES "-whole-module.*")
469474
set(output_option "-o" "${objfile}")
@@ -622,6 +627,15 @@ function (swift_benchmark_compile_archopts)
622627
else()
623628
set(SWIFT_LINK_RPATH "${SWIFT_RPATH_BASE}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}")
624629
endif()
630+
631+
# On Darwin, we pass the *.swiftmodule paths transitively referenced by the
632+
# driver executable to ld64. ld64 inserts N_AST references to these modules
633+
# into the program, for later use by lldb.
634+
set(ld64_add_ast_path_opts)
635+
foreach(ast_path ${bench_library_swiftmodules})
636+
list(APPEND ld64_add_ast_path_opts "-Wl,-add_ast_path,${ast_path}")
637+
endforeach()
638+
625639
add_custom_command(
626640
OUTPUT "${OUTPUT_EXEC}"
627641
DEPENDS
@@ -647,6 +661,7 @@ function (swift_benchmark_compile_archopts)
647661
"-Xlinker" "${SWIFT_LINK_RPATH}"
648662
${bench_library_objects}
649663
${bench_driver_objects}
664+
${ld64_add_ast_path_opts}
650665
${SWIFT_BENCH_OBJFILES}
651666
${objcfile}
652667
"-o" "${OUTPUT_EXEC}"

include/swift/AST/AutoDiff.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ struct AutoDiffConfig {
227227
SWIFT_DEBUG_DUMP;
228228
};
229229

230+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
231+
const SILAutoDiffIndices &indices) {
232+
indices.print(s);
233+
return s;
234+
}
235+
230236
/// A semantic function result type: either a formal function result type or
231237
/// an `inout` parameter type. Used in derivative function type calculation.
232238
struct AutoDiffSemanticFunctionResultType {

include/swift/AST/DiagnosticsSIL.def

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,36 @@ ERROR(not_constant_evaluable, none, "not constant evaluable", ())
445445
ERROR(constexpr_imported_func_not_onone, none, "imported constant evaluable "
446446
"function '%0' must be annotated '@_optimize(none)'", (StringRef))
447447

448+
// Differentiation transform diagnostics
449+
ERROR(autodiff_internal_swift_not_imported,none,
450+
"Automatic differentiation internal error: the Swift module is not "
451+
"imported", ())
452+
ERROR(autodiff_differentiation_module_not_imported,none,
453+
"Automatic differentiation requires the '_Differentiation' module to be "
454+
"imported", ())
455+
ERROR(autodiff_conversion_to_linear_function_not_supported,none,
456+
"conversion to '@differentiable(linear)' function type is not yet "
457+
"supported", ())
458+
ERROR(autodiff_function_not_differentiable_error,none,
459+
"function is not differentiable", ())
460+
ERROR(autodiff_expression_not_differentiable_error,none,
461+
"expression is not differentiable", ())
462+
NOTE(autodiff_expression_not_differentiable_note,none,
463+
"expression is not differentiable", ())
464+
NOTE(autodiff_when_differentiating_function_call,none,
465+
"when differentiating this function call", ())
466+
NOTE(autodiff_when_differentiating_function_definition,none,
467+
"when differentiating this function definition", ())
468+
NOTE(autodiff_implicitly_inherited_differentiable_attr_here,none,
469+
"differentiability required by the corresponding protocol requirement "
470+
"here", ())
471+
NOTE(autodiff_jvp_control_flow_not_supported,none,
472+
"forward-mode differentiation does not yet support control flow", ())
473+
NOTE(autodiff_control_flow_not_supported,none,
474+
"cannot differentiate unsupported control flow", ())
475+
NOTE(autodiff_missing_return,none,
476+
"missing return for differentiation", ())
477+
448478
ERROR(non_physical_addressof,none,
449479
"addressof only works with purely physical lvalues; "
450480
"use 'withUnsafePointer' or 'withUnsafeBytes' unless you're implementing "

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,13 @@ NOTE(objc_ambiguous_inference_candidate,none,
43424342
"%0 (in protocol %1) provides Objective-C name %2",
43434343
(DeclName, DeclName, ObjCSelector))
43444344

4345+
ERROR(objc_ambiguous_error_convention,none,
4346+
"%0 overrides or implements protocol requirements for Objective-C "
4347+
"declarations with incompatible error argument conventions",
4348+
(DeclName))
4349+
NOTE(objc_ambiguous_error_convention_candidate,none,
4350+
"%0 provides an error argument here", (DeclName))
4351+
43454352
ERROR(nonlocal_bridged_to_objc,none,
43464353
"conformance of %0 to %1 can only be written in module %2",
43474354
(Identifier, Identifier, Identifier))

include/swift/AST/ForeignErrorConvention.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ class ForeignErrorConvention {
182182
getKind() == NonZeroResult);
183183
return ResultType;
184184
}
185+
186+
bool operator==(ForeignErrorConvention other) const {
187+
return info.TheKind == other.info.TheKind
188+
&& info.ErrorIsOwned == other.info.ErrorIsOwned
189+
&& info.ErrorParameterIsReplaced == other.info.ErrorParameterIsReplaced
190+
&& info.ErrorParameterIndex == other.info.ErrorParameterIndex;
191+
}
192+
bool operator!=(ForeignErrorConvention other) const {
193+
return !(*this == other);
194+
}
185195
};
186196

187197
}

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ namespace swift {
327327
/// `@differentiable` declaration attribute, etc.
328328
bool EnableExperimentalDifferentiableProgramming = false;
329329

330+
/// Whether to enable forward mode differentiation.
331+
bool EnableExperimentalForwardModeDifferentiation = false;
332+
330333
/// Whether to enable experimental `AdditiveArithmetic` derived
331334
/// conformances.
332335
bool EnableExperimentalAdditiveArithmeticDerivedConformances = false;

include/swift/Option/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
498498
HelpText<"Disable automatic generation of bridging PCH files">;
499499

500500
// Experimental feature options
501+
502+
// Note: this flag will be removed when JVP/differential generation in the
503+
// differentiation transform is robust.
504+
def enable_experimental_forward_mode_differentiation :
505+
Flag<["-"], "enable-experimental-forward-mode-differentiation">,
506+
Flags<[FrontendOption]>,
507+
HelpText<"Enable experimental forward mode differentiation">;
508+
501509
def enable_experimental_additive_arithmetic_derivation :
502510
Flag<["-"], "enable-experimental-additive-arithmetic-derivation">,
503511
Flags<[FrontendOption]>,

include/swift/SIL/MemAccessUtils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ SingleValueInstruction *isAccessProjection(SILValue v);
7878
/// findAccessedStorage() on either \p v or the returned address.
7979
SILValue getAddressAccess(SILValue v);
8080

81-
/// Convenience for stripAccessMarkers(getAddressAccess(V)).
82-
SILValue getAccessedAddress(SILValue v);
81+
/// Convenience for stripAccessMarkers(getAddressAccess(v)).
82+
inline SILValue getAccessedAddress(SILValue v) {
83+
return stripAccessMarkers(getAddressAccess(v));
84+
}
8385

8486
/// Return true if \p accessedAddress points to a let-variable.
8587
///

include/swift/SIL/SILDifferentiabilityWitness.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class SILDifferentiabilityWitness
132132
bool isSerialized() const { return IsSerialized; }
133133
const DeclAttribute *getAttribute() const { return Attribute; }
134134

135+
/// Returns the `SILAutoDiffIndices` corresponding to this config's indices.
136+
// TODO(TF-893): This is a temporary shim for incremental removal of
137+
// `SILAutoDiffIndices`. Eventually remove this.
138+
SILAutoDiffIndices getSILAutoDiffIndices() const;
139+
135140
/// Verify that the differentiability witness is well-formed.
136141
void verify(const SILModule &module) const;
137142

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ PASS(CopyForwarding, "copy-forwarding",
120120
"Copy Forwarding to Remove Redundant Copies")
121121
PASS(CopyPropagation, "copy-propagation",
122122
"Copy propagation to Remove Redundant SSA Copies")
123+
PASS(Differentiation, "differentiation",
124+
"Automatic Differentiation")
123125
PASS(EpilogueARCMatcherDumper, "sil-epilogue-arc-dumper",
124126
"Print Epilogue retains of Returned Values and Argument releases")
125127
PASS(EpilogueRetainReleaseMatcherDumper, "sil-epilogue-retain-release-dumper",

0 commit comments

Comments
 (0)