Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions toolchain/check/eval_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ auto EvalConstantInst(Context& context, SemIR::Converted inst)
context.constant_values().Get(inst.result_id));
}

// TODO: This should not be necessary since the constant kind is
// WheneverPossible.
auto EvalConstantInst(Context& /*context*/, SemIR::CppOverloadSetValue inst)
-> ConstantEvalResult {
return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
.type_id = inst.type_id, .elements_id = SemIR::InstBlockId::Empty});
}

auto EvalConstantInst(Context& /*context*/, SemIR::Deref /*inst*/)
-> ConstantEvalResult {
// TODO: Handle this.
Expand Down
30 changes: 21 additions & 9 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1845,24 +1845,33 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, InstT inst)
resolver, {.type_id = SemIR::TypeType::TypeId, .inner_id = inner_id});
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::CppOverloadSetType inst)
-> ResolveResult {
static auto HandleUnsupportedCppOverloadSet(ImportRefResolver& resolver,
SemIR::CppOverloadSetId id) {
// Supporting C++ overload resolution of imported functions is a large task,
// which might require serializing and deserializing AST for using decl ids,
// using modules and/or linking ASTs.
resolver.local_context().TODO(
SemIR::LocId::None,
llvm::formatv("Unsupported: Importing C++ function `{0}` indirectly",
resolver.import_ir().names().GetAsStringIfIdentifier(
resolver.import_ir()
.cpp_overload_sets()
.Get(inst.overload_set_id)
.name_id)));
llvm::formatv(
"Unsupported: Importing C++ function `{0}` indirectly",
resolver.import_ir().names().GetAsStringIfIdentifier(
resolver.import_ir().cpp_overload_sets().Get(id).name_id)));
return ResolveResult::Done(SemIR::ErrorInst::ConstantId,
SemIR::ErrorInst::InstId);
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::CppOverloadSetType inst)
-> ResolveResult {
return HandleUnsupportedCppOverloadSet(resolver, inst.overload_set_id);
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::CppOverloadSetValue inst)
-> ResolveResult {
return HandleUnsupportedCppOverloadSet(resolver, inst.overload_set_id);
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::ExportDecl inst) -> ResolveResult {
auto value_id = GetLocalConstantId(resolver, inst.value_id);
Expand Down Expand Up @@ -3188,6 +3197,9 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
case CARBON_KIND(SemIR::CppOverloadSetType inst): {
return TryResolveTypedInst(resolver, inst);
}
case CARBON_KIND(SemIR::CppOverloadSetValue inst): {
return TryResolveTypedInst(resolver, inst);
}
case CARBON_KIND(SemIR::ExportDecl inst): {
return TryResolveTypedInst(resolver, inst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn G(x: Cpp.X) {
// CHECK:STDOUT: inst36: {kind: NameRef, arg0: name0, arg1: inst16, type: type(inst(NamespaceType))}
// CHECK:STDOUT: inst37: {kind: CppOverloadSetType, arg0: cpp_overload_set0, arg1: specific<none>, type: type(TypeType)}
// CHECK:STDOUT: inst38: {kind: CppOverloadSetValue, arg0: cpp_overload_set0, type: type(inst37)}
// CHECK:STDOUT: inst39: {kind: StructValue, arg0: inst_block_empty, type: type(inst37)}
// CHECK:STDOUT: inst39: {kind: CppOverloadSetValue, arg0: cpp_overload_set0, type: type(inst37)}
// CHECK:STDOUT: inst40: {kind: NameRef, arg0: name4, arg1: inst38, type: type(inst37)}
// CHECK:STDOUT: inst41: {kind: FunctionDecl, arg0: function1, arg1: inst_block_empty, type: type(inst42)}
// CHECK:STDOUT: inst42: {kind: FunctionType, arg0: function1, arg1: specific<none>, type: type(TypeType)}
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/testdata/interop/cpp/builtins.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ fn F() {
// CHECK:STDOUT: %u32: type = class_type @UInt, @UInt(%int_32) [concrete]
// CHECK:STDOUT: %pattern_type.4a9: type = pattern_type %u32 [concrete]
// CHECK:STDOUT: %.15a: type = cpp_overload_set_type @unsigned_int.foo [concrete]
// CHECK:STDOUT: %empty_struct: %.15a = struct_value () [concrete]
// CHECK:STDOUT: %.afb: %.15a = cpp_overload_set_value @unsigned_int.foo [concrete]
// CHECK:STDOUT: %ptr.d47: type = ptr_type %unsigned_int [concrete]
// CHECK:STDOUT: %unsigned_int.foo.type: type = fn_type @unsigned_int.foo [concrete]
// CHECK:STDOUT: %unsigned_int.foo: %unsigned_int.foo.type = struct_value () [concrete]
Expand All @@ -566,7 +566,7 @@ fn F() {
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %unsigned_int.decl: type = class_decl @unsigned_int [concrete = constants.%unsigned_int] {} {}
// CHECK:STDOUT: %.afb: %.15a = cpp_overload_set_value @unsigned_int.foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.afb: %.15a = cpp_overload_set_value @unsigned_int.foo [concrete = constants.%.afb]
// CHECK:STDOUT: %unsigned_int.foo.decl: %unsigned_int.foo.type = fn_decl @unsigned_int.foo [concrete = constants.%unsigned_int.foo] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
Expand All @@ -590,7 +590,7 @@ fn F() {
// CHECK:STDOUT: %x.patt: %pattern_type.4a9 = binding_pattern x [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT: %unsigned_int.ref.loc13: ref %unsigned_int = name_ref unsigned_int, %unsigned_int
// CHECK:STDOUT: %foo.ref: %.15a = name_ref foo, imports.%.afb [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo.ref: %.15a = name_ref foo, imports.%.afb [concrete = constants.%.afb]
// CHECK:STDOUT: %bound_method.loc13: <bound method> = bound_method %unsigned_int.ref.loc13, %foo.ref
// CHECK:STDOUT: %addr.loc13: %ptr.d47 = addr_of %unsigned_int.ref.loc13
// CHECK:STDOUT: %unsigned_int.foo.call: init %u32 = call imports.%unsigned_int.foo.decl(%addr.loc13)
Expand Down
12 changes: 6 additions & 6 deletions toolchain/check/testdata/interop/cpp/class/access.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ fn F() {
// CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %.177: type = cpp_overload_set_type @S.foo [concrete]
// CHECK:STDOUT: %empty_struct: %.177 = struct_value () [concrete]
// CHECK:STDOUT: %.dcb: %.177 = cpp_overload_set_value @S.foo [concrete]
// CHECK:STDOUT: %S.foo.type: type = fn_type @S.foo [concrete]
// CHECK:STDOUT: %S.foo: %S.foo.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %.dcb: %.177 = cpp_overload_set_value @S.foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.dcb: %.177 = cpp_overload_set_value @S.foo [concrete = constants.%.dcb]
// CHECK:STDOUT: %S.foo.decl: %S.foo.type = fn_decl @S.foo [concrete = constants.%S.foo] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
Expand All @@ -452,7 +452,7 @@ fn F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %s.ref: %ptr.5c7 = name_ref s, %s
// CHECK:STDOUT: %.loc8: ref %S = deref %s.ref
// CHECK:STDOUT: %foo.ref: %.177 = name_ref foo, imports.%.dcb [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo.ref: %.177 = name_ref foo, imports.%.dcb [concrete = constants.%.dcb]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc8, %foo.ref
// CHECK:STDOUT: %addr: %ptr.5c7 = addr_of %.loc8
// CHECK:STDOUT: %S.foo.call: init %empty_tuple.type = call imports.%S.foo.decl(%addr)
Expand Down Expand Up @@ -487,7 +487,7 @@ fn F() {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %DerivedPublic: type = class_type @DerivedPublic [concrete]
// CHECK:STDOUT: %.5a6: type = cpp_overload_set_type @Base.foo [concrete]
// CHECK:STDOUT: %empty_struct: %.5a6 = struct_value () [concrete]
// CHECK:STDOUT: %.607: %.5a6 = cpp_overload_set_value @Base.foo [concrete]
// CHECK:STDOUT: %Base.foo.type: type = fn_type @Base.foo [concrete]
// CHECK:STDOUT: %Base.foo: %Base.foo.type = struct_value () [concrete]
// CHECK:STDOUT: }
Expand All @@ -498,15 +498,15 @@ fn F() {
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %DerivedPublic.decl: type = class_decl @DerivedPublic [concrete = constants.%DerivedPublic] {} {}
// CHECK:STDOUT: %.607: %.5a6 = cpp_overload_set_value @Base.foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.607: %.5a6 = cpp_overload_set_value @Base.foo [concrete = constants.%.607]
// CHECK:STDOUT: %Base.foo.decl: %Base.foo.type = fn_decl @Base.foo [concrete = constants.%Base.foo] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %DerivedPublic.ref: type = name_ref DerivedPublic, imports.%DerivedPublic.decl [concrete = constants.%DerivedPublic]
// CHECK:STDOUT: %foo.ref: %.5a6 = name_ref foo, imports.%.607 [concrete = constants.%empty_struct]
// CHECK:STDOUT: %foo.ref: %.5a6 = name_ref foo, imports.%.607 [concrete = constants.%.607]
// CHECK:STDOUT: %Base.foo.call: init %empty_tuple.type = call imports.%Base.foo.decl()
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
Expand Down
30 changes: 15 additions & 15 deletions toolchain/check/testdata/interop/cpp/class/base.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ class V {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %Base: type = class_type @Base [concrete]
// CHECK:STDOUT: %.75e: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %empty_struct.c9f: %.75e = struct_value () [concrete]
// CHECK:STDOUT: %.750: %.75e = cpp_overload_set_value @<null name> [concrete]
// CHECK:STDOUT: %Base.base_fn.type: type = fn_type @Base.base_fn [concrete]
// CHECK:STDOUT: %Base.base_fn: %Base.base_fn.type = struct_value () [concrete]
// CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
// CHECK:STDOUT: %.809: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %empty_struct.422: %.809 = struct_value () [concrete]
// CHECK:STDOUT: %.22a: %.809 = cpp_overload_set_value @<null name> [concrete]
// CHECK:STDOUT: %.5f9: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %empty_struct.510: %.5f9 = struct_value () [concrete]
// CHECK:STDOUT: %.24a: %.5f9 = cpp_overload_set_value @<null name> [concrete]
// CHECK:STDOUT: %Derived.derived_fn.type: type = fn_type @Derived.derived_fn [concrete]
// CHECK:STDOUT: %Derived.derived_fn: %Derived.derived_fn.type = struct_value () [concrete]
// CHECK:STDOUT: }
Expand All @@ -364,27 +364,27 @@ class V {
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
// CHECK:STDOUT: %.750: %.75e = cpp_overload_set_value @<null name> [concrete = constants.%empty_struct.c9f]
// CHECK:STDOUT: %.750: %.75e = cpp_overload_set_value @<null name> [concrete = constants.%.750]
// CHECK:STDOUT: %Base.base_fn.decl: %Base.base_fn.type = fn_decl @Base.base_fn [concrete = constants.%Base.base_fn] {} {}
// CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
// CHECK:STDOUT: %.22a: %.809 = cpp_overload_set_value @<null name> [concrete = constants.%empty_struct.422]
// CHECK:STDOUT: %.24a: %.5f9 = cpp_overload_set_value @<null name> [concrete = constants.%empty_struct.510]
// CHECK:STDOUT: %.22a: %.809 = cpp_overload_set_value @<null name> [concrete = constants.%.22a]
// CHECK:STDOUT: %.24a: %.5f9 = cpp_overload_set_value @<null name> [concrete = constants.%.24a]
// CHECK:STDOUT: %Derived.derived_fn.decl: %Derived.derived_fn.type = fn_decl @Derived.derived_fn [concrete = constants.%Derived.derived_fn] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @MyF() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
// CHECK:STDOUT: %base_fn.ref.loc8: %.75e = name_ref base_fn, imports.%.750 [concrete = constants.%empty_struct.c9f]
// CHECK:STDOUT: %base_fn.ref.loc8: %.75e = name_ref base_fn, imports.%.750 [concrete = constants.%.750]
// CHECK:STDOUT: %Base.base_fn.call.loc8: init %empty_tuple.type = call imports.%Base.base_fn.decl()
// CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Derived.ref.loc9: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
// CHECK:STDOUT: %base_fn.ref.loc9: %.809 = name_ref base_fn, imports.%.22a [concrete = constants.%empty_struct.422]
// CHECK:STDOUT: %base_fn.ref.loc9: %.809 = name_ref base_fn, imports.%.22a [concrete = constants.%.22a]
// CHECK:STDOUT: %Base.base_fn.call.loc9: init %empty_tuple.type = call imports.%Base.base_fn.decl()
// CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Derived.ref.loc10: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
// CHECK:STDOUT: %derived_fn.ref: %.5f9 = name_ref derived_fn, imports.%.24a [concrete = constants.%empty_struct.510]
// CHECK:STDOUT: %derived_fn.ref: %.5f9 = name_ref derived_fn, imports.%.24a [concrete = constants.%.24a]
// CHECK:STDOUT: %Derived.derived_fn.call: init %empty_tuple.type = call imports.%Derived.derived_fn.decl()
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
Expand Down Expand Up @@ -463,14 +463,14 @@ class V {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %Base: type = class_type @Base [concrete]
// CHECK:STDOUT: %.5b0: type = cpp_overload_set_type @f__carbon_thunk [concrete]
// CHECK:STDOUT: %empty_struct.3f3: %.5b0 = struct_value () [concrete]
// CHECK:STDOUT: %.e54: %.5b0 = cpp_overload_set_value @f__carbon_thunk [concrete]
// CHECK:STDOUT: %const: type = const_type %Base [concrete]
// CHECK:STDOUT: %ptr.a97: type = ptr_type %const [concrete]
// CHECK:STDOUT: %f__carbon_thunk.type: type = fn_type @f__carbon_thunk [concrete]
// CHECK:STDOUT: %f__carbon_thunk: %f__carbon_thunk.type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.fb2: type = ptr_type %Base [concrete]
// CHECK:STDOUT: %.7c6: type = cpp_overload_set_type @CallQualified [concrete]
// CHECK:STDOUT: %empty_struct.49e: %.7c6 = struct_value () [concrete]
// CHECK:STDOUT: %.362: %.7c6 = cpp_overload_set_value @CallQualified [concrete]
// CHECK:STDOUT: %g__carbon_thunk.type: type = fn_type @g__carbon_thunk [concrete]
// CHECK:STDOUT: %g__carbon_thunk: %g__carbon_thunk.type = struct_value () [concrete]
// CHECK:STDOUT: }
Expand All @@ -483,13 +483,13 @@ class V {
// CHECK:STDOUT: }
// CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
// CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
// CHECK:STDOUT: %.e54: %.5b0 = cpp_overload_set_value @f__carbon_thunk [concrete = constants.%empty_struct.3f3]
// CHECK:STDOUT: %.e54: %.5b0 = cpp_overload_set_value @f__carbon_thunk [concrete = constants.%.e54]
// CHECK:STDOUT: %f__carbon_thunk.decl: %f__carbon_thunk.type = fn_decl @f__carbon_thunk [concrete = constants.%f__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: %.362: %.7c6 = cpp_overload_set_value @CallQualified [concrete = constants.%empty_struct.49e]
// CHECK:STDOUT: %.362: %.7c6 = cpp_overload_set_value @CallQualified [concrete = constants.%.362]
// CHECK:STDOUT: %g__carbon_thunk.decl: %g__carbon_thunk.type = fn_decl @g__carbon_thunk [concrete = constants.%g__carbon_thunk] {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: } {
Expand All @@ -500,7 +500,7 @@ class V {
// CHECK:STDOUT: fn @CallDirect(%d.param: %Derived) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
// CHECK:STDOUT: %f.ref: %.5b0 = name_ref f, imports.%.e54 [concrete = constants.%empty_struct.3f3]
// CHECK:STDOUT: %f.ref: %.5b0 = name_ref f, imports.%.e54 [concrete = constants.%.e54]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %d.ref, %f.ref
// CHECK:STDOUT: %.loc8_3.1: ref %Base = class_element_access %d.ref, element0
// CHECK:STDOUT: %.loc8_3.2: ref %Base = converted %d.ref, %.loc8_3.1
Expand All @@ -518,7 +518,7 @@ class V {
// CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
// CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
// CHECK:STDOUT: %g.ref: %.7c6 = name_ref g, imports.%.362 [concrete = constants.%empty_struct.49e]
// CHECK:STDOUT: %g.ref: %.7c6 = name_ref g, imports.%.362 [concrete = constants.%.362]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %d.ref, %g.ref
// CHECK:STDOUT: %.loc14_3.1: ref %Base = class_element_access %d.ref, element0
// CHECK:STDOUT: %.loc14_3.2: ref %Base = converted %d.ref, %.loc14_3.1
Expand Down
Loading
Loading