-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Fix crash during generic curry thunk cloning. #26404
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
Conversation
Create simple `BasicTypeSubstCloner` inheriting from `TypeSubstCloner`. Use `BasicTypeSubstCloner` to clone generic curry thunks, remapping types. Resolves TF-688.
@swift-ci Please test tensorflow |
void run() { | ||
auto &target = Builder.getFunction(); | ||
auto *entry = target.createBasicBlock(); | ||
createEntryArguments(&target); |
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.
SILCloner already knows how to clone function arguments. I’ve been leaning towards getting rid of ‘createEntryArguments’ instead of using it in more places.
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.
All you need to overload in your new class is type remapping. No need to define a ‘run()’ or to overload ‘postProcess()’ or ‘visit()’.
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.
My notes:
SILCloner::cloneFunction
does clone function arguments, but is not suitable forTypeSubstCloner
because it does not remap argument types.- Perhaps a good patch would be to add something like
TypeSubstCloner::cloneFunction
upstream that doesBasicTypeSubstCloner::run()
. AFAIK currently all subclasses duplicate the same "create entry and function arguments" logic. For now, I definedBasicTypeSubstCloner::run()
for convenience.
- Perhaps a good patch would be to add something like
- Overriding
TypeSubstCloner::postProcess
is necessary:void postProcess(SILInstruction *Orig, SILInstruction *Cloned) { llvm_unreachable("Clients need to explicitly call a base class impl!"); }
- Not overriding
TypeSubstCloner::visit
is fine, thanks!
Please let me know if you have suggestions.
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.
Great. It’d be good to include what the original problem was and this context in the PR message.
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.
Updated PR description, thanks!
@swift-ci Please test tensorflow |
Create simple
BasicTypeSubstCloner
inheriting fromTypeSubstCloner
.Use
BasicTypeSubstCloner
to clone generic curry thunks, remapping types.Resolves TF-688.
Context:
The reproducer above crashes during the differentiation transform (
ADContext::promoteToDifferentiableFunction
) because curry thunks were cloned usingSILFunctionCloner
without accounting for generics.With this patch, curry thunk cloning handles generics correctly by setting the new thunk's generic environment and remapping types with a
TypeSubstCloner
subclass.