SR-12802: Disambiguate functions with lvalue and rvalue reference parameters in the same overload set

Hey everyone, I have spent some time investigating SR-12802, and have created this patch:

The idea is to check for rvalue references, and allow the overload to always pass by value. However I don't know if this is a viable approach (or maybe there is something wrong in my local environment?) and am looking for feedback/ideas.

I have specifically worked on this based on the push_back method import, and the overload that is used for vector. With this patch, it allows to pass by value, however when updating the tests I get a crash (segmentation fault).

tests output:

[ RUN      ] StdVector.init
[       OK ] StdVector.init
[ RUN      ] StdVector.push back
stderr>>> CRASHED: SIGSEGV
the test crashed unexpectedly
[     FAIL ] StdVector.push back
[ RUN      ] StdVector.map
stderr>>> CRASHED: SIGSEGV
the test crashed unexpectedly
[     FAIL ] StdVector.map
StdVector: Some tests failed, aborting
UXPASS: []
FAIL: ["push back", "map"]
SKIP: []

Here is the output for swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Interop/Cxx/stdlib/Output/use-std-vector.swift.tmp/a.out --stdlib-unittest-in-process --stdlib-unittest-filter "push_back"

objc[69006]: Class _TtCs25CheckedContinuationCanary is implemented in both /usr/lib/swift/libswift_Concurrency.dylib (0x20ced5ee0) and swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift/macosx/libswift_Concurrency.dylib (0x1031d48d0). One of the two will be used. Which one is undefined.
objc[69006]: Class _TtCs17DispatchQueueShim is implemented in both /usr/lib/swift/libswift_Concurrency.dylib (0x20ced5f70) and /swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift/macosx/libswift_Concurrency.dylib (0x1031d4960). One of the two will be used. Which one is undefined.
objc[69006]: Class _TtCs9MainActor is implemented in both /usr/lib/swift/libswift_Concurrency.dylib (0x20ced6000) and /swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/swift/macosx/libswift_Concurrency.dylib (0x1031d49f8). One of the two will be used. Which one is undefined.
StdlibUnittest: using filter: push back
[ RUN      ] StdVector.push back
check failed at /swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector.swift, line 30
first:  0 (of type Swift.Int32)
second: 42 (of type Swift.Int32)
[     FAIL ] StdVector.push back
StdVector: Some tests failed, aborting
UXPASS: []
FAIL: ["push back"]
SKIP: []

Thank you!

Turns out I missed a check in SILFunctionType.cpp however still trying to figure out the best way to approach this:

  // Pass C++ const reference types indirectly. 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: rdar://89647503
  if (clangTy->isReferenceType() &&
      clangTy->getPointeeType().isConstQualified())
    return true;

The comment says we want to pass const references indirectly, from my understanding we should also pass rvalue references indirectly. So by doing:

    if (clangTy->isReferenceType() ||
        clangTy->getPointeeType().isConstQualified()) {
        return true;
    }

This seems to work for vector however I still have the same issue with iterator and several other tests:

Failed Tests (12):
  Swift(macosx-arm64) :: Interop/Cxx/class/method/ambiguous-methods-module-interface.swift
  Swift(macosx-arm64) :: Interop/Cxx/class/method/ambiguous-methods.swift
  Swift(macosx-arm64) :: Interop/Cxx/reference/reference-irgen.swift
  Swift(macosx-arm64) :: Interop/Cxx/reference/reference-module-interface.swift
  Swift(macosx-arm64) :: Interop/Cxx/reference/reference-silgen.swift
  Swift(macosx-arm64) :: Interop/Cxx/reference/reference.swift
  Swift(macosx-arm64) :: Interop/Cxx/stdlib/use-std-iterator.swift
  Swift(macosx-arm64) :: Interop/Cxx/templates/defaulted-template-type-parameter.swift
  Swift(macosx-arm64) :: Interop/Cxx/templates/dependent-types.swift
  Swift(macosx-arm64) :: Interop/Cxx/templates/function-template.swift
  Swift(macosx-arm64) :: Interop/Cxx/templates/member-templates-silgen.swift
  Swift(macosx-arm64) :: Interop/Cxx/templates/template-type-parameter-not-in-signature.swift


Testing Time: 52.75s
  Unsupported:  15
  Passed     : 226
  Failed     :  12

continued here: Importing of r value references overrides other imports that should be imported using references in SR-12802