Enable heterogeneous compound assignments for CppCompat.Long32 (#6628)

Context: https://github.com/carbon-language/carbon-lang/issues/6275.

Part of https://github.com/carbon-language/carbon-lang/issues/5263.
This commit is contained in:
Ivana Ivanovska
2026-01-21 13:27:58 +00:00
committed by GitHub
parent 67163096b6
commit a448792207
3 changed files with 1135 additions and 134 deletions
+20 -11
View File
@@ -216,50 +216,59 @@ final impl CppCompat.Long32 as RightShiftWith(Self) where .Result = Self {
// Compound arithmetic assignments.
impl CppCompat.Long32 as AddAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as AddAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.sadd_assign";
}
impl CppCompat.Long32 as SubAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as SubAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.ssub_assign";
}
impl CppCompat.Long32 as MulAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as MulAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.smul_assign";
}
impl CppCompat.Long32 as DivAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as DivAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.sdiv_assign";
}
impl CppCompat.Long32 as ModAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as ModAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.smod_assign";
}
// Compound bitwise assignments.
impl CppCompat.Long32 as BitAndAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as BitAndAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.and_assign";
}
impl CppCompat.Long32 as BitOrAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as BitOrAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.or_assign";
}
impl CppCompat.Long32 as BitXorAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as BitXorAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.xor_assign";
}
impl CppCompat.Long32 as LeftShiftAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as LeftShiftAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.left_shift_assign";
}
impl CppCompat.Long32 as RightShiftAssignWith(CppCompat.Long32) {
impl forall [U:! ImplicitAs(CppCompat.Long32)]
CppCompat.Long32 as RightShiftAssignWith(U) {
fn Op[ref self: Self](other: Self) = "int.right_shift_assign";
}
// TODO: ULong32, LongLong64, ULongLong64: compound assignments.
// TODO: Long32: heterogeneous compound assignments.
// Increment and decrement.
impl CppCompat.Long32 as Dec {
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -852,8 +852,8 @@ fn CopyUnsignedLongLong() {
// CHECK:STDOUT: %ImplicitAs.Convert.type.71e: type = fn_type @ImplicitAs.Convert, @ImplicitAs(Core.IntLiteral) [concrete]
// CHECK:STDOUT: %ImplicitAs.type.584: type = facet_type <@ImplicitAs, @ImplicitAs(%u64)> [concrete]
// CHECK:STDOUT: %ImplicitAs.Convert.type.c65: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%u64) [concrete]
// CHECK:STDOUT: %ImplicitAs.impl_witness.438: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.517 [concrete]
// CHECK:STDOUT: %ImplicitAs.facet.195: %ImplicitAs.type.407 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.438) [concrete]
// CHECK:STDOUT: %ImplicitAs.impl_witness.4384: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.517 [concrete]
// CHECK:STDOUT: %ImplicitAs.facet.195: %ImplicitAs.type.407 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.4384) [concrete]
// CHECK:STDOUT: %.dd7: type = fn_type_with_self_type %ImplicitAs.Convert.type.c4b, %ImplicitAs.facet.195 [concrete]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.bcb: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert.1 [concrete]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.f87: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.bcb = struct_value () [concrete]
@@ -990,7 +990,7 @@ fn CopyUnsignedLongLong() {
// CHECK:STDOUT: %Cpp.ref.loc15: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %unsigned_long_long.ref.loc15: type = name_ref unsigned_long_long, constants.%Cpp.unsigned_long_long [concrete = constants.%Cpp.unsigned_long_long]
// CHECK:STDOUT: }
// CHECK:STDOUT: %impl.elem0.loc15: %.dd7 = impl_witness_access constants.%ImplicitAs.impl_witness.438, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f87]
// CHECK:STDOUT: %impl.elem0.loc15: %.dd7 = impl_witness_access constants.%ImplicitAs.impl_witness.4384, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f87]
// CHECK:STDOUT: %bound_method.loc15: <bound method> = bound_method %int_1.loc15, %impl.elem0.loc15 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %Cpp.unsigned_long_long = call %bound_method.loc15(%int_1.loc15) [concrete = constants.%int_1.79a]
// CHECK:STDOUT: %.loc15_56.1: %Cpp.unsigned_long_long = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_1.79a]
@@ -1137,8 +1137,8 @@ fn CopyUnsignedLongLong() {
// CHECK:STDOUT: %ImplicitAs.Convert.type.c4b: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%Cpp.unsigned_long_long) [concrete]
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
// CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
// CHECK:STDOUT: %ImplicitAs.impl_witness.438: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.517 [concrete]
// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.407 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.438) [concrete]
// CHECK:STDOUT: %ImplicitAs.impl_witness.4384: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.517 [concrete]
// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.407 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.4384) [concrete]
// CHECK:STDOUT: %.dd7: type = fn_type_with_self_type %ImplicitAs.Convert.type.c4b, %ImplicitAs.facet [concrete]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert [concrete]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type = struct_value () [concrete]
@@ -1172,7 +1172,7 @@ fn CopyUnsignedLongLong() {
// CHECK:STDOUT: }
// CHECK:STDOUT: %a.var: ref %Cpp.unsigned_long_long = var %a.var_patt
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
// CHECK:STDOUT: %impl.elem0.loc8: %.dd7 = impl_witness_access constants.%ImplicitAs.impl_witness.438, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert]
// CHECK:STDOUT: %impl.elem0.loc8: %.dd7 = impl_witness_access constants.%ImplicitAs.impl_witness.4384, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert]
// CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %int_1, %impl.elem0.loc8 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %Cpp.unsigned_long_long = call %bound_method.loc8(%int_1) [concrete = constants.%int_1.79a]
// CHECK:STDOUT: %.loc8_3: init %Cpp.unsigned_long_long = converted %int_1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_1.79a]