mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Implementing interface modifiers causes an infinite loop when generating fingerprints because the witness value generates a fingerprint that's dependent on something dependent on the witness value. We've debugged this to the witness table's `elements_id` field. This hack is a workaround for creating a new block type whose value is not codependent with its identity. Co-authored-by: Richard Smith <richard@metafoo.co.uk> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
211 lines
12 KiB
Plaintext
211 lines
12 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
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/convert_facet_value_to_itself.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/convert_facet_value_to_itself.carbon
|
|
|
|
interface Animal {}
|
|
|
|
fn FeedAnimal(unused generic T: Animal) {}
|
|
|
|
fn HandleAnimal(generic T: Animal) { FeedAnimal(T); }
|
|
|
|
class Goat {}
|
|
impl Goat as Animal {}
|
|
|
|
fn F() {
|
|
HandleAnimal(Goat);
|
|
}
|
|
|
|
// CHECK:STDOUT: --- convert_facet_value_to_itself.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Animal.type: type = facet_type <@Animal> [concrete]
|
|
// CHECK:STDOUT: %Self: %Animal.type = symbolic_binding Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %Animal.type [concrete]
|
|
// CHECK:STDOUT: %T.patt.e44e2f.1: %pattern_type = symbolic_binding_pattern T, 0 [symbolic]
|
|
// CHECK:STDOUT: %T.443025.1: %Animal.type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %FeedAnimal.type: type = fn_type @FeedAnimal [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %FeedAnimal: %FeedAnimal.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %T.patt.e44e2f.2: %pattern_type = symbolic_binding_pattern T, 0 [symbolic]
|
|
// CHECK:STDOUT: %T.443025.2: %Animal.type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %HandleAnimal.type: type = fn_type @HandleAnimal [concrete]
|
|
// CHECK:STDOUT: %HandleAnimal: %HandleAnimal.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %FeedAnimal.specific_fn.5bd: <specific function> = specific_function %FeedAnimal, @FeedAnimal(%T.443025.2) [symbolic]
|
|
// CHECK:STDOUT: %Goat: type = class_type @Goat [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: %.629: <witness> = impl_self_witness %Goat, @Animal [concrete]
|
|
// CHECK:STDOUT: %Animal.impl_witness: <witness> = impl_witness @Goat.as.Animal.impl.%Animal.impl_witness_table [concrete]
|
|
// CHECK:STDOUT: %Animal.facet: %Animal.type = facet_value %Goat, (%Animal.impl_witness) [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %HandleAnimal.specific_fn: <specific function> = specific_function %HandleAnimal, @HandleAnimal(%Animal.facet) [concrete]
|
|
// CHECK:STDOUT: %FeedAnimal.specific_fn.99a: <specific function> = specific_function %FeedAnimal, @FeedAnimal(%Animal.facet) [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: .Animal = %Animal.decl
|
|
// CHECK:STDOUT: .FeedAnimal = %FeedAnimal.decl
|
|
// CHECK:STDOUT: .HandleAnimal = %HandleAnimal.decl
|
|
// CHECK:STDOUT: .Goat = %Goat.decl
|
|
// CHECK:STDOUT: .F = %F.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Animal.decl: type = interface_decl @Animal [concrete = constants.%Animal.type] {} {}
|
|
// CHECK:STDOUT: %FeedAnimal.decl: %FeedAnimal.type = fn_decl @FeedAnimal [concrete = constants.%FeedAnimal] {
|
|
// CHECK:STDOUT: %T.patt.loc17_31.1: %pattern_type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc17_31.2 (constants.%T.patt.e44e2f.1)]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc17: type = splice_block %Animal.ref [concrete = constants.%Animal.type] {
|
|
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
|
// CHECK:STDOUT: %Animal.ref: type = name_ref Animal, file.%Animal.decl [concrete = constants.%Animal.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc17_31.2: %Animal.type = symbolic_binding T, 0 [symbolic = %T.loc17_31.1 (constants.%T.443025.1)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %HandleAnimal.decl: %HandleAnimal.type = fn_decl @HandleAnimal [concrete = constants.%HandleAnimal] {
|
|
// CHECK:STDOUT: %T.patt.loc19_26.1: %pattern_type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc19_26.2 (constants.%T.patt.e44e2f.2)]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc19: type = splice_block %Animal.ref [concrete = constants.%Animal.type] {
|
|
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
|
// CHECK:STDOUT: %Animal.ref: type = name_ref Animal, file.%Animal.decl [concrete = constants.%Animal.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc19_26.2: %Animal.type = symbolic_binding T, 0 [symbolic = %T.loc19_26.1 (constants.%T.443025.2)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Goat.decl: type = class_decl @Goat [concrete = constants.%Goat] {} {}
|
|
// CHECK:STDOUT: impl_decl @Goat.as.Animal.impl [concrete] {} {
|
|
// CHECK:STDOUT: %Goat.ref: type = name_ref Goat, file.%Goat.decl [concrete = constants.%Goat]
|
|
// CHECK:STDOUT: %Animal.ref: type = name_ref Animal, file.%Animal.decl [concrete = constants.%Animal.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.loc22: <witness> = impl_self_witness @Goat.as.Animal.impl.%Goat.ref, @Animal [concrete = constants.%.629]
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @Animal {
|
|
// CHECK:STDOUT: %Self: %Animal.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
|
|
// CHECK:STDOUT: %Animal.WithSelf.decl = interface_with_self_decl @Animal [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: impl @Goat.as.Animal.impl: %Goat.ref as %Animal.ref {
|
|
// CHECK:STDOUT: %Animal.impl_witness_table = impl_witness_table (), @Goat.as.Animal.impl [concrete]
|
|
// CHECK:STDOUT: %Animal.impl_witness: <witness> = impl_witness %Animal.impl_witness_table [concrete = constants.%Animal.impl_witness]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: extend %Animal.ref
|
|
// CHECK:STDOUT: witness = %Animal.impl_witness
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Goat {
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%Goat
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @FeedAnimal(%T.loc17_31.2: %Animal.type) {
|
|
// CHECK:STDOUT: %T.patt.loc17_31.2: %pattern_type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc17_31.2 (constants.%T.patt.e44e2f.1)]
|
|
// CHECK:STDOUT: %T.loc17_31.1: %Animal.type = symbolic_binding T, 0 [symbolic = %T.loc17_31.1 (constants.%T.443025.1)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @HandleAnimal(%T.loc19_26.2: %Animal.type) {
|
|
// CHECK:STDOUT: %T.patt.loc19_26.2: %pattern_type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc19_26.2 (constants.%T.patt.e44e2f.2)]
|
|
// CHECK:STDOUT: %T.loc19_26.1: %Animal.type = symbolic_binding T, 0 [symbolic = %T.loc19_26.1 (constants.%T.443025.2)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %FeedAnimal.specific_fn.loc19_38.2: <specific function> = specific_function constants.%FeedAnimal, @FeedAnimal(%T.loc19_26.1) [symbolic = %FeedAnimal.specific_fn.loc19_38.2 (constants.%FeedAnimal.specific_fn.5bd)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %FeedAnimal.ref: %FeedAnimal.type = name_ref FeedAnimal, file.%FeedAnimal.decl [concrete = constants.%FeedAnimal]
|
|
// CHECK:STDOUT: %T.ref: %Animal.type = name_ref T, %T.loc19_26.2 [symbolic = %T.loc19_26.1 (constants.%T.443025.2)]
|
|
// CHECK:STDOUT: %FeedAnimal.specific_fn.loc19_38.1: <specific function> = specific_function %FeedAnimal.ref, @FeedAnimal(constants.%T.443025.2) [symbolic = %FeedAnimal.specific_fn.loc19_38.2 (constants.%FeedAnimal.specific_fn.5bd)]
|
|
// CHECK:STDOUT: %FeedAnimal.call: init %empty_tuple.type = call %FeedAnimal.specific_fn.loc19_38.1()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %HandleAnimal.ref: %HandleAnimal.type = name_ref HandleAnimal, file.%HandleAnimal.decl [concrete = constants.%HandleAnimal]
|
|
// CHECK:STDOUT: %Goat.ref: type = name_ref Goat, file.%Goat.decl [concrete = constants.%Goat]
|
|
// CHECK:STDOUT: %Animal.facet: %Animal.type = facet_value %Goat.ref, (constants.%Animal.impl_witness) [concrete = constants.%Animal.facet]
|
|
// CHECK:STDOUT: %.loc25: %Animal.type = converted %Goat.ref, %Animal.facet [concrete = constants.%Animal.facet]
|
|
// CHECK:STDOUT: %HandleAnimal.specific_fn: <specific function> = specific_function %HandleAnimal.ref, @HandleAnimal(constants.%Animal.facet) [concrete = constants.%HandleAnimal.specific_fn]
|
|
// CHECK:STDOUT: %HandleAnimal.call: init %empty_tuple.type = call %HandleAnimal.specific_fn()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Animal.WithSelf(constants.%Self) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @FeedAnimal(constants.%T.443025.1) {
|
|
// CHECK:STDOUT: %T.patt.loc17_31.2 => constants.%T.patt.e44e2f.1
|
|
// CHECK:STDOUT: %T.loc17_31.1 => constants.%T.443025.1
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @HandleAnimal(constants.%T.443025.2) {
|
|
// CHECK:STDOUT: %T.patt.loc19_26.2 => constants.%T.patt.e44e2f.2
|
|
// CHECK:STDOUT: %T.loc19_26.1 => constants.%T.443025.2
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @FeedAnimal(constants.%T.443025.2) {
|
|
// CHECK:STDOUT: %T.patt.loc17_31.2 => constants.%T.patt.e44e2f.1
|
|
// CHECK:STDOUT: %T.loc17_31.1 => constants.%T.443025.2
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Animal.WithSelf(constants.%Animal.facet) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @HandleAnimal(constants.%Animal.facet) {
|
|
// CHECK:STDOUT: %T.patt.loc19_26.2 => constants.%T.patt.e44e2f.2
|
|
// CHECK:STDOUT: %T.loc19_26.1 => constants.%Animal.facet
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %FeedAnimal.specific_fn.loc19_38.2 => constants.%FeedAnimal.specific_fn.99a
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @FeedAnimal(constants.%Animal.facet) {
|
|
// CHECK:STDOUT: %T.patt.loc17_31.2 => constants.%T.patt.e44e2f.1
|
|
// CHECK:STDOUT: %T.loc17_31.1 => constants.%Animal.facet
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|