mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 18:32:38 +00:00
Replace the binary `Operation` interfaces with the `OperationWith(T:! type)` interfaces described in the design, and add a `Result` associated type for both unary and binary operations. Update the `impl`s in the prelude for integer types to use the new form, including supporting implicit conversion of either operand. I've tried to split this PR up into commits focused on distinct changes for review convenience. It may be simplest to review it one commit at a time.
123 lines
7.9 KiB
Plaintext
123 lines
7.9 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/fail_generic.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_generic.carbon
|
|
|
|
// TODO: Should this be valid?
|
|
fn F(a: i32) -> i32 {
|
|
let T:! type = i32;
|
|
// CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:14: error: cannot implicitly convert expression of type `Core.IntLiteral` to `T` [ConversionFailure]
|
|
// CHECK:STDERR: let x: T = 5;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:14: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(T)` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: let x: T = 5;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
let x: T = 5;
|
|
// CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `T` to `i32` [ConversionFailure]
|
|
// CHECK:STDERR: return x;
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:3: note: type `T` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: return x;
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
return x;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_generic.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
|
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
|
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
|
// CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %T.8b3: type = bind_symbolic_name T, 0 [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
|
|
// CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T.8b3 [symbolic]
|
|
// CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete]
|
|
// CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
|
|
// CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
|
|
// CHECK:STDOUT: %Convert.type.2751f3.1: type = fn_type @Convert.1, @ImplicitAs(%Dest) [symbolic]
|
|
// CHECK:STDOUT: %Convert.42ebb8.1: %Convert.type.2751f3.1 = struct_value () [symbolic]
|
|
// CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.1: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
|
|
// CHECK:STDOUT: %ImplicitAs.type.d628ce.2: type = facet_type <@ImplicitAs, @ImplicitAs(%T.8b3)> [symbolic]
|
|
// CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.2: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%T.8b3) [symbolic]
|
|
// CHECK:STDOUT: %assoc0.9f5e6b.2: %ImplicitAs.assoc_type.ca0d85.2 = assoc_entity element0, imports.%Core.import_ref.1c7 [symbolic]
|
|
// CHECK:STDOUT: %assoc0.dc0: %ImplicitAs.assoc_type.ca0d85.1 = assoc_entity element0, imports.%Core.import_ref.207 [symbolic]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: .Int = %Core.Int
|
|
// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
|
|
// CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
|
|
// CHECK:STDOUT: %Core.import_ref.492: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.ca0d85.1) = import_ref Core//prelude/operators/as, loc13_35, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.dc0)]
|
|
// CHECK:STDOUT: %Core.import_ref.1c7: @ImplicitAs.%Convert.type (%Convert.type.2751f3.1) = import_ref Core//prelude/operators/as, loc13_35, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.42ebb8.1)]
|
|
// CHECK:STDOUT: %Core.import_ref.207 = import_ref Core//prelude/operators/as, loc13_35, unloaded
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .F = %F.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
|
|
// CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
|
|
// CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
|
|
// CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
|
|
// CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %int_32.loc15_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc15_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %a.param: %i32 = value_param call_param0
|
|
// CHECK:STDOUT: %.loc15: type = splice_block %i32.loc15_9 [concrete = constants.%i32] {
|
|
// CHECK:STDOUT: %int_32.loc15_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc15_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
|
|
// CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
|
|
// CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F(%a.param: %i32) -> %i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32.loc16 [symbolic = constants.%T.8b3]
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %x.patt: %pattern_type.7dcd0a.1 = binding_pattern x [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete = constants.%int_5]
|
|
// CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T.8b3]
|
|
// CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%T.8b3)> [symbolic = constants.%ImplicitAs.type.d628ce.2]
|
|
// CHECK:STDOUT: %.loc24_14.1: %ImplicitAs.assoc_type.ca0d85.2 = specific_constant imports.%Core.import_ref.492, @ImplicitAs(constants.%T.8b3) [symbolic = constants.%assoc0.9f5e6b.2]
|
|
// CHECK:STDOUT: %Convert.ref: %ImplicitAs.assoc_type.ca0d85.2 = name_ref Convert, %.loc24_14.1 [symbolic = constants.%assoc0.9f5e6b.2]
|
|
// CHECK:STDOUT: %.loc24_14.2: %T.8b3 = converted %int_5, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %x: %T.8b3 = bind_name x, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %x.ref: %T.8b3 = name_ref x, %x [concrete = <error>]
|
|
// CHECK:STDOUT: %.loc32: %i32 = converted %x.ref, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: return <error>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|