swift
Fix two issues related with emission of differentiability witnesses
#80983
Open

Fix two issues related with emission of differentiability witnesses #80983

asl wants to merge 6 commits into main from 59135-fix
asl
asl97 days ago
  1. When differentiable nested function (closure) is specialized by capture promotion pass ensure we generate a differentiability witness for the specialized function as well. Ensure the original witness is removed if the original function becomes dead.
  2. Differentiability witnesses for a function could originate either from its @differentiable attribute or from explicit @derivative(of:) attribute on the derivative. In the latter case the derivative itself might not be emitted, while original function is (e.g. original function is @inlineable, but derivative is @usableFromInline). Previously both cases were handled only when function body was emitted. As a result we missed witness in the aforementioned case. Ensure the differentiability witness originating from @derivative(of:) is emitted even if we're not going to emit body of the derivative.

Fixes #59135

asl asl requested a review from rxwei rxwei 97 days ago
asl asl requested a review from eeckstein eeckstein 97 days ago
asl asl requested a review from jckarter jckarter 97 days ago
asl
asl97 days ago

@swift-ci please test

asl
asl97 days ago (edited 97 days ago)

Linux build seems to be broken due to unrelated issue:

... lib/libFoundationInternationalization.so  lib/libFoundationEssentials.so  lib/lib_FoundationCollections.a  lib/lib_FoundationCShims.a  lib/lib_FoundationICU.so  /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/libswiftDispatch.so  /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/libdispatch.so  /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/libBlocksRuntime.so  -lgcc  -lgcc_s  -lc  -lgcc  -lgcc_s && :
error: link command failed with exit code 1 (use -v to see invocation)
Sources/plutil/CMakeFiles/plutil.dir/PLUContext_KeyPaths.swift.o:main.swift.o:function $sSS6plutilE19escapedKeyPathSplitSaySSGyF: error: undefined reference to '$sSy12RegexBuilderSs11SubSequenceRtzrlE5split9separator9maxSplits25omittingEmptySubsequencesSaySsGSS_SiSbtF'

Windows too:

FAILED: bin/FoundationInternationalization.dll lib/FoundationInternationalization.lib 
C:\Windows\system32\cmd.exe /C "cd . && T:\5\bin\swiftc.exe -target x86_64-unknown-windows-msvc -j 36 -num-threads 36 -emit-library -sdk "T:/Program Files/Swift/Platforms/Windows.platform/Developer/SDKs/Windows.sdk" -gnone -Xlinker /INCREMENTAL:NO -Xlinker /OPT:REF -Xlinker /OPT:ICF -O -libc MD   -Xlinker -implib:lib\FoundationInternationalization.lib   -o bin\FoundationInternationalization.dll @CMakeFiles\FoundationInternationalization.rsp && cd ."
<unknown>:0: warning: using (deprecated) legacy driver, Swift installation does not contain swift-driver at: 'C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\build\5\bin\swift-driver-new.exe'
   Creating library lib\FoundationInternationalization.lib and object lib\FoundationInternationalization.exp
ICUDateFormatter.swift.obj : error LNK2019: unresolved external symbol __imp_$sSy12RegexBuilderSs11SubSequenceRtzrlE5split9separator9maxSplits25omittingEmptySubsequencesSaySsGSS_SiSbtF referenced in function $s20FoundationEssentials4DateV0A20InternationalizationE11FormatStyleV0C15FieldCollectionV14updateScheduleAD16ICUDateFormatterC0cE4InfoV06UpdateJ0Ovg
ICUDateFormatter.swift.obj : error LNK2019: unresolved external symbol __imp_$sSS17_StringProcessing14RegexComponent0C7BuilderMc referenced in function $sS2S17_StringProcessing14RegexComponent0C7BuilderWl
Duration+UnitsFormatStyle.swift.obj : error LNK2001: unresolved external symbol __imp_$sSS17_StringProcessing14RegexComponent0C7BuilderMc

TimeZone_ICU.swift.obj : error LNK2001: unresolved external symbol __imp_$sSS17_StringProcessing14RegexComponent0C7BuilderMc
asl asl added AutoDiff
asl
asl90 days ago

@swift-ci please test

asl
asl87 days ago

@swift-ci please test

asl asl force pushed from 8dc69e77 to 43c17531 70 days ago
asl
asl70 days ago

@swift-ci please test

asl
asl68 days ago

@swift-ci please test windows platform

asl
asl55 days ago

@swift-ci please test windows platform

JaapWijnen
JaapWijnen31 days ago

I'm running into this one more often nowadays. Would be great if we could move this PR forward. Is there anything left to do to make the windows tests pass?

asl
asl31 days ago

@JaapWijnen windows was just broken on main IIRC.

asl
asl31 days ago

@swift-ci please test windows platform

asl asl force pushed from 43c17531 to 9c04e625 31 days ago
asl
asl31 days ago

@swift-ci please test

asl
asl30 days ago

@swift-ci please test macos platform

asl
asl28 days ago❤ 1

@swift-ci please test macos platform

JaapWijnen
JaapWijnen27 days ago

I'd love to get this merged and perhaps we can still cherry pick this into 6.2? @clackary

clackary
clackary commented on 2025-07-02
Conversation is marked as resolved
Show resolved
test/AutoDiff/compiler_crashers_fixed/issue-59135-usableFromInline-VJP.swift
3
4// The original function Tensor.subscriptIndexPath() is not marked as @differentiable. As a result, no explicit differentiable witness is generated for it.
5// However, the witness is generated as a side effect of providing a derivative via @derivative(of: subscriptIndexPath) on _vjpSubscriptIndexPath.
6
// Since _vjpSubscriptIndexPath is not emitted when -emit-module is used, we need to ensure we still generate a wittness.
clackary26 days ago
Suggested change
// Since _vjpSubscriptIndexPath is not emitted when -emit-module is used, we need to ensure we still generate a wittness.
// Since _vjpSubscriptIndexPath is not emitted when -emit-module is used, we need to ensure we still generate a witness.

typo

asl
asl26 days ago

@eeckstein @jckarter Any objections on this PR?

asl
asl26 days ago

@swift-ci please test

asl
asl25 days ago

@swift-ci please test

asl
asl21 days ago

@swift-ci please test windows platform

asl
asl17 days ago
asl Ensure we create differentiability witness when the closure is specia…
516200c1
asl Drop differentiability witnesses for dead functions for which bodies …
cc45d6aa
asl Emit differentiability witness originating from custom derivative dec…
8f5f33b5
asl Add tests
34274afa
asl Try to pacify Windows
fa176ab9
asl Typo
14d53734
asl asl force pushed from 6d391e45 to 14d53734 5 days ago
asl
asl5 days ago

@swift-ci please test

Login to write a write a comment.

Login via GitHub

Assignees
No one assigned
Labels
Milestone