|
22 | 22 | #include "toolchain/check/type_completion.h"
|
23 | 23 | #include "toolchain/parse/node_ids.h"
|
24 | 24 | #include "toolchain/sem_ir/constant.h"
|
| 25 | +#include "toolchain/sem_ir/cpp_overload_set.h" |
25 | 26 | #include "toolchain/sem_ir/file.h"
|
26 | 27 | #include "toolchain/sem_ir/ids.h"
|
27 | 28 | #include "toolchain/sem_ir/import_ir.h"
|
@@ -235,6 +236,9 @@ class ImportContext {
|
235 | 236 | return import_ir().facet_types();
|
236 | 237 | }
|
237 | 238 | auto import_functions() -> decltype(auto) { return import_ir().functions(); }
|
| 239 | + auto import_cpp_overload_sets() -> decltype(auto) { |
| 240 | + return import_ir().cpp_overload_sets(); |
| 241 | + } |
238 | 242 | auto import_generics() -> decltype(auto) { return import_ir().generics(); }
|
239 | 243 | auto import_identifiers() -> decltype(auto) {
|
240 | 244 | return import_ir().identifiers();
|
@@ -295,6 +299,9 @@ class ImportContext {
|
295 | 299 | return local_ir().facet_types();
|
296 | 300 | }
|
297 | 301 | auto local_functions() -> decltype(auto) { return local_ir().functions(); }
|
| 302 | + auto local_cpp_overload_sets() -> decltype(auto) { |
| 303 | + return local_ir().cpp_overload_sets(); |
| 304 | + } |
298 | 305 | auto local_generics() -> decltype(auto) { return local_ir().generics(); }
|
299 | 306 | auto local_identifiers() -> decltype(auto) {
|
300 | 307 | return local_ir().identifiers();
|
@@ -1837,26 +1844,40 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, InstT inst)
|
1837 | 1844 | resolver, {.type_id = SemIR::TypeType::TypeId, .inner_id = inner_id});
|
1838 | 1845 | }
|
1839 | 1846 |
|
1840 |
| -// TODO: This is a WIP attempt to solve the failing test |
1841 |
| -// https://github.com/carbon-language/carbon-lang/blob/508a88e2a995c9f3342b019cee6948c162004b68/toolchain/check/testdata/interop/cpp/import.carbon. |
1842 |
| -// Adding this method solves the failure `TryResolveInst on unsupported |
1843 |
| -// instruction kind CppOverloadSetType`. However there is a new failure |
1844 |
| -// `./toolchain/base/value_store.h:111: id.index < size_: inst27` and this still |
1845 |
| -// remains a WIP. |
| 1847 | +static auto GetLocalCppOverloadSet(ImportRefResolver& resolver, |
| 1848 | + SemIR::CppOverloadSetId cpp_overload_set_id) |
| 1849 | + -> SemIR::CppOverloadSet { |
| 1850 | + CARBON_CHECK(cpp_overload_set_id.has_value()); |
| 1851 | + |
| 1852 | + const auto& import_cpp_overload_set = |
| 1853 | + resolver.import_cpp_overload_sets().Get(cpp_overload_set_id); |
| 1854 | + return SemIR::CppOverloadSet{ |
| 1855 | + .name_id = GetLocalNameId(resolver, import_cpp_overload_set.name_id), |
| 1856 | + .parent_scope_id = GetLocalNameScopeId( |
| 1857 | + resolver, import_cpp_overload_set.parent_scope_id), |
| 1858 | + // THIS IS A PROBLEM. |
| 1859 | + .candidate_functions = import_cpp_overload_set.candidate_functions}; |
| 1860 | +} |
| 1861 | + |
1846 | 1862 | static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
1847 |
| - SemIR::CppOverloadSetType inst, |
1848 |
| - SemIR::InstId inst_id, SemIR::Inst untyped_inst) |
| 1863 | + SemIR::CppOverloadSetType inst) |
1849 | 1864 | -> ResolveResult {
|
1850 |
| - resolver.local_context().TODO(SemIR::LocId::None, |
1851 |
| - "Unsupported: Importing C++ functions that " |
1852 |
| - "require thunks indirectly called here"); |
1853 |
| - auto inst_constant_id = resolver.import_constant_values().Get(inst_id); |
1854 |
| - if (!inst_constant_id.is_constant()) { |
1855 |
| - CARBON_CHECK(untyped_inst.Is<SemIR::BindName>(), |
1856 |
| - "TryResolveInst on non-constant instruction {0}", inst); |
1857 |
| - return ResolveResult::Done(SemIR::ConstantId::NotConstant); |
| 1865 | + auto type_const_id = GetLocalConstantId(resolver, inst.type_id); |
| 1866 | + auto cpp_overload_set = |
| 1867 | + GetLocalCppOverloadSet(resolver, inst.overload_set_id); |
| 1868 | + auto specific_data = GetLocalSpecificData(resolver, inst.specific_id); |
| 1869 | + if (resolver.HasNewWork()) { |
| 1870 | + return ResolveResult::Retry(); |
1858 | 1871 | }
|
1859 |
| - return ResolveResult::Done(inst_constant_id); |
| 1872 | + |
| 1873 | + return ResolveAsDeduplicated<SemIR::CppOverloadSetType>( |
| 1874 | + resolver, |
| 1875 | + {.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId( |
| 1876 | + type_const_id), |
| 1877 | + .overload_set_id = |
| 1878 | + resolver.local_cpp_overload_sets().Add(cpp_overload_set), |
| 1879 | + .specific_id = |
| 1880 | + GetOrAddLocalSpecific(resolver, inst.specific_id, specific_data)}); |
1860 | 1881 | }
|
1861 | 1882 |
|
1862 | 1883 | static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
@@ -3182,7 +3203,7 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
|
3182 | 3203 | return TryResolveTypedInst(resolver, inst);
|
3183 | 3204 | }
|
3184 | 3205 | case CARBON_KIND(SemIR::CppOverloadSetType inst): {
|
3185 |
| - return TryResolveTypedInst(resolver, inst, inst_id, untyped_inst); |
| 3206 | + return TryResolveTypedInst(resolver, inst); |
3186 | 3207 | }
|
3187 | 3208 | case CARBON_KIND(SemIR::ExportDecl inst): {
|
3188 | 3209 | return TryResolveTypedInst(resolver, inst);
|
|
0 commit comments