Model var as a pattern operator (#4720)

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Geoff Romer
2025-01-17 17:51:34 +00:00
committed by GitHub
co-authored by Richard Smith
parent 6572da7314
commit 13434f0e8a
510 changed files with 11819 additions and 3352 deletions
+13 -3
View File
@@ -90,8 +90,11 @@ fn F(b: bool, n: i32, m: i32) -> i32 {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F(%b.param_patt: bool, %n.param_patt: %i32, %m.param_patt: %i32) -> %i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %x.patt: %array_type = binding_pattern x
// CHECK:STDOUT: %.loc12_3.1: %array_type = var_pattern %x.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %x.var: ref %array_type = var x
// CHECK:STDOUT: %x: ref %array_type = bind_name x, %x.var
// CHECK:STDOUT: %int_0.loc12_22: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
// CHECK:STDOUT: %.loc12_24.1: %tuple.type = tuple_literal (%int_0.loc12_22)
// CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
@@ -103,8 +106,15 @@ fn F(b: bool, n: i32, m: i32) -> i32 {
// CHECK:STDOUT: %.loc12_24.3: ref %i32 = array_index %x.var, %int_0.loc12_24
// CHECK:STDOUT: %.loc12_24.4: init %i32 = initialize_from %.loc12_24.2 to %.loc12_24.3 [template = constants.%int_0.6a9]
// CHECK:STDOUT: %.loc12_24.5: init %array_type = array_init (%.loc12_24.4) to %x.var [template = constants.%array]
// CHECK:STDOUT: %.loc12_25: init %array_type = converted %.loc12_24.1, %.loc12_24.5 [template = constants.%array]
// CHECK:STDOUT: assign %x.var, %.loc12_25
// CHECK:STDOUT: %.loc12_3.2: init %array_type = converted %.loc12_24.1, %.loc12_24.5 [template = constants.%array]
// CHECK:STDOUT: assign %x.var, %.loc12_3.2
// CHECK:STDOUT: %.loc12_17: type = splice_block %array_type [template = constants.%array_type] {
// CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
// CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [template = constants.%array_type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %x: ref %array_type = bind_name x, %x.var
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
// CHECK:STDOUT: if %b.ref br !if.expr.then else br !if.expr.else
// CHECK:STDOUT:
+113 -12
View File
@@ -125,8 +125,8 @@ fn PartiallyConstant(t: type) -> i32 {
// CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
// CHECK:STDOUT: } {
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %int_32.loc22: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc22: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
// CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
// CHECK:STDOUT: }
@@ -136,8 +136,8 @@ fn PartiallyConstant(t: type) -> i32 {
// CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
// CHECK:STDOUT: } {
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %int_32.loc28: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc28: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %t.param: type = value_param runtime_param0
// CHECK:STDOUT: %t: type = bind_name t, %t.param
// CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
@@ -219,20 +219,72 @@ fn PartiallyConstant(t: type) -> i32 {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Constant() -> %i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %v.patt: %i32 = binding_pattern v
// CHECK:STDOUT: %.loc23_3.1: %i32 = var_pattern %v.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %v.var: ref %i32 = var v
// CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
// CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1, %impl.elem0 [template = constants.%Convert.bound.ab5]
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
// CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_1) [template = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc23: init %i32 = converted %int_1, %int.convert_checked [template = constants.%int_1.5d2]
// CHECK:STDOUT: assign %v.var, %.loc23
// CHECK:STDOUT: %.loc23_3.2: init %i32 = converted %int_1, %int.convert_checked [template = constants.%int_1.5d2]
// CHECK:STDOUT: assign %v.var, %.loc23_3.2
// CHECK:STDOUT: br !.loc23_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc23_13:
// CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
// CHECK:STDOUT: if %true br !if.expr.then.loc23 else br !if.expr.else.loc23
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc23:
// CHECK:STDOUT: %int_32.loc23_23: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc23_23: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result.loc23(%i32.loc23_23)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc23:
// CHECK:STDOUT: %int_32.loc23_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc23_32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %ptr.loc23: type = ptr_type %i32 [template = constants.%ptr]
// CHECK:STDOUT: br !if.expr.result.loc23(%ptr.loc23)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc23:
// CHECK:STDOUT: %.loc23_10: type = block_arg !if.expr.result.loc23 [template = constants.%i32]
// CHECK:STDOUT: br !.loc23_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc23_7:
// CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %w.patt: %ptr = binding_pattern w
// CHECK:STDOUT: %.loc24_3: %ptr = var_pattern %w.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %w.var: ref %ptr = var w
// CHECK:STDOUT: %w: ref %ptr = bind_name w, %w.var
// CHECK:STDOUT: %v.ref: ref %i32 = name_ref v, %v
// CHECK:STDOUT: %addr: %ptr = addr_of %v.ref
// CHECK:STDOUT: assign %w.var, %addr
// CHECK:STDOUT: br !.loc24_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc24_13:
// CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
// CHECK:STDOUT: if %false br !if.expr.then.loc24 else br !if.expr.else.loc24
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc24:
// CHECK:STDOUT: %int_32.loc24_24: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc24_24: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result.loc24(%i32.loc24_24)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc24:
// CHECK:STDOUT: %int_32.loc24_33: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc24_33: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %ptr.loc24: type = ptr_type %i32 [template = constants.%ptr]
// CHECK:STDOUT: br !if.expr.result.loc24(%ptr.loc24)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc24:
// CHECK:STDOUT: %.loc24_10: type = block_arg !if.expr.result.loc24 [template = constants.%ptr]
// CHECK:STDOUT: br !.loc24_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc24_7:
// CHECK:STDOUT: %w: ref %ptr = bind_name w, %w.var
// CHECK:STDOUT: %w.ref: ref %ptr = name_ref w, %w
// CHECK:STDOUT: %.loc25_11: %ptr = bind_value %w.ref
// CHECK:STDOUT: %.loc25_10.1: ref %i32 = deref %.loc25_11
@@ -242,20 +294,69 @@ fn PartiallyConstant(t: type) -> i32 {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @PartiallyConstant(%t.param_patt: type) -> %i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %v.patt: %i32 = binding_pattern v
// CHECK:STDOUT: %.loc29_3.1: %i32 = var_pattern %v.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %v.var: ref %i32 = var v
// CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
// CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1, %impl.elem0 [template = constants.%Convert.bound.ab5]
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
// CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_1) [template = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc29: init %i32 = converted %int_1, %int.convert_checked [template = constants.%int_1.5d2]
// CHECK:STDOUT: assign %v.var, %.loc29
// CHECK:STDOUT: %.loc29_3.2: init %i32 = converted %int_1, %int.convert_checked [template = constants.%int_1.5d2]
// CHECK:STDOUT: assign %v.var, %.loc29_3.2
// CHECK:STDOUT: br !.loc29_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc29_13:
// CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
// CHECK:STDOUT: if %true br !if.expr.then.loc29 else br !if.expr.else.loc29
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc29:
// CHECK:STDOUT: %int_32.loc29: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc29: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result.loc29(%i32.loc29)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc29:
// CHECK:STDOUT: %t.ref.loc29: type = name_ref t, %t
// CHECK:STDOUT: br !if.expr.result.loc29(%t.ref.loc29)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc29:
// CHECK:STDOUT: %.loc29_10: type = block_arg !if.expr.result.loc29 [template = constants.%i32]
// CHECK:STDOUT: br !.loc29_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc29_7:
// CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %w.patt: %ptr = binding_pattern w
// CHECK:STDOUT: %.loc30_3: %ptr = var_pattern %w.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %w.var: ref %ptr = var w
// CHECK:STDOUT: %w: ref %ptr = bind_name w, %w.var
// CHECK:STDOUT: %v.ref: ref %i32 = name_ref v, %v
// CHECK:STDOUT: %addr: %ptr = addr_of %v.ref
// CHECK:STDOUT: assign %w.var, %addr
// CHECK:STDOUT: br !.loc30_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc30_13:
// CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
// CHECK:STDOUT: if %false br !if.expr.then.loc30 else br !if.expr.else.loc30
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc30:
// CHECK:STDOUT: %t.ref.loc30: type = name_ref t, %t
// CHECK:STDOUT: br !if.expr.result.loc30(%t.ref.loc30)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc30:
// CHECK:STDOUT: %int_32.loc30: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc30: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %ptr: type = ptr_type %i32 [template = constants.%ptr]
// CHECK:STDOUT: br !if.expr.result.loc30(%ptr)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc30:
// CHECK:STDOUT: %.loc30_10: type = block_arg !if.expr.result.loc30 [template = constants.%ptr]
// CHECK:STDOUT: br !.loc30_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc30_7:
// CHECK:STDOUT: %w: ref %ptr = bind_name w, %w.var
// CHECK:STDOUT: %w.ref: ref %ptr = name_ref w, %w
// CHECK:STDOUT: %.loc31_11: %ptr = bind_value %w.ref
// CHECK:STDOUT: %.loc31_10.1: ref %i32 = deref %.loc31_11
@@ -26,10 +26,14 @@
// CHECK:STDERR:
let x: i32 = if true then 1 else 0;
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]:8: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]:8: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
// CHECK:STDERR: var y: if true then i32 else f64;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]:8: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
// CHECK:STDERR: var y: if true then i32 else f64;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
var y: if true then i32 else f64;
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
@@ -77,12 +81,24 @@ class C {
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .x = <unexpected>.inst43.loc27_5
// CHECK:STDOUT: .x = %x
// CHECK:STDOUT: .y = %y
// CHECK:STDOUT: .F = %F.decl
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %x.patt: %i32 = binding_pattern x
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc27: type = splice_block %i32 [template = constants.%i32] {
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: }
// CHECK:STDOUT: %x: %i32 = bind_name x, <unexpected>.inst998.loc27_14
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %y.patt: %i32 = binding_pattern y
// CHECK:STDOUT: %.loc37: %i32 = var_pattern %y.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %y.var: ref %i32 = var y
// CHECK:STDOUT: %y: ref %i32 = bind_name y, %y.var
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
@@ -96,7 +112,11 @@ class C {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: %.loc50: %C.elem = field_decl n, element0 [template]
// CHECK:STDOUT: %.loc54_8: %C.elem = field_decl n, element0 [template]
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %.loc54_3: %C.elem = var_pattern %.loc54_8
// CHECK:STDOUT: }
// CHECK:STDOUT: %.var: ref %C.elem = var <invalid>
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [template = constants.%complete_type.54b]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT: }
@@ -47,6 +47,8 @@ fn ChosenBranchIsNonConstant(t: type) {
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
// CHECK:STDOUT: %ConditionIsNonConstant.type: type = fn_type @ConditionIsNonConstant [template]
// CHECK:STDOUT: %ConditionIsNonConstant: %ConditionIsNonConstant.type = struct_value () [template]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -81,10 +83,35 @@ fn ChosenBranchIsNonConstant(t: type) {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @ConditionIsNonConstant(%b.param_patt: bool) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %v.patt: <error> = binding_pattern v
// CHECK:STDOUT: %.loc12_3: <error> = var_pattern %v.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %v.var: ref <error> = var v
// CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
// CHECK:STDOUT: assign %v.var, <error>
// CHECK:STDOUT: br !.loc12_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc12_13:
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
// CHECK:STDOUT: if %b.ref br !if.expr.then else br !if.expr.else
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then:
// CHECK:STDOUT: %int_32.loc12_20: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc12_20: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result(%i32.loc12_20)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else:
// CHECK:STDOUT: %int_32.loc12_29: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc12_29: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result(%i32.loc12_29)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result:
// CHECK:STDOUT: %.loc12_10: type = block_arg !if.expr.result
// CHECK:STDOUT: br !.loc12_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc12_7:
// CHECK:STDOUT: %v: <error> = bind_name v, <error>
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -93,7 +120,11 @@ fn ChosenBranchIsNonConstant(t: type) {
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %ChosenBranchIsNonConstant.type: type = fn_type @ChosenBranchIsNonConstant [template]
// CHECK:STDOUT: %ChosenBranchIsNonConstant: %ChosenBranchIsNonConstant.type = struct_value () [template]
// CHECK:STDOUT: %true: bool = bool_literal true [template]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
// CHECK:STDOUT: %false: bool = bool_literal false [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -121,14 +152,62 @@ fn ChosenBranchIsNonConstant(t: type) {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @ChosenBranchIsNonConstant(%t.param_patt: type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %v.patt: <error> = binding_pattern v
// CHECK:STDOUT: %.loc9_3: <error> = var_pattern %v.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %v.var: ref <error> = var v
// CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
// CHECK:STDOUT: %int_1.loc9: Core.IntLiteral = int_value 1 [template = constants.%int_1]
// CHECK:STDOUT: assign %v.var, <error>
// CHECK:STDOUT: br !.loc9_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc9_13:
// CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
// CHECK:STDOUT: if %true br !if.expr.then.loc9 else br !if.expr.else.loc9
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc9:
// CHECK:STDOUT: %t.ref.loc9: type = name_ref t, %t
// CHECK:STDOUT: br !if.expr.result.loc9(%t.ref.loc9)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc9:
// CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result.loc9(%i32.loc9)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc9:
// CHECK:STDOUT: %.loc9_10: type = block_arg !if.expr.result.loc9
// CHECK:STDOUT: br !.loc9_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc9_7:
// CHECK:STDOUT: %v: <error> = bind_name v, <error>
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %w.patt: <error> = binding_pattern w
// CHECK:STDOUT: %.loc14_3: <error> = var_pattern %w.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %w.var: ref <error> = var w
// CHECK:STDOUT: %w: ref <error> = bind_name w, %w.var
// CHECK:STDOUT: %int_1.loc14: Core.IntLiteral = int_value 1 [template = constants.%int_1]
// CHECK:STDOUT: assign %w.var, <error>
// CHECK:STDOUT: br !.loc14_13
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc14_13:
// CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
// CHECK:STDOUT: if %false br !if.expr.then.loc14 else br !if.expr.else.loc14
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc14:
// CHECK:STDOUT: %int_32.loc14: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc14: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: br !if.expr.result.loc14(%i32.loc14)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc14:
// CHECK:STDOUT: %t.ref.loc14: type = name_ref t, %t
// CHECK:STDOUT: br !if.expr.result.loc14(%t.ref.loc14)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc14:
// CHECK:STDOUT: %.loc14_10: type = block_arg !if.expr.result.loc14
// CHECK:STDOUT: br !.loc14_7
// CHECK:STDOUT:
// CHECK:STDOUT: !.loc14_7:
// CHECK:STDOUT: %w: <error> = bind_name w, <error>
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
+14 -3
View File
@@ -93,8 +93,11 @@ fn F(cond: bool) {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F(%cond.param_patt: bool) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %a.patt: %struct_type.a.b.501 = binding_pattern a
// CHECK:STDOUT: %.loc14_3.1: %struct_type.a.b.501 = var_pattern %a.patt
// CHECK:STDOUT: }
// CHECK:STDOUT: %a.var: ref %struct_type.a.b.501 = var a
// CHECK:STDOUT: %a: ref %struct_type.a.b.501 = bind_name a, %a.var
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
// CHECK:STDOUT: %.loc14_46.1: %struct_type.a.b.cfd = struct_literal (%int_1, %int_2)
@@ -113,8 +116,16 @@ fn F(cond: bool) {
// CHECK:STDOUT: %.loc14_46.6: ref %i32 = struct_access %a.var, element1
// CHECK:STDOUT: %.loc14_46.7: init %i32 = initialize_from %.loc14_46.5 to %.loc14_46.6 [template = constants.%int_2.ef8]
// CHECK:STDOUT: %.loc14_46.8: init %struct_type.a.b.501 = struct_init (%.loc14_46.4, %.loc14_46.7) to %a.var [template = constants.%struct]
// CHECK:STDOUT: %.loc14_47: init %struct_type.a.b.501 = converted %.loc14_46.1, %.loc14_46.8 [template = constants.%struct]
// CHECK:STDOUT: assign %a.var, %.loc14_47
// CHECK:STDOUT: %.loc14_3.2: init %struct_type.a.b.501 = converted %.loc14_46.1, %.loc14_46.8 [template = constants.%struct]
// CHECK:STDOUT: assign %a.var, %.loc14_3.2
// CHECK:STDOUT: %.loc14_27: type = splice_block %struct_type.a.b [template = constants.%struct_type.a.b.501] {
// CHECK:STDOUT: %int_32.loc14_15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc14_15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %int_32.loc14_24: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc14_24: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [template = constants.%struct_type.a.b.501]
// CHECK:STDOUT: }
// CHECK:STDOUT: %a: ref %struct_type.a.b.501 = bind_name a, %a.var
// CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
// CHECK:STDOUT: %cond.ref: bool = name_ref cond, %cond
// CHECK:STDOUT: if %cond.ref br !if.expr.then else br !if.expr.else