mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 08:11:04 +01:00
Factor out logic to evaluate `EntityNameId` instead of duplicating it between `BindSymbolicName` and `SymbolicBindingPattern`. Remove support in `SymbolicBindingPattern` for evaluating a pattern to the constant value of the corresponding binding, which doesn't really make any sense given that patterns don't generally evaluate to the value that they matched. This results in the handling for `SymbolicBindingPattern` being simply the default handling for an always-constant instruction, so remove the special case for it entirely and change its constant kind to `Always`. It's not entirely clear that it makes sense for `SymbolicBindingPattern` to be treated as a constant when other patterns aren't, but we seem to be relying on this in various places, so leave it as a constant for now. Changing it to never be constant will be a smaller change now -- it just requires changing the `constant_kind`. The IR changes in the tests are fairly widespread, but mechanical, and there are two kinds of things changing: - `symbolic_binding_pattern`s in specifics now evaluate to `symbolic_binding_pattern`s, not to the argument values. This means in a few cases we end up with additional `symbolic_binding_pattern` constants. - We evaluate the type operand of `symbolic_binding_pattern` now, so an error in the type will now properly be propagated into an error in the pattern's constant value.
174 lines
7.5 KiB
Plaintext
174 lines
7.5 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
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/where_expr/fail_not_facet.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/fail_not_facet.carbon
|
|
|
|
// --- fail_left_where_not_facet.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_left_where_not_facet.carbon:[[@LINE+4]]:10: error: left argument of `where` operator must be a facet type [WhereOnNonFacetType]
|
|
// CHECK:STDERR: fn F(T:! i32 where .Self == bool);
|
|
// CHECK:STDERR: ^~~
|
|
// CHECK:STDERR:
|
|
fn F(T:! i32 where .Self == bool);
|
|
|
|
// --- fail_left_where_unknown.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_left_where_unknown.carbon:[[@LINE+4]]:10: error: name `NOT_DECLARED` not found [NameNotFound]
|
|
// CHECK:STDERR: fn G(U:! NOT_DECLARED where .Self == bool);
|
|
// CHECK:STDERR: ^~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn G(U:! NOT_DECLARED where .Self == bool);
|
|
|
|
// --- fail_var.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:8: error: name `e` not found [NameNotFound]
|
|
// CHECK:STDERR: var v: e where .x = 3;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
var v: e where .x = 3;
|
|
|
|
// CHECK:STDOUT: --- fail_left_where_not_facet.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
|
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
|
|
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: .Int = %Core.Int
|
|
// CHECK:STDOUT: .Bool = %Core.Bool
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// 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: %T.patt: <error> = symbolic_binding_pattern T, 0 [concrete = <error>]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc8_14.1: type = splice_block %.loc8_14.2 [concrete = <error>] {
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
|
|
// CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
|
|
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
|
|
// CHECK:STDOUT: %.loc8_14.2: type = where_expr %.Self [concrete = <error>] {
|
|
// CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T: <error> = bind_symbolic_name T, 0 [concrete = <error>]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @F(%T: <error>) {
|
|
// CHECK:STDOUT: fn(%T.patt: <error>);
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @F(<error>) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_left_where_unknown.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
|
|
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
|
|
// CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: .Bool = %Core.Bool
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .NOT_DECLARED = <poisoned>
|
|
// CHECK:STDOUT: .G = %G.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
|
|
// CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [concrete = <error>]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc8_23.1: type = splice_block %.loc8_23.2 [concrete = <error>] {
|
|
// CHECK:STDOUT: %NOT_DECLARED.ref: <error> = name_ref NOT_DECLARED, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
|
|
// CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
|
|
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
|
|
// CHECK:STDOUT: %.loc8_23.2: type = where_expr %.Self [concrete = <error>] {
|
|
// CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [concrete = <error>]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @G(%U: <error>) {
|
|
// CHECK:STDOUT: fn(%U.patt: <error>);
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @G(<error>) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_var.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .e = <poisoned>
|
|
// CHECK:STDOUT: .v = %v
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %v.patt: <error> = binding_pattern v
|
|
// CHECK:STDOUT: %.loc8_1: <error> = var_pattern %v.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %v.var: ref <error> = var v
|
|
// CHECK:STDOUT: %.loc8_10.1: type = splice_block %.loc8_10.2 [concrete = <error>] {
|
|
// CHECK:STDOUT: %e.ref: <error> = name_ref e, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
|
|
// CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
|
|
// CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
|
|
// CHECK:STDOUT: %.loc8_10.2: type = where_expr %.Self [concrete = <error>] {
|
|
// CHECK:STDOUT: requirement_rewrite %x.ref, <error>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %v: <error> = bind_name v, <error>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|