Model type expressions as regions (#4698)

This is a precondition for enabling the new pattern-matching subsystem
to support binding patterns that have `if` expressions in the type
position.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Geoff Romer
2024-12-19 21:41:06 +00:00
committed by GitHub
co-authored by Richard Smith
parent 95c9634c60
commit a112cbde5c
504 changed files with 5699 additions and 8719 deletions
+5 -75
View File
@@ -117,11 +117,8 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %NoParams.decl: type = class_decl @NoParams [template = constants.%NoParams] {} {}
// CHECK:STDOUT: %EmptyParams.decl: %EmptyParams.type = class_decl @EmptyParams [template = constants.%EmptyParams.generic] {} {}
// CHECK:STDOUT: %NoParams.ref: type = name_ref NoParams, %NoParams.decl [template = constants.%NoParams]
// CHECK:STDOUT: %v.var: ref %NoParams = var v
// CHECK:STDOUT: %v: ref %NoParams = bind_name v, %v.var
// CHECK:STDOUT: %EmptyParams.ref: %EmptyParams.type = name_ref EmptyParams, %EmptyParams.decl [template = constants.%EmptyParams.generic]
// CHECK:STDOUT: %EmptyParams: type = class_type @EmptyParams [template = constants.%EmptyParams]
// CHECK:STDOUT: %w.var: ref %EmptyParams = var w
// CHECK:STDOUT: %w: ref %EmptyParams = bind_name w, %w.var
// CHECK:STDOUT: }
@@ -200,25 +197,8 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
// CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_13.2 (constants.%T)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %Outer.ref.loc9: %Outer.type = name_ref Outer, %Outer.decl [template = constants.%Outer.generic]
// CHECK:STDOUT: %.loc9_15: %empty_struct_type = struct_literal ()
// CHECK:STDOUT: %.loc9_16: type = converted %.loc9_15, constants.%empty_struct_type [template = constants.%empty_struct_type]
// CHECK:STDOUT: %ptr.loc9: type = ptr_type %empty_struct_type [template = constants.%ptr.1]
// CHECK:STDOUT: %Outer.loc9: type = class_type @Outer, @Outer(constants.%ptr.1) [template = constants.%Outer.2]
// CHECK:STDOUT: %v.var: ref %Outer.2 = var v
// CHECK:STDOUT: %v: ref %Outer.2 = bind_name v, %v.var
// CHECK:STDOUT: %Outer.ref.loc19: %Outer.type = name_ref Outer, %Outer.decl [template = constants.%Outer.generic]
// CHECK:STDOUT: %.loc19_15: %empty_struct_type = struct_literal ()
// CHECK:STDOUT: %.loc19_16: type = converted %.loc19_15, constants.%empty_struct_type [template = constants.%empty_struct_type]
// CHECK:STDOUT: %ptr.loc19_16: type = ptr_type %empty_struct_type [template = constants.%ptr.1]
// CHECK:STDOUT: %Outer.loc19: type = class_type @Outer, @Outer(constants.%ptr.1) [template = constants.%Outer.2]
// CHECK:STDOUT: %.loc19_18: %Inner.type.2 = specific_constant @Outer.%Inner.decl, @Outer(constants.%ptr.1) [template = constants.%Inner.generic.2]
// CHECK:STDOUT: %Inner.ref: %Inner.type.2 = name_ref Inner, %.loc19_18 [template = constants.%Inner.generic.2]
// 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: %struct_type.a: type = struct_type {.a: %i32} [template = constants.%struct_type.a]
// CHECK:STDOUT: %ptr.loc19_34: type = ptr_type %struct_type.a [template = constants.%ptr.2]
// CHECK:STDOUT: %Inner: type = class_type @Inner, @Inner(constants.%ptr.1, constants.%ptr.2) [template = constants.%Inner.2]
// CHECK:STDOUT: %w.var: ref %Inner.2 = var w
// CHECK:STDOUT: %w: ref %Inner.2 = bind_name w, %w.var
// CHECK:STDOUT: }
@@ -312,13 +292,6 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %C.1: type = class_type @C, @C(%N.2) [symbolic]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
// CHECK:STDOUT: %complete_type.2: <witness> = complete_type_witness %empty_struct_type [template]
// CHECK:STDOUT: %int_123.1: Core.IntLiteral = int_value 123 [template]
// CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
// CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
// CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
// CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_123.1, %Convert.10 [template]
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
// CHECK:STDOUT: %int_123.2: %i32 = int_value 123 [template]
// CHECK:STDOUT: %C.2: type = class_type @C, @C(%int_123.2) [template]
// CHECK:STDOUT: }
@@ -343,20 +316,13 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %N.patt.loc4_9.1: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_9.2 (constants.%N.patt.2)]
// CHECK:STDOUT: %N.param_patt: %i32 = value_param_pattern %N.patt.loc4_9.1, runtime_param<invalid> [symbolic = %N.patt.loc4_9.2 (constants.%N.patt.2)]
// 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: %N.param: %i32 = value_param runtime_param<invalid>
// CHECK:STDOUT: %.loc4: 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: %N.loc4_9.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc4_9.2 (constants.%N.2)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %C.ref: %C.type = name_ref C, %C.decl [template = constants.%C.generic]
// CHECK:STDOUT: %int_123: Core.IntLiteral = int_value 123 [template = constants.%int_123.1]
// CHECK:STDOUT: %impl.elem0: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_123, %impl.elem0 [template = constants.%Convert.bound]
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
// CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_123) [template = constants.%int_123.2]
// CHECK:STDOUT: %.loc13_13.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_123.2]
// CHECK:STDOUT: %.loc13_13.2: %i32 = converted %int_123, %.loc13_13.1 [template = constants.%int_123.2]
// CHECK:STDOUT: %C: type = class_type @C, @C(constants.%int_123.2) [template = constants.%C.2]
// CHECK:STDOUT: %v.var: ref %C.2 = var v
// CHECK:STDOUT: %v: ref %C.2 = bind_name v, %v.var
// CHECK:STDOUT: }
@@ -412,20 +378,11 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %E: type = class_type @E, @E(%F) [symbolic]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
// CHECK:STDOUT: %complete_type.4: <witness> = complete_type_witness %empty_struct_type [template]
// CHECK:STDOUT: %int_1.1: Core.IntLiteral = int_value 1 [template]
// CHECK:STDOUT: %int_2.1: Core.IntLiteral = int_value 2 [template]
// CHECK:STDOUT: %struct_type.a.b.2: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
// CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
// CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
// CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
// CHECK:STDOUT: %interface.5: <witness> = interface_witness (%Convert.10) [template]
// CHECK:STDOUT: %Convert.bound.1: <bound method> = bound_method %int_1.1, %Convert.10 [template]
// CHECK:STDOUT: %Convert.specific_fn.1: <specific function> = specific_function %Convert.bound.1, @Convert.2(%int_32) [template]
// CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
// CHECK:STDOUT: %Convert.bound.2: <bound method> = bound_method %int_2.1, %Convert.10 [template]
// CHECK:STDOUT: %Convert.specific_fn.2: <specific function> = specific_function %Convert.bound.2, @Convert.2(%int_32) [template]
// CHECK:STDOUT: %int_2.2: %i32 = int_value 2 [template]
// CHECK:STDOUT: %D.val.1: %D = struct_value (%int_1.2, %int_2.2) [template]
// CHECK:STDOUT: %int_3.1: Core.IntLiteral = int_value 3 [template]
// CHECK:STDOUT: %int_4.1: Core.IntLiteral = int_value 4 [template]
// CHECK:STDOUT: %Convert.bound.3: <bound method> = bound_method %int_3.1, %Convert.10 [template]
@@ -459,43 +416,16 @@ var g: E({.a = 1, .b = 2}) = {} as E({.a = 3, .b = 4} as D);
// CHECK:STDOUT: %F.patt.loc9_9.1: %D = symbolic_binding_pattern F, 0 [symbolic = %F.patt.loc9_9.2 (constants.%F.patt)]
// CHECK:STDOUT: %F.param_patt: %D = value_param_pattern %F.patt.loc9_9.1, runtime_param<invalid> [symbolic = %F.patt.loc9_9.2 (constants.%F.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
// CHECK:STDOUT: %F.param: %D = value_param runtime_param<invalid>
// CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
// CHECK:STDOUT: %F.loc9_9.1: %D = bind_symbolic_name F, 0, %F.param [symbolic = %F.loc9_9.2 (constants.%F)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %E.ref: %E.type = name_ref E, %E.decl [template = constants.%E.generic]
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.1]
// CHECK:STDOUT: %.loc24_25.1: %struct_type.a.b.2 = struct_literal (%int_1, %int_2)
// CHECK:STDOUT: %impl.elem0.loc24_25.1: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
// CHECK:STDOUT: %Convert.bound.loc24_25.1: <bound method> = bound_method %int_1, %impl.elem0.loc24_25.1 [template = constants.%Convert.bound.1]
// CHECK:STDOUT: %Convert.specific_fn.loc24_25.1: <specific function> = specific_function %Convert.bound.loc24_25.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.1]
// CHECK:STDOUT: %int.convert_checked.loc24_25.1: init %i32 = call %Convert.specific_fn.loc24_25.1(%int_1) [template = constants.%int_1.2]
// CHECK:STDOUT: %.loc24_25.2: init %i32 = converted %int_1, %int.convert_checked.loc24_25.1 [template = constants.%int_1.2]
// CHECK:STDOUT: %.loc24_25.3: ref %D = temporary_storage
// CHECK:STDOUT: %.loc24_25.4: ref %i32 = class_element_access %.loc24_25.3, element0
// CHECK:STDOUT: %.loc24_25.5: init %i32 = initialize_from %.loc24_25.2 to %.loc24_25.4 [template = constants.%int_1.2]
// CHECK:STDOUT: %impl.elem0.loc24_25.2: %Convert.type.2 = interface_witness_access constants.%interface.5, element0 [template = constants.%Convert.10]
// CHECK:STDOUT: %Convert.bound.loc24_25.2: <bound method> = bound_method %int_2, %impl.elem0.loc24_25.2 [template = constants.%Convert.bound.2]
// CHECK:STDOUT: %Convert.specific_fn.loc24_25.2: <specific function> = specific_function %Convert.bound.loc24_25.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.2]
// CHECK:STDOUT: %int.convert_checked.loc24_25.2: init %i32 = call %Convert.specific_fn.loc24_25.2(%int_2) [template = constants.%int_2.2]
// CHECK:STDOUT: %.loc24_25.6: init %i32 = converted %int_2, %int.convert_checked.loc24_25.2 [template = constants.%int_2.2]
// CHECK:STDOUT: %.loc24_25.7: ref %i32 = class_element_access %.loc24_25.3, element1
// CHECK:STDOUT: %.loc24_25.8: init %i32 = initialize_from %.loc24_25.6 to %.loc24_25.7 [template = constants.%int_2.2]
// CHECK:STDOUT: %.loc24_25.9: init %D = class_init (%.loc24_25.5, %.loc24_25.8), %.loc24_25.3 [template = constants.%D.val.1]
// CHECK:STDOUT: %.loc24_25.10: ref %D = temporary %.loc24_25.3, %.loc24_25.9
// CHECK:STDOUT: %.loc24_26.1: ref %D = converted %.loc24_25.1, %.loc24_25.10
// CHECK:STDOUT: %.loc24_26.2: %D = bind_value %.loc24_26.1
// CHECK:STDOUT: %g.var: ref <error> = var g
// CHECK:STDOUT: %g: ref <error> = bind_name g, %g.var
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @D {
// CHECK:STDOUT: %int_32.loc5: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc5: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc5: %D.elem = field_decl a, element0 [template]
// CHECK:STDOUT: %int_32.loc6: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc6: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc6: %D.elem = field_decl b, element1 [template]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b.1 [template = constants.%complete_type.3]
// CHECK:STDOUT: