-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] Mangle @differentiable
function types.
#25804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AutoDiff] Mangle @differentiable
function types.
#25804
Conversation
include/swift/ABI/MetadataValues.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using a single DifferentiabilityMask
, similar to the one in AnyFunctionType::ExtInfo
:
DifferentiabilityMask = 0xF8000000U,
DifferentiabilityShift = 24U
But I didn't figure out how to make it work all the way. Things are tricky because the mask is F8
instead of FF
, which requires extra bitshifting.
docs/ABI/Mangling.rst
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you differentiate between @differentiable @convention(thin)
and @differentiable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Currently, modifiers like @convention(thin)
and @differentiable
have their own function type demangle node variant:
Modifier | Demangle node kind |
---|---|
- |
NoEscapeFunctionType |
@escaping |
FunctionType (escaping) |
@autoclosure |
AutoClosureType |
@escaping @autoclosure |
EscapingAutoClosureType |
... | ... |
Here's what it looks like:
$ $SWIFT_BIN/swift-demangle --expand sS2fXfD
Demangling for $sS2fXfD
kind=Global
kind=TypeMangling
kind=Type
kind=ThinFunctionType
kind=ArgumentTuple
kind=Type
kind=Structure
kind=Module, text="Swift"
kind=Identifier, text="Float"
kind=ReturnType
kind=Type
kind=Structure
kind=Module, text="Swift"
kind=Identifier, text="Float"
$sS2fXfD ---> @convention(thin) (Swift.Float) -> Swift.Float
This leads to an explosion of demangle node kinds for combinations of modifiers.
A more reflexible representation would be to have a single FunctionType
demangle node kind, with modifier nodes as children in a list. Dummy view:
kind=FunctionType
kind=FunctionTypeModifiers
kind=ThinFunction
kind=EscapingFunction
kind=DifferentiableFunction
kind=ArgumentTuple
kind=Type
kind=Structure
kind=Module, text="Swift"
kind=Identifier, text="Float"
kind=ReturnType
kind=Type
kind=Structure
kind=Module, text="Swift"
kind=Identifier, text="Float"
Changing the mangling scheme certainly seems breaking though. The significance of type mangling isn't exactly clear to me: I imagine LLDB uses this mangling to show types of variables. Perhaps it's not important to capture all combinations of function type modifiers, only the semantically important ones (@differentiable
is probably more semantically heavy than @escaping
).
Started a discussion at https://forums.swift.org/t/questions-about-function-type-mangling/26360.
@swift-ci Please clean test tensorflow |
220f45d
to
32273b1
Compare
- Mangle `@differentiable` and `@differentiable(linear)` function types, both escaping and non-escaping variants. - Add `FunctionMetadataDifferentiabilityKind` to MetadataValues.h. Use it in `TargetFunctionTypeFlags` to represent differentiable/linear functions. - Add TypeDecoder tests.
32273b1
to
3c1f021
Compare
@swift-ci Please test tensorflow |
@differentiable
and@differentiable(linear)
function types,both escaping and non-escaping variants.
TargetFunctionTypeFlags
to represent linear functions.TypeDecoder
tests.