C++ interop: support for default arguments. (#6108)

The general strategy here is to force use of a thunk when we want to use
default arguments, and have Clang generate uses of the default arguments
on its side of the thunk.

To support this, change the key type used in `clang_decls` from being
just a `Decl*` to being a pair of `Decl*` and number of parameters in
the case of function decls. Import distinct `SemIR::Function`s for each
number of parameters that's used, and corresponding distinct thunks.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2025-09-24 01:07:59 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 82679e6689
commit 1e7b7e53ae
42 changed files with 2097 additions and 720 deletions
+20 -20
View File
@@ -486,10 +486,10 @@ fn F() {
// CHECK:STDOUT: --- fail_import_decl_value_param_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -498,8 +498,8 @@ fn F() {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @<null name> [concrete = constants.%empty_struct]
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
@@ -516,10 +516,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %U.val: %U = struct_value () [concrete]
// CHECK:STDOUT: %ptr.86f: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo__carbon_thunk.type: type = fn_type @foo__carbon_thunk [concrete]
@@ -536,8 +536,8 @@ fn F() {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
@@ -573,10 +573,10 @@ fn F() {
// CHECK:STDOUT: --- fail_import_definition_single_data_member_value_param_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @As.Convert [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -585,8 +585,8 @@ fn F() {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @As.Convert [concrete = constants.%empty_struct]
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
@@ -603,10 +603,10 @@ fn F() {
// CHECK:STDOUT: --- fail_import_definition_multiple_data_members_value_param_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @As.Convert [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -615,8 +615,8 @@ fn F() {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @As.Convert [concrete = constants.%empty_struct]
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
@@ -634,10 +634,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %U.val: %U = struct_value () [concrete]
// CHECK:STDOUT: %pattern_type.eb9: type = pattern_type %U [concrete]
// CHECK:STDOUT: %ptr.87e: type = ptr_type %U [concrete]
@@ -655,12 +655,12 @@ fn F() {
// CHECK:STDOUT: .N = %N
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %N: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
@@ -716,10 +716,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.92e: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.92e = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %U.val: %U = struct_value () [concrete]
// CHECK:STDOUT: %ptr.8c1: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo__carbon_thunk.type: type = fn_type @foo__carbon_thunk [concrete]
@@ -740,12 +740,12 @@ fn F() {
// CHECK:STDOUT: .N2 = %N2
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %.218: %.92e = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %N2: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.218: %.92e = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
@@ -785,11 +785,11 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %O: type = class_type @O [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %O: type = class_type @O [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %U.val: %U = struct_value () [concrete]
// CHECK:STDOUT: %ptr.a6c: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo__carbon_thunk.type: type = fn_type @foo__carbon_thunk [concrete]
@@ -811,9 +811,9 @@ fn F() {
// CHECK:STDOUT: .O = %O.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %O.decl: type = class_decl @O [concrete = constants.%O] {} {}
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
@@ -936,10 +936,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo__carbon_thunk [concrete]
// CHECK:STDOUT: %empty_struct.109: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %U.val: %U = struct_value () [concrete]
// CHECK:STDOUT: %ptr.86f: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo__carbon_thunk.type: type = fn_type @foo__carbon_thunk [concrete]
@@ -960,8 +960,8 @@ fn F() {
// CHECK:STDOUT: .U = %U.decl
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %.a21: %.c5d = cpp_overload_set_value @foo__carbon_thunk [concrete = constants.%empty_struct.109]
// CHECK:STDOUT: %U.decl: type = class_decl @U [concrete = constants.%U] {} {}
// CHECK:STDOUT: %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
@@ -1076,9 +1076,9 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %ptr.86f: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo__carbon_thunk.type: type = fn_type @foo__carbon_thunk [concrete]
// CHECK:STDOUT: %foo__carbon_thunk: %foo__carbon_thunk.type = struct_value () [concrete]
@@ -1123,9 +1123,9 @@ fn F() {
// CHECK:STDOUT: --- import_decl_pointer_return_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %ptr: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]
@@ -1155,9 +1155,9 @@ fn F() {
// CHECK:STDOUT: --- import_definition_pointer_return_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %.c5d: type = cpp_overload_set_type @foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c5d = struct_value () [concrete]
// CHECK:STDOUT: %U: type = class_type @U [concrete]
// CHECK:STDOUT: %ptr: type = ptr_type %U [concrete]
// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]