mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Model Core.Int as a class type (#4644)
Instead of treating `Core.Int` as the toolchain's builtin `IntType`, model it as a class that adapts the builtin type. This aligns us better with the intended language model, gives an associated library for `impl`s involving `Core.Int` to live within, and opens the door adding member functions to `Core.Int` if we decide that is desirable. Remarkably it also seems to make the formatted SemIR a little smaller, because a call to a generic class generates less IR than a call to a function.
This commit is contained in:
+27
-35
@@ -137,15 +137,13 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: %Inner.generic.1: %Inner.type.1 = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %Inner.1: type = class_type @Inner, @Inner(%T, %U) [symbolic]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
|
||||
// CHECK:STDOUT: %complete_type.1: <witness> = complete_type_witness %empty_struct_type [template]
|
||||
// CHECK:STDOUT: %ptr.1: type = ptr_type %empty_struct_type [template]
|
||||
// CHECK:STDOUT: %Outer.2: type = class_type @Outer, @Outer(%ptr.1) [template]
|
||||
// CHECK:STDOUT: %Inner.type.2: type = generic_class_type @Inner, @Outer(%ptr.1) [template]
|
||||
// CHECK:STDOUT: %Inner.generic.2: %Inner.type.2 = struct_value () [template]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
|
||||
// CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
|
||||
// CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
|
||||
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
|
||||
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [template]
|
||||
// CHECK:STDOUT: %ptr.2: type = ptr_type %struct_type.a [template]
|
||||
// CHECK:STDOUT: %Inner.2: type = class_type @Inner, @Inner(%ptr.1, %ptr.2) [template]
|
||||
@@ -154,7 +152,7 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
||||
// CHECK:STDOUT: .Int = %import_ref.1
|
||||
// CHECK:STDOUT: .ImplicitAs = %import_ref.2
|
||||
// CHECK:STDOUT: .ImplicitAs = %import_ref.5
|
||||
// CHECK:STDOUT: import Core//prelude
|
||||
// CHECK:STDOUT: import Core//prelude/...
|
||||
// CHECK:STDOUT: }
|
||||
@@ -190,9 +188,7 @@ var v: C(123) = ();
|
||||
// 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: %int.make_type_signed: init type = call constants.%Int(%int_32) [template = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc19_30.1: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc19_30.2: type = converted %int.make_type_signed, %.loc19_30.1 [template = constants.%i32]
|
||||
// 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]
|
||||
@@ -216,7 +212,7 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: %U.param: type = value_param runtime_param<invalid>
|
||||
// CHECK:STDOUT: %U.loc5_15.1: type = bind_symbolic_name U, 1, %U.param [symbolic = %U.loc5_15.2 (constants.%U)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.1]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = constants.%Outer.1
|
||||
@@ -232,7 +228,7 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class {
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.1]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = constants.%Inner.1
|
||||
@@ -283,23 +279,21 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
|
||||
// CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
|
||||
// CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
|
||||
// CHECK:STDOUT: %N.1: %i32 = bind_symbolic_name N, 0 [symbolic]
|
||||
// CHECK:STDOUT: %N.patt.1: %i32 = symbolic_binding_pattern N, 0 [symbolic]
|
||||
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
|
||||
// CHECK:STDOUT: %N.2: %i32 = bind_symbolic_name N, 0 [symbolic]
|
||||
// CHECK:STDOUT: %N.patt.2: %i32 = symbolic_binding_pattern N, 0 [symbolic]
|
||||
// CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
|
||||
// CHECK:STDOUT: %C.generic: %C.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %C.1: type = class_type @C, @C(%N.1) [symbolic]
|
||||
// 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.1: <witness> = complete_type_witness %empty_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.14: type = fn_type @Convert.2, @impl.1(%int_32) [template]
|
||||
// CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
|
||||
// CHECK:STDOUT: %interface.9: <witness> = interface_witness (%Convert.14) [template]
|
||||
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_123.1, %Convert.14 [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]
|
||||
@@ -308,7 +302,7 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
||||
// CHECK:STDOUT: .Int = %import_ref.1
|
||||
// CHECK:STDOUT: .ImplicitAs = %import_ref.2
|
||||
// CHECK:STDOUT: .ImplicitAs = %import_ref.5
|
||||
// CHECK:STDOUT: import Core//prelude
|
||||
// CHECK:STDOUT: import Core//prelude/...
|
||||
// CHECK:STDOUT: }
|
||||
@@ -322,19 +316,17 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Core.import = import Core
|
||||
// CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.generic] {
|
||||
// CHECK:STDOUT: %N.patt.loc4_9.1: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_9.2 (constants.%N.patt.1)]
|
||||
// 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.1)]
|
||||
// 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: %int.make_type_signed: init type = call constants.%Int(%int_32) [template = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc4_13.2: type = converted %int.make_type_signed, %.loc4_13.1 [template = constants.%i32]
|
||||
// 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: %N.loc4_9.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc4_9.2 (constants.%N.1)]
|
||||
// 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.9, element0 [template = constants.%Convert.14]
|
||||
// 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]
|
||||
@@ -346,13 +338,13 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: generic class @C(%N.loc4_9.1: %i32) {
|
||||
// CHECK:STDOUT: %N.loc4_9.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc4_9.2 (constants.%N.1)]
|
||||
// CHECK:STDOUT: %N.patt.loc4_9.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_9.2 (constants.%N.patt.1)]
|
||||
// CHECK:STDOUT: %N.loc4_9.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc4_9.2 (constants.%N.2)]
|
||||
// CHECK:STDOUT: %N.patt.loc4_9.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_9.2 (constants.%N.patt.2)]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class {
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.1]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.2]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = constants.%C.1
|
||||
@@ -368,9 +360,9 @@ var v: C(123) = ();
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @C(constants.%N.1) {
|
||||
// CHECK:STDOUT: %N.loc4_9.2 => constants.%N.1
|
||||
// CHECK:STDOUT: %N.patt.loc4_9.2 => constants.%N.1
|
||||
// CHECK:STDOUT: specific @C(constants.%N.2) {
|
||||
// CHECK:STDOUT: %N.loc4_9.2 => constants.%N.2
|
||||
// CHECK:STDOUT: %N.patt.loc4_9.2 => constants.%N.2
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @C(constants.%int_123.2) {
|
||||
|
||||
Reference in New Issue
Block a user