Split the witness table into a separate ImplWitnessTable instruction (#5272)

This allows us to import the table for a given impl only once, while we
can import many ImplWitness instructions with different specifics for a
generic impl.

For example in convert_facet_value_to_narrowed_facet_type.carbon we see
that a single witness table is imported for the BitAnd interface, with
multiple witnesses (for different specifics) imported and sharing the
same table.

The ImplWitnessTable now contains a back-link to the Impl the witness is
for, allowing inst namer to name that interface in the textual semir,
and allowing the interface to be found when debugging from a witness.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Dana Jansens
2025-04-11 20:30:04 +00:00
committed by GitHub
co-authored by Richard Smith
parent c34a8d0a3a
commit 0e8d354567
273 changed files with 4091 additions and 3391 deletions
@@ -50,20 +50,20 @@ fn Run() {
// CHECK:STDOUT:
// CHECK:STDOUT: define void @main() !dbg !12 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CG.Main.562d5cdd5cdbd5c5(), !dbg !13
// CHECK:STDOUT: call void @_CG.Main.386ac59331346fc4(), !dbg !14
// CHECK:STDOUT: call void @_CG.Main.2c436a64dfc3fd29(), !dbg !13
// CHECK:STDOUT: call void @_CG.Main.c124d41ebc08c32b(), !dbg !14
// CHECK:STDOUT: ret void, !dbg !15
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare i32 @printf(ptr, ...)
// CHECK:STDOUT:
// CHECK:STDOUT: define void @_CG.Main.562d5cdd5cdbd5c5() !dbg !16 {
// CHECK:STDOUT: define void @_CG.Main.2c436a64dfc3fd29() !dbg !16 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @"_CF.X.Main:I.Main"(), !dbg !17
// CHECK:STDOUT: ret void, !dbg !18
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: define void @_CG.Main.386ac59331346fc4() !dbg !19 {
// CHECK:STDOUT: define void @_CG.Main.c124d41ebc08c32b() !dbg !19 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @"_CF.Y.Main:I.Main"(), !dbg !20
// CHECK:STDOUT: ret void, !dbg !21
@@ -91,9 +91,9 @@ fn Run() {
// CHECK:STDOUT: !13 = !DILocation(line: 30, column: 3, scope: !12)
// CHECK:STDOUT: !14 = !DILocation(line: 31, column: 3, scope: !12)
// CHECK:STDOUT: !15 = !DILocation(line: 29, column: 1, scope: !12)
// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.562d5cdd5cdbd5c5", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.2c436a64dfc3fd29", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !17 = !DILocation(line: 27, column: 15, scope: !16)
// CHECK:STDOUT: !18 = !DILocation(line: 27, column: 1, scope: !16)
// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.386ac59331346fc4", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c124d41ebc08c32b", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !20 = !DILocation(line: 27, column: 15, scope: !19)
// CHECK:STDOUT: !21 = !DILocation(line: 27, column: 1, scope: !19)
@@ -59,7 +59,7 @@ fn G() {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %out.var = alloca i32, align 4, !dbg !10
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 4, ptr %out.var), !dbg !10
// CHECK:STDOUT: %CallGenericMethod.call = call i32 @_CCallGenericMethod.Main.2b28d1a7fa793cbc(i32 10), !dbg !11
// CHECK:STDOUT: %CallGenericMethod.call = call i32 @_CCallGenericMethod.Main.b330a91dfda257ee(i32 10), !dbg !11
// CHECK:STDOUT: store i32 %CallGenericMethod.call, ptr %out.var, align 4, !dbg !10
// CHECK:STDOUT: %.loc40 = load i32, ptr %out.var, align 4, !dbg !12
// CHECK:STDOUT: %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %.loc40), !dbg !13
@@ -69,7 +69,7 @@ fn G() {
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
// CHECK:STDOUT:
// CHECK:STDOUT: define i32 @_CCallGenericMethod.Main.2b28d1a7fa793cbc(i32 %x) !dbg !15 {
// CHECK:STDOUT: define i32 @_CCallGenericMethod.Main.b330a91dfda257ee(i32 %x) !dbg !15 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc35_15 = call i32 @"_CF.ImplsSomeInterface.Main:SomeInterface.Main"(i32 %x), !dbg !16
// CHECK:STDOUT: ret i32 %.loc35_15, !dbg !17
@@ -97,6 +97,6 @@ fn G() {
// CHECK:STDOUT: !12 = !DILocation(line: 40, column: 14, scope: !9)
// CHECK:STDOUT: !13 = !DILocation(line: 40, column: 3, scope: !9)
// CHECK:STDOUT: !14 = !DILocation(line: 38, column: 1, scope: !9)
// CHECK:STDOUT: !15 = distinct !DISubprogram(name: "CallGenericMethod", linkageName: "_CCallGenericMethod.Main.2b28d1a7fa793cbc", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !15 = distinct !DISubprogram(name: "CallGenericMethod", linkageName: "_CCallGenericMethod.Main.b330a91dfda257ee", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !16 = !DILocation(line: 35, column: 10, scope: !15)
// CHECK:STDOUT: !17 = !DILocation(line: 35, column: 3, scope: !15)
@@ -58,14 +58,14 @@ fn Run() {
// CHECK:STDOUT:
// CHECK:STDOUT: define void @main() !dbg !12 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %G.call.loc38 = call i32 @_CG.Main.562d5cdd5cdbd5c5(i32 0), !dbg !13
// CHECK:STDOUT: %G.call.loc39 = call i32 @_CG.Main.386ac59331346fc4(i32 0), !dbg !14
// CHECK:STDOUT: %G.call.loc38 = call i32 @_CG.Main.2c436a64dfc3fd29(i32 0), !dbg !13
// CHECK:STDOUT: %G.call.loc39 = call i32 @_CG.Main.c124d41ebc08c32b(i32 0), !dbg !14
// CHECK:STDOUT: ret void, !dbg !15
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare i32 @printf(ptr, ...)
// CHECK:STDOUT:
// CHECK:STDOUT: define i32 @_CG.Main.562d5cdd5cdbd5c5(i32 %count) !dbg !16 {
// CHECK:STDOUT: define i32 @_CG.Main.2c436a64dfc3fd29(i32 %count) !dbg !16 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @"_CF.X.Main:I.Main"(), !dbg !17
// CHECK:STDOUT: %int.greater = icmp sgt i32 %count, 0, !dbg !18
@@ -76,11 +76,11 @@ fn Run() {
// CHECK:STDOUT:
// CHECK:STDOUT: if.else: ; preds = %entry
// CHECK:STDOUT: %int.sadd = add i32 %count, 1, !dbg !21
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.562d5cdd5cdbd5c5(i32 %int.sadd), !dbg !22
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.2c436a64dfc3fd29(i32 %int.sadd), !dbg !22
// CHECK:STDOUT: ret i32 %G.call, !dbg !23
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: define i32 @_CG.Main.386ac59331346fc4(i32 %count) !dbg !24 {
// CHECK:STDOUT: define i32 @_CG.Main.c124d41ebc08c32b(i32 %count) !dbg !24 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @"_CF.Y.Main:I.Main"(), !dbg !25
// CHECK:STDOUT: %int.greater = icmp sgt i32 %count, 0, !dbg !26
@@ -91,7 +91,7 @@ fn Run() {
// CHECK:STDOUT:
// CHECK:STDOUT: if.else: ; preds = %entry
// CHECK:STDOUT: %int.sadd = add i32 %count, 1, !dbg !29
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.386ac59331346fc4(i32 %int.sadd), !dbg !30
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.c124d41ebc08c32b(i32 %int.sadd), !dbg !30
// CHECK:STDOUT: ret i32 %G.call, !dbg !31
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -117,7 +117,7 @@ fn Run() {
// CHECK:STDOUT: !13 = !DILocation(line: 38, column: 3, scope: !12)
// CHECK:STDOUT: !14 = !DILocation(line: 39, column: 3, scope: !12)
// CHECK:STDOUT: !15 = !DILocation(line: 37, column: 1, scope: !12)
// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.562d5cdd5cdbd5c5", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.2c436a64dfc3fd29", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !17 = !DILocation(line: 29, column: 3, scope: !16)
// CHECK:STDOUT: !18 = !DILocation(line: 31, column: 7, scope: !16)
// CHECK:STDOUT: !19 = !DILocation(line: 31, column: 6, scope: !16)
@@ -125,7 +125,7 @@ fn Run() {
// CHECK:STDOUT: !21 = !DILocation(line: 34, column: 15, scope: !16)
// CHECK:STDOUT: !22 = !DILocation(line: 34, column: 10, scope: !16)
// CHECK:STDOUT: !23 = !DILocation(line: 34, column: 3, scope: !16)
// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.386ac59331346fc4", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.c124d41ebc08c32b", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
// CHECK:STDOUT: !25 = !DILocation(line: 29, column: 3, scope: !24)
// CHECK:STDOUT: !26 = !DILocation(line: 31, column: 7, scope: !24)
// CHECK:STDOUT: !27 = !DILocation(line: 31, column: 6, scope: !24)