We should focus on 'training" swift's code completion to suggest a new symbol to take precedence over an imported discouraged symbol when importing a new package.
There are a couple of issues that would need to be addressed:
- How do we "train" the code completion logic to pick an implementation over another?
- Raise the precedence of some symbols in overloading resolution implicitly via the same mechanism so that when somebody calls a symbol with that name then it gets picked up by a "shim" library that was imported.
- We still need a way to disambiguate overloads on the call site (out of scope)
Intellisence allows custom training that could function in a similar way as the bellow suggestions but instead of arbitrary being able to train code completion we would sort of "tag" our preference using an attributed.
We can address 1 and 2 with an attribute that will inform the overload resolution and code completion that should take precedence:
@symbolPrecedence(overloadRename: "mapping(_:)", higherThan: Swift , lowerThan: OtherLib)
- overloadRename: The name of an method similar to the rename property
- higherThan, lowerThan : a library name that would function in a similar way as "Precedence Group Declaration" . Hopefully this can be strongly typed in some form via import
Imagine I wanted to create new package that contains all the new suggested name changes, lets call this package SwiftBoost.
\\ SwiftBoost Library
import Swift
import OtherLib
extension CollectionOrArrayEtc {
...
@available(swift 5.3)
@symbolPrecedence(overloadRename: "mapping(_:)", higherThan: Swift , lowerThan: OtherLib)
@inlinable public func mapping<T>(_ transform: (Character) throws -> T) rethrows -> [T] { ... }
@symbolPrecedence higherThan: Swift , lowerThan: OtherLib)
@available(*, deprecated: 5.3, renamed: "mapping(_:)", message: "Please use mapping")
@inlinable public func map<T>(_ transform: (Character) throws -> T) rethrows -> [T] { ... }
...
}
// New Lib ABC
import SwiftBoost
var someArray = ...
someArray.mapping(...)
In ABC when I start typing map, the symbol mapping should be the first choice on code completion.
some.map(...)
In ABC if I were to choose map anyway then I will get a warning that is coming from SwiftBoost.
some.Swift::map(...)
some.SwiftBoost::map(...)
It would be really helpful if we could disambiguate which package the symbol is being picked up.
Reference:
https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID380