Overload Resolution


(Toni Suter) #1

Hi,

Does someone know a good explanation / summary of Swift's overload resolution rules?
After reading https://github.com/apple/swift/blob/master/docs/TypeChecker.rst I understand
that the overloading resolution happens as part of the constraint solving step in the type
checker, but maybe there's a document somewhere, that explains the rules in more detail?

Thanks and best regards,
Toni


(Mark Lacey) #2

I don’t know of any existing documentation for overload resolution. I was hoping to find some time to write something up in the next few months, but I’m not sure exactly when I might get to it.

In the meantime the best advice I can give is to dig into the code a bit to understand what’s going on. The type checker runs the constraint solver and collections all applicable solutions, and then compares these solutions to find a winner. That step is done in ConstraintSystem::findBestSolution() in CSRanking.cpp. That calls into ConstraintSystem::compareSolutions(), which is where most of the specific logic is. It checks overloads, and then checks the specific type bindings in each solution.

That code is reasonably well documented, so even without knowing a lot about the compiler internals I think it shouldn’t be too hard to follow.

Mark

···

On Oct 6, 2016, at 4:53 AM, Toni Suter via swift-users <swift-users@swift.org> wrote:

Hi,

Does someone know a good explanation / summary of Swift's overload resolution rules?
After reading https://github.com/apple/swift/blob/master/docs/TypeChecker.rst I understand
that the overloading resolution happens as part of the constraint solving step in the type
checker, but maybe there's a document somewhere, that explains the rules in more detail?


(Mark Lacey) #3

Hi,

Does someone know a good explanation / summary of Swift's overload resolution rules?
After reading https://github.com/apple/swift/blob/master/docs/TypeChecker.rst I understand
that the overloading resolution happens as part of the constraint solving step in the type
checker, but maybe there's a document somewhere, that explains the rules in more detail?

I don’t know of any existing documentation for overload resolution. I was hoping to find some time to write something up in the next few months, but I’m not sure exactly when I might get to it.

In the meantime the best advice I can give is to dig into the code a bit to understand what’s going on. The type checker runs the constraint solver and collections

^^^ collects

···

On Oct 6, 2016, at 7:31 AM, Mark Lacey <mark.lacey@apple.com> wrote:

On Oct 6, 2016, at 4:53 AM, Toni Suter via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

all applicable solutions, and then compares these solutions to find a winner. That step is done in ConstraintSystem::findBestSolution() in CSRanking.cpp. That calls into ConstraintSystem::compareSolutions(), which is where most of the specific logic is. It checks overloads, and then checks the specific type bindings in each solution.

That code is reasonably well documented, so even without knowing a lot about the compiler internals I think it shouldn’t be too hard to follow.

Mark


(Toni Suter) #4

Hi Mark,

Thanks for pointing me into the right direction!

Best regards,
Toni

···

Am 06.10.2016 um 16:31 schrieb Mark Lacey <mark.lacey@apple.com>:

On Oct 6, 2016, at 4:53 AM, Toni Suter via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

Hi,

Does someone know a good explanation / summary of Swift's overload resolution rules?
After reading https://github.com/apple/swift/blob/master/docs/TypeChecker.rst I understand
that the overloading resolution happens as part of the constraint solving step in the type
checker, but maybe there's a document somewhere, that explains the rules in more detail?

I don’t know of any existing documentation for overload resolution. I was hoping to find some time to write something up in the next few months, but I’m not sure exactly when I might get to it.

In the meantime the best advice I can give is to dig into the code a bit to understand what’s going on. The type checker runs the constraint solver and collections all applicable solutions, and then compares these solutions to find a winner. That step is done in ConstraintSystem::findBestSolution() in CSRanking.cpp. That calls into ConstraintSystem::compareSolutions(), which is where most of the specific logic is. It checks overloads, and then checks the specific type bindings in each solution.

That code is reasonably well documented, so even without knowing a lot about the compiler internals I think it shouldn’t be too hard to follow.

Mark