mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:34:42 +01:00
Provide diagnostic locations for imported namespaces. (#3640)
Building on #3636 which handles the general import case, add special casing for namespaces. Namespaces can be combined cross-IR, so it's a little more complex. The implementation adds import_id to the Namespace instruction as a reference to find the original using the normal structure. This is achieved by moving the name_id to NameScope to free up space. --- I considered a few alternatives... I considered adding import_id to NameScope, but: 1. It's more consistent with things such as Function or Class that provide name_id on the info object rather than the instruction. 2. I thought it more likely that there would be more NameScope cases that might want a name_id rather than the import_id, since ImportRef will typically be used. I considered putting the import source (cross-ref IR id + inst id) on the NameScope versus a separate ImportRef, which seems like the strongest argument towards the NameScope approach because it removes an instruction. That just felt inconsistent though, and the overhead of instruction-per-imported-namespace should be low (theoretically few namespaces should be used). Plus I feel a bit odd adding two generally-unused ids to NameScope. A specialized Namespace structure could also have been created to store the import_id, but that would add an indirection to the NameScope.
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ fn G() {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F, .G = %G} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F, .G = %G} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G [template]
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ fn G() {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.G = %G} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.G = %G} [template]
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -24,7 +24,7 @@ fn Run() {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F, .Run = %Run} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F, .Run = %Run} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %Run: <function> = fn_decl @Run [template]
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ var b: [i32; 3] = a;
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: %.loc7_22.1: (type, type, type) = tuple_literal (i32, i32, i32)
|
||||
// CHECK:STDOUT: %.loc7_22.2: type = converted %.loc7_22.1, constants.%.2 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref (i32, i32, i32) = var a
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ var c: [(); 5] = ((), (), (), (), (),);
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .b = %b, .c = %c} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b, .c = %c} [template]
|
||||
// CHECK:STDOUT: %.loc7_14: i32 = int_literal 1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 1] = var a
|
||||
|
||||
@@ -25,7 +25,7 @@ var b: [1; 39999999999999999993];
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: %.loc10_14: i32 = int_literal 39999999999999999993 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc10_34: type = array_type %.loc10_14, i32 [template = <error>]
|
||||
// CHECK:STDOUT: %a.var: ref <error> = var a
|
||||
|
||||
@@ -31,7 +31,7 @@ var p: Incomplete* = &a[0];
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.Incomplete = %Incomplete.decl, .a = %a, .p = %p} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.Incomplete = %Incomplete.decl, .a = %a, .p = %p} [template]
|
||||
// CHECK:STDOUT: %Incomplete.decl = class_decl @Incomplete, ()
|
||||
// CHECK:STDOUT: %Incomplete.ref.loc15: type = name_ref Incomplete, constants.%Incomplete [template = constants.%Incomplete]
|
||||
// CHECK:STDOUT: %.loc15_21: i32 = int_literal 1 [template = constants.%.1]
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ var a: [1; 1];
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a} [template]
|
||||
// CHECK:STDOUT: %.loc10_9: i32 = int_literal 1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc10_12: i32 = int_literal 1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc10_13: type = array_type %.loc10_12, <error> [template = constants.%.2]
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ var a: [i32; 1] = (1, 2, 3);
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a} [template]
|
||||
// CHECK:STDOUT: %.loc10_14: i32 = int_literal 1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc10_15: type = array_type %.loc10_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 1] = var a
|
||||
|
||||
@@ -28,7 +28,7 @@ var b: i32 = a[{.index = 3}.index];
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: %.loc7_14: i32 = int_literal 3 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 3] = var a
|
||||
|
||||
@@ -49,7 +49,7 @@ var d: [i32; 3] = t2;
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .t1 = %t1, .b = %b, .c = %c, .t2 = %t2, .d = %d} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .t1 = %t1, .b = %b, .c = %c, .t2 = %t2, .d = %d} [template]
|
||||
// CHECK:STDOUT: %.loc10_14: i32 = int_literal 3 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc10_15: type = array_type %.loc10_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 3] = var a
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ fn G() -> i32 {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F, .G = %G} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F, .G = %G} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G [template]
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ var b: i32 = a[{.index = 2}.index];
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
|
||||
// CHECK:STDOUT: %.loc7_14: i32 = int_literal 3 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 3] = var a
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ var a: [i32; 9] = (1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.a = %a} [template]
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a} [template]
|
||||
// CHECK:STDOUT: %.loc7_14: i32 = int_literal 9 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %a.var: ref [i32; 9] = var a
|
||||
|
||||
Reference in New Issue
Block a user