Files
carbon-lang/toolchain/check/testdata/eval/symbolic.carbon
T
Richard Smith cefa0397bb More fixes to package and library fingerprinting. (#7297)
Fix import logic to make all imported packages be children of the
`NameScopeId::Package` scope. Previously, indirectly-imported packages
would end up as children of their importing package's scope, which
resulted in them not being treated as packages at all, and in particular
not being fingerprinted as packages.

Fixing that caused a failure in the fingerprinting logic as we started
to encounter packages with no correspoding import scopes. Instead of
looking for import scopes, use a simpler mechanism to map packages to
their package names, and clean up.

Unfortunately the latter change churns all the fingerprints again :(
Hopefully this is the last time for a while.
2026-06-04 17:41:46 +00:00

127 lines
5.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
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/bool.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/eval/symbolic.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/eval/symbolic.carbon
// --- symbolic_call_to_eval_fn.carbon
library "[[@TEST_NAME]]";
eval fn F(B:! bool) -> type {
if (B) { return (); }
return ({}, {});
}
fn G(B:! bool) {
let unused n: F(B) = ({}, {});
}
fn H() {
G(false);
}
// --- fail_symbolic_call_to_eval_fn_invalid_instantiation.carbon
library "[[@TEST_NAME]]";
eval fn F(B:! bool) -> type {
if (B) { return (); }
return ({}, {});
}
fn G(B:! bool) {
let unused n: F(B) = ({}, {});
}
// TODO: Provide a location for the "cannot initialize" error message.
fn H() {
// CHECK:STDERR: fail_symbolic_call_to_eval_fn_invalid_instantiation.carbon:[[@LINE+5]]:3: error: unable to monomorphize specific `G(true)` [ResolvingSpecificHere]
// CHECK:STDERR: G(true);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_symbolic_call_to_eval_fn_invalid_instantiation.carbon: note: cannot initialize tuple of 0 elements from tuple with 2 elements [TupleInitElementCountMismatch]
// CHECK:STDERR:
G(true);
}
// --- dependent_symbolic_instruction.carbon
library "[[@TEST_NAME]]";
interface Z {}
impl {} as Z {}
eval fn E(U:! Z) -> type {
// This makes a FacetAccessType(U) instruction, for which we have to get a
// constant value from the definition in the called function's specific. This
// requires that the called function has its specific definition resolved.
//@dump-sem-ir-begin
return U;
//@dump-sem-ir-end
}
fn F() {
E({});
}
// CHECK:STDOUT: --- dependent_symbolic_instruction.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %Z.impl_witness: <witness> = impl_witness @empty_struct_type.as.Z.impl.%Z.impl_witness_table [concrete]
// CHECK:STDOUT: %Z.facet: %Z.type = facet_value %empty_struct_type, (%Z.impl_witness) [concrete]
// CHECK:STDOUT: %U.013: %Z.type = symbolic_binding U, 0 [symbolic]
// CHECK:STDOUT: %U.as_type.ff1: type = facet_access_type %U.013 [symbolic]
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
// CHECK:STDOUT: %Copy.impl_witness.638: <witness> = impl_witness imports.%Copy.impl_witness_table.4d6 [concrete]
// CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value type, (%Copy.impl_witness.638) [concrete]
// CHECK:STDOUT: %Copy.WithSelf.Op.type.8b3: type = fn_type @Copy.WithSelf.Op, @Copy.WithSelf(%Copy.facet) [concrete]
// CHECK:STDOUT: %.524: type = fn_type_with_self_type %Copy.WithSelf.Op.type.8b3, %Copy.facet [concrete]
// CHECK:STDOUT: %type.as.Copy.impl.Op.type: type = fn_type @type.as.Copy.impl.Op [concrete]
// CHECK:STDOUT: %type.as.Copy.impl.Op: %type.as.Copy.impl.Op.type = struct_value () [concrete]
// CHECK:STDOUT: %type.as.Copy.impl.Op.bound.05d: <bound method> = bound_method %U.as_type.ff1, %type.as.Copy.impl.Op [symbolic]
// CHECK:STDOUT: %type.as.Copy.impl.Op.bound.57f: <bound method> = bound_method %empty_struct_type, %type.as.Copy.impl.Op [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core.import_ref.9c3: %type.as.Copy.impl.Op.type = import_ref Core//prelude/parts/copy, loc{{\d+_\d+}}, loaded [concrete = constants.%type.as.Copy.impl.Op]
// CHECK:STDOUT: %Copy.impl_witness_table.4d6 = impl_witness_table (%Core.import_ref.9c3), @type.as.Copy.impl [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @E(%U.loc6_12.2: %Z.type) {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %U.as_type.loc11_11.2: type = facet_access_type %U.loc6_12.1 [symbolic = %U.as_type.loc11_11.2 (constants.%U.as_type.ff1)]
// CHECK:STDOUT: %type.as.Copy.impl.Op.bound: <bound method> = bound_method %U.as_type.loc11_11.2, constants.%type.as.Copy.impl.Op [symbolic = %type.as.Copy.impl.Op.bound (constants.%type.as.Copy.impl.Op.bound.05d)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn() -> out %return.param: type {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %U.ref: %Z.type = name_ref U, %U.loc6_12.2 [symbolic = %U.loc6_12.1 (constants.%U.013)]
// CHECK:STDOUT: %U.as_type.loc11_11.1: type = facet_access_type %U.ref [symbolic = %U.as_type.loc11_11.2 (constants.%U.as_type.ff1)]
// CHECK:STDOUT: %.loc11: type = converted %U.ref, %U.as_type.loc11_11.1 [symbolic = %U.as_type.loc11_11.2 (constants.%U.as_type.ff1)]
// CHECK:STDOUT: %impl.elem0: %.524 = impl_witness_access constants.%Copy.impl_witness.638, element0 [concrete = constants.%type.as.Copy.impl.Op]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc11, %impl.elem0 [symbolic = %type.as.Copy.impl.Op.bound (constants.%type.as.Copy.impl.Op.bound.05d)]
// CHECK:STDOUT: %type.as.Copy.impl.Op.call: init type = call %bound_method(%.loc11) [symbolic = %U.as_type.loc11_11.2 (constants.%U.as_type.ff1)]
// CHECK:STDOUT: return %type.as.Copy.impl.Op.call
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @E(constants.%U.013) {
// CHECK:STDOUT: %U.loc6_12.1 => constants.%U.013
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @E(constants.%Z.facet) {
// CHECK:STDOUT: %U.loc6_12.1 => constants.%Z.facet
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %U.as_type.loc11_11.2 => constants.%empty_struct_type
// CHECK:STDOUT: %type.as.Copy.impl.Op.bound => constants.%type.as.Copy.impl.Op.bound.57f
// CHECK:STDOUT: }
// CHECK:STDOUT: