mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Format the decl block for a declaration as a trailing block. (#3731)
Previously we used the default inst block formatting, which writes out a parenthesized list of references, which would always be 'unexpected instref's because nothing else prints the instructions in the decl block. In addition, track the decl block for function declarations like we do for other kinds of declaration. This means that the parameter declarations for a function are now properly rendered into the formatted IR. Note that this adds a lot of verbosity to `function_decl`, but it does accurately reflect the IR, and we'll probably want this information to be printed once we start supporting more complex generic function declarations. This removes almost all the 'unexpected instref's in our formatted output. There are remaining cases when a declarative scope contains multiple blocks, where we only track one of those blocks. That happens when there is control flow within declarative scopes, and for error recovery when a class or interface or similar is defined more than once. As requested in #3730.
This commit is contained in:
@@ -18,7 +18,9 @@ fn F() -> i32 {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F {
|
||||
// CHECK:STDOUT: %return.var: ref i32 = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() -> i32 {
|
||||
|
||||
@@ -34,7 +34,7 @@ fn F() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F {} [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
|
||||
+3
-1
@@ -20,7 +20,9 @@ fn F() -> i32 {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F {
|
||||
// CHECK:STDOUT: %return.var: ref i32 = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() -> i32 {
|
||||
|
||||
@@ -22,7 +22,7 @@ fn Test() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.Test = %Test} [template]
|
||||
// CHECK:STDOUT: %Test: <function> = fn_decl @Test [template]
|
||||
// CHECK:STDOUT: %Test: <function> = fn_decl @Test {} [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Test() {
|
||||
|
||||
@@ -109,14 +109,22 @@ fn AddressOfParam(param: i32) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.G = %G, .H = %H, .AddressOfLiteral = %AddressOfLiteral, .AddressOfOperator = %AddressOfOperator, .AddressOfCall = %AddressOfCall, .AddressOfType = %AddressOfType, .AddressOfTupleElementValue = %AddressOfTupleElementValue, .AddressOfParam = %AddressOfParam} [template]
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G [template]
|
||||
// CHECK:STDOUT: %H: <function> = fn_decl @H [template]
|
||||
// CHECK:STDOUT: %AddressOfLiteral: <function> = fn_decl @AddressOfLiteral [template]
|
||||
// CHECK:STDOUT: %AddressOfOperator: <function> = fn_decl @AddressOfOperator [template]
|
||||
// CHECK:STDOUT: %AddressOfCall: <function> = fn_decl @AddressOfCall [template]
|
||||
// CHECK:STDOUT: %AddressOfType: <function> = fn_decl @AddressOfType [template]
|
||||
// CHECK:STDOUT: %AddressOfTupleElementValue: <function> = fn_decl @AddressOfTupleElementValue [template]
|
||||
// CHECK:STDOUT: %AddressOfParam: <function> = fn_decl @AddressOfParam [template]
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G {
|
||||
// CHECK:STDOUT: %return.var.loc7: ref i32 = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: %H: <function> = fn_decl @H {
|
||||
// CHECK:STDOUT: %.loc9: type = struct_type {.a: i32} [template = constants.%.1]
|
||||
// CHECK:STDOUT: %return.var.loc9: ref {.a: i32} = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: %AddressOfLiteral: <function> = fn_decl @AddressOfLiteral {} [template]
|
||||
// CHECK:STDOUT: %AddressOfOperator: <function> = fn_decl @AddressOfOperator {} [template]
|
||||
// CHECK:STDOUT: %AddressOfCall: <function> = fn_decl @AddressOfCall {} [template]
|
||||
// CHECK:STDOUT: %AddressOfType: <function> = fn_decl @AddressOfType {} [template]
|
||||
// CHECK:STDOUT: %AddressOfTupleElementValue: <function> = fn_decl @AddressOfTupleElementValue {} [template]
|
||||
// CHECK:STDOUT: %AddressOfParam: <function> = fn_decl @AddressOfParam {
|
||||
// CHECK:STDOUT: %param.loc78_19.1: i32 = param param
|
||||
// CHECK:STDOUT: @AddressOfParam.%param: i32 = bind_name param, %param.loc78_19.1
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @G() -> i32;
|
||||
|
||||
@@ -15,7 +15,7 @@ fn A() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.A = %A} [template]
|
||||
// CHECK:STDOUT: %A: <function> = fn_decl @A [template]
|
||||
// CHECK:STDOUT: %A: <function> = fn_decl @A {} [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @A() {
|
||||
|
||||
@@ -18,7 +18,7 @@ fn F() {
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.A = %.loc7, .F = %F} [template]
|
||||
// CHECK:STDOUT: %.loc7: <namespace> = namespace {} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F {} [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
|
||||
@@ -30,7 +30,10 @@ fn Deref(n: i32) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.Deref = %Deref} [template]
|
||||
// CHECK:STDOUT: %Deref: <function> = fn_decl @Deref [template]
|
||||
// CHECK:STDOUT: %Deref: <function> = fn_decl @Deref {
|
||||
// CHECK:STDOUT: %n.loc7_10.1: i32 = param n
|
||||
// CHECK:STDOUT: @Deref.%n: i32 = bind_name n, %n.loc7_10.1
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Deref(%n: i32) {
|
||||
|
||||
+13
-1
@@ -23,7 +23,19 @@ fn ConstMismatch(p: const {}*) -> const ({}*) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.ConstMismatch = %ConstMismatch} [template]
|
||||
// CHECK:STDOUT: %ConstMismatch: <function> = fn_decl @ConstMismatch [template]
|
||||
// CHECK:STDOUT: %ConstMismatch: <function> = fn_decl @ConstMismatch {
|
||||
// CHECK:STDOUT: %.loc7_28.1: {} = struct_literal ()
|
||||
// CHECK:STDOUT: %.loc7_28.2: type = converted %.loc7_28.1, constants.%.1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_21: type = const_type {} [template = constants.%.2]
|
||||
// CHECK:STDOUT: %.loc7_29: type = ptr_type const {} [template = constants.%.3]
|
||||
// CHECK:STDOUT: %p.loc7_18.1: const {}* = param p
|
||||
// CHECK:STDOUT: @ConstMismatch.%p: const {}* = bind_name p, %p.loc7_18.1
|
||||
// CHECK:STDOUT: %.loc7_43.1: {} = struct_literal ()
|
||||
// CHECK:STDOUT: %.loc7_43.2: type = converted %.loc7_43.1, constants.%.1 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc7_44: type = ptr_type {} [template = constants.%.4]
|
||||
// CHECK:STDOUT: %.loc7_35: type = const_type {}* [template = constants.%.5]
|
||||
// CHECK:STDOUT: %return.var: ref const ({}*) = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @ConstMismatch(%p: const {}*) -> const ({}*) {
|
||||
|
||||
+11
-1
@@ -21,7 +21,17 @@ fn F(p: const (const (const i32*)*)) -> const i32 {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F} [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F {
|
||||
// CHECK:STDOUT: %.loc8_23: type = const_type i32 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %.loc8_32: type = ptr_type const i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %.loc8_16: type = const_type const i32* [template = constants.%.3]
|
||||
// CHECK:STDOUT: %.loc8_34: type = ptr_type const (const i32*) [template = constants.%.4]
|
||||
// CHECK:STDOUT: %.loc8_9: type = const_type const (const i32*)* [template = constants.%.5]
|
||||
// CHECK:STDOUT: %p.loc8_6.1: const (const (const i32*)*) = param p
|
||||
// CHECK:STDOUT: @F.%p: const (const (const i32*)*) = bind_name p, %p.loc8_6.1
|
||||
// CHECK:STDOUT: %.loc8_41: type = const_type i32 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %return.var: ref const i32 = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F(%p: const (const (const i32*)*)) -> const i32 {
|
||||
|
||||
+16
-2
@@ -22,8 +22,22 @@ fn ConstPtr(p: const i32*) -> (const i32)* {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace {.Ptr = %Ptr, .ConstPtr = %ConstPtr} [template]
|
||||
// CHECK:STDOUT: %Ptr: <function> = fn_decl @Ptr [template]
|
||||
// CHECK:STDOUT: %ConstPtr: <function> = fn_decl @ConstPtr [template]
|
||||
// CHECK:STDOUT: %Ptr: <function> = fn_decl @Ptr {
|
||||
// CHECK:STDOUT: %.loc7_14: type = ptr_type i32 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %p.loc7_8.1: i32* = param p
|
||||
// CHECK:STDOUT: @Ptr.%p: i32* = bind_name p, %p.loc7_8.1
|
||||
// CHECK:STDOUT: %.loc7_23: type = ptr_type i32 [template = constants.%.1]
|
||||
// CHECK:STDOUT: %return.var.loc7: ref i32* = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: %ConstPtr: <function> = fn_decl @ConstPtr {
|
||||
// CHECK:STDOUT: %.loc11_16: type = const_type i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %.loc11_25: type = ptr_type const i32 [template = constants.%.3]
|
||||
// CHECK:STDOUT: %p.loc11_13.1: const i32* = param p
|
||||
// CHECK:STDOUT: @ConstPtr.%p: const i32* = bind_name p, %p.loc11_13.1
|
||||
// CHECK:STDOUT: %.loc11_32: type = const_type i32 [template = constants.%.2]
|
||||
// CHECK:STDOUT: %.loc11_42: type = ptr_type const i32 [template = constants.%.3]
|
||||
// CHECK:STDOUT: %return.var.loc11: ref const i32* = var <return slot>
|
||||
// CHECK:STDOUT: } [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Ptr(%p: i32*) -> i32* {
|
||||
|
||||
Reference in New Issue
Block a user