Hello,
I have been working on a PR to start the work on issue SR-12802: Disambiguate functions with lvalue and rvalue reference parameters in the same overload set. I have made some progress however I am looking for some suggestions/feedback for how to resolve a few issues around Cxx/Intrerop/tests:
Here’s a brief overview:
//In ImportType.cpp - Checking to if param is inout:
//Checking if the type is non const l value
paramTy = refType->getPointeeType();
if (isa<clang::LValueReferenceType>(paramTy) &&
!paramTy.isConstQualified()) {
isInOut = true;
}
Which gives us the desired import for push_back
overload
C++:
void push_back (value_type&& val);
Swift:
mutating func push_back(_ /__x/: std.__1.__CxxTemplateInstNSt3__16vectorIdNS_9allocatorIdEEEE.value_type)
We then update the SIL to pass const references indirectly :
//In SILFunctionType:
if (clangTy->isReferenceType()) {
if (clangTy->getPointeeType().isConstQualified() ||
clangTy->isRValueReferenceType()) {
return true;
}
}
Side note:
Right now there's no way to express immutable borrowed params, so we have to have this hack. Eventually, we should just express these correctly:
This solution generally solves the issue stated for passing rvalue refs by value, however I have been stuck trying to update the tests. For example in Interop/Cxx/class/method/ambiguous-methods.swift
there are a two tests that are failing:
Out Param Increment: (Int, Int, inout Int) -> Void
Inout Param Increment: (inout Int, Int) -> Void
It comes down to how the methods being imported with these changes. So for Out Param Increment: (Int, Int, inout Int) -> Void
C++:
void increment(int a, int b, int &c) const {
c = a + b;
}
Swift:
func increment(_ a: Int32, _ b: Int32, _ c: Int32)
So with the current changes, namely the check in ImportType.cpp
the Check for non const and l value also transforms this method but it should be imported as inout
.
So it seems like there should be another check for the import type? Or is there something else I am missing?