# Amend SE-0216 Dynamic Callable: Reduce Overloads

**URL:** <https://forums.swift.org/t/amend-se-0216-dynamic-callable-reduce-overloads/16639>\
**Category:** Pitches\
**Created:** [October 2, 2018, 6:48pm UTC](https://forums.swift.org/t/amend-se-0216-dynamic-callable-reduce-overloads/16639 "2018-10-02T18:48:55Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![dan-zheng](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dan-zheng/32/2534_2.png) [@dan-zheng](https://forums.swift.org/u/dan-zheng)\
**Post date:** [October 2, 2018, 11:02pm UTC](https://forums.swift.org/t/amend-se-0216-dynamic-callable-reduce-overloads/16639/10 "2018-10-02T23:02:10Z")

</div>

Thanks for suggestions on staging the implementation! I agree that incremental work is good.  
However, the [blocker I encountered](https://github.com/apple/swift/pull/16980#issuecomment-423710872) prevents step #1 from being implemented (visit the link for the full explanation):

> [@dan-zheng](#):
>
> One problem is that dynamic calls are not a pure syntactic sugar. Original call expressions have a tuple of multiple arguments (e.g. `x(1, 2)`), but the `dynamicallyCall` methods expect a single argument of array type (e.g. `x.dynamicallyCall(withArguments: [1, 2])`.
> 
> Thus, when the solver iterates over the options in the disjunction and tries to simplify the `($T5) -> $T3 applicable fn $T4` constraint, there is a crash in `matchCallArguments` because `x(1, 2)` does not fit the expected form `x.dynamicallyCall(WithArguments: [1, 2])`. The call site has two empty labels but the method has one label:
> 
> ```swift
> Assertion failed: (params.size() == labels.size()), function relabelParams, file /Users/dan/swift-build/swift/lib/AST/ASTContext.cpp, line 3623.
> Stack dump:
> ...
> swift::AnyFunctionType::relabelParams(llvm::MutableArrayRef<swift::AnyFunctionType::Param>, llvm::ArrayRef<swift::Identifier>) + 119
> swift::constraints::matchCallArguments(swift::constraints::ConstraintSystem&, bool, llvm::ArrayRef<swift::AnyFunctionType::Param>, llvm::ArrayRef<swift::AnyFunctionType::Param>, swift::constraints::ConstraintLocatorBuilder) + 1616
> swift::constraints::ConstraintSystem::simplifyApplicableFnConstraint(swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 1574
> swift::constraints::ConstraintSystem::simplifyConstraint(swift::constraints::Constraint const&) + 1150
> swift::constraints::ConstraintSystem::simplify(bool) + 210
> swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&) + 83
> swift::constraints::DisjunctionChoice::solve(llvm::SmallVectorImpl<swift::constraints::Solution>&) + 113
> swift::constraints::ConstraintSystem::solveForDisjunctionChoices(swift::constraints::Disjunction&, llvm:)
> 
> ```
> 
> I'm not sure how to work around this. One bad idea is to add a special case to `matchCallArguments` for resolving dynamic calls, but even this is difficult because when the solver iterates over the disjunction and tries to simplify the `($T5) -> $T3 applicable fn $T4` constraint, it's not known whether the call is a dynamic call or not.

I need some guidance on working around this blocker. Perhaps I should ask for help on a new thread.

---

_[View the full topic](https://forums.swift.org/t/amend-se-0216-dynamic-callable-reduce-overloads/16639)._
