mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Improve lowering for global variables. (#5492)
- Track the `VarPattern` instruction on the `VarStorage` instruction so that it's available for name mangling. - Mangle global variables based on the first binding name within their pattern. - Give global variables external rather than internal linkage, except if they have no bindings whatsoever in their pattern. - To support lowering references to bindings nested within a global var, such as for `var (x: i32, b: i32)`, add some basic initial support for reference constant expressions. Treat a global `var` as a reference constant, and treat an aggregate access into a reference constant as a reference constant.
This commit is contained in:
@@ -1315,17 +1315,17 @@ fn F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a [concrete]
|
||||
// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: %a.var_patt: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var a
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var %a.var_patt
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound]
|
||||
// CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
|
||||
// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3.2
|
||||
// CHECK:STDOUT: %.loc7_3: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3
|
||||
// CHECK:STDOUT: %.loc7_10: type = splice_block %i16 [concrete = constants.%i16] {
|
||||
// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16]
|
||||
// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16]
|
||||
@@ -1400,17 +1400,17 @@ fn F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a [concrete]
|
||||
// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: %a.var_patt: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var a
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var %a.var_patt
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound]
|
||||
// CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
|
||||
// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3.2
|
||||
// CHECK:STDOUT: %.loc7_3: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3
|
||||
// CHECK:STDOUT: %.loc7_10: type = splice_block %i16 [concrete = constants.%i16] {
|
||||
// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16]
|
||||
// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16]
|
||||
@@ -1486,17 +1486,17 @@ fn F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a [concrete]
|
||||
// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: %a.var_patt: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var a
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var %a.var_patt
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound]
|
||||
// CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
|
||||
// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3.2
|
||||
// CHECK:STDOUT: %.loc7_3: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3
|
||||
// CHECK:STDOUT: %.loc7_10: type = splice_block %i16 [concrete = constants.%i16] {
|
||||
// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16]
|
||||
// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16]
|
||||
@@ -1573,17 +1573,17 @@ fn F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a [concrete]
|
||||
// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: %a.var_patt: %pattern_type.2f8 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var a
|
||||
// CHECK:STDOUT: %a.var: ref %i16 = var %a.var_patt
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound]
|
||||
// CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc7_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
|
||||
// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3.2
|
||||
// CHECK:STDOUT: %.loc7_3: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90]
|
||||
// CHECK:STDOUT: assign %a.var, %.loc7_3
|
||||
// CHECK:STDOUT: %.loc7_10: type = splice_block %i16 [concrete = constants.%i16] {
|
||||
// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16]
|
||||
// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16]
|
||||
|
||||
Reference in New Issue
Block a user