dan-zheng
(Dan Zheng)
October 2, 2018, 11:02pm
10
Thanks for suggestions on staging the implementation! I agree that incremental work is good.
However, the blocker I encountered 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:
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.