mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 22:22:38 +00:00
This is in support of a goal of changing the blanket `destroy` impl to
use (roughly):
```
private fn CanAggregateDestroy() -> type = "type.can_aggregate_destroy";
// Handles aggregate type destruction.
impl forall [AggregateDestroyT:! CanAggregateDestroy()] AggregateDestroyT as Destroy {
fn Op[addr self: Self*]() = "type.aggregate_destroy";
}
```
That isn't done here because there's still other issues that migrating
raises. What this *does* do is add the builtin functions, and in
particular, support to `FacetTypeInfo` to make `CanAggregateDestroy`
work.
The "special requirement" approach in `FacetTypeInfo` allows us to
support restricting a blanket impl under the current approach of impls.
Maybe we'll find a cleaner approach that can work in the future, but
this fits into the current model by propagating similar to other
requirements. I'm using an enum mask because we have a number of similar
things to add (e.g. copy, move) but I'm not sure we need a full vector.
A few alternatives considered were:
- Supporting syntax more like `where .Self impls
TypeCanAggregateDestroy(.Self, SupportedInterface,
UnsupportedInterface)`. I think it'd be a little cleaner, but requires
better compile-time evaluation in order to assess the type of the call.
Right now it's expected to be a `FacetType` too early to make this work,
and I was concerned about pouring too much more time down this route.
- Providing an actual interface, in particular doing name lookup back
into `Core.` for an interface. This would've added name lookup overhead,
and the question of whether an `impl` exists.
- Generating an interface. This avoids the name lookup, but would still
raise the question of whether an `impl` should also be generated. Work
I've previously done generating interfaces for class destruction also
feels complex to both write and understand (an unfortunate issue).
- Still modeling as an `ImplsConstraint`, for example by defining a
special `InterfaceId::CanAggregateDestroy = -2` similar to what we do on
other ids. I was hesitant because of how this expands the number of
modes of `InterfaceId`, and things for consuming code to watch out for,
for what feels like a relatively niche set of use-cases that are only
interface-like.
---------
Co-authored-by: Dana Jansens <danakj@orodu.net>
162 lines
11 KiB
Plaintext
162 lines
11 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/primitives.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/where_expr/dot_self_index.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/dot_self_index.carbon
|
|
|
|
interface Empty(W:! type) {
|
|
let A:! type;
|
|
}
|
|
|
|
// T has index 0
|
|
// .Self has index invalid, not 1
|
|
// V has index 1, does not match .Self
|
|
//@dump-sem-ir-begin
|
|
fn H(T:! type, U: Empty(T) where .A = T*, V:! type) {}
|
|
//@dump-sem-ir-end
|
|
|
|
fn G(U: Empty(i32) where .A = i32*) {
|
|
H(i32, U, bool);
|
|
}
|
|
|
|
// CHECK:STDOUT: --- dot_self_index.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
|
|
// CHECK:STDOUT: %Empty.type.d5a: type = generic_interface_type @Empty [concrete]
|
|
// CHECK:STDOUT: %Empty.generic: %Empty.type.d5a = struct_value () [concrete]
|
|
// CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
|
|
// CHECK:STDOUT: %Empty.type.752200.2: type = facet_type <@Empty, @Empty(%T)> [symbolic]
|
|
// CHECK:STDOUT: %.Self.ac8: %Empty.type.752200.2 = bind_symbolic_name .Self [symbolic]
|
|
// CHECK:STDOUT: %Empty.assoc_type.3cf698.2: type = assoc_entity_type @Empty, @Empty(%T) [symbolic]
|
|
// CHECK:STDOUT: %assoc0.3715ce.2: %Empty.assoc_type.3cf698.2 = assoc_entity element0, @Empty.%A [symbolic]
|
|
// CHECK:STDOUT: %require_complete.059: <witness> = require_complete_type %Empty.type.752200.2 [symbolic]
|
|
// CHECK:STDOUT: %.Self.as_type.4e9: type = facet_access_type %.Self.ac8 [symbolic]
|
|
// CHECK:STDOUT: %Empty.lookup_impl_witness.e0b: <witness> = lookup_impl_witness %.Self.ac8, @Empty, @Empty(%T) [symbolic]
|
|
// CHECK:STDOUT: %impl.elem0.c5c: type = impl_witness_access %Empty.lookup_impl_witness.e0b, element0 [symbolic]
|
|
// CHECK:STDOUT: %ptr.79f: type = ptr_type %T [symbolic]
|
|
// CHECK:STDOUT: %Empty_where.type.b70: type = facet_type <@Empty, @Empty(%T) where %impl.elem0.c5c = %ptr.79f> [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.382: type = pattern_type %Empty_where.type.b70 [symbolic]
|
|
// CHECK:STDOUT: %V: type = bind_symbolic_name V, 1 [symbolic]
|
|
// CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
|
|
// CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %require_complete.63d: <witness> = require_complete_type %Empty_where.type.b70 [symbolic]
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
|
// CHECK:STDOUT: %Empty.type.d26: type = facet_type <@Empty, @Empty(%i32)> [concrete]
|
|
// CHECK:STDOUT: %.Self.aa8: %Empty.type.d26 = bind_symbolic_name .Self [symbolic_self]
|
|
// CHECK:STDOUT: %Empty.assoc_type.7c7: type = assoc_entity_type @Empty, @Empty(%i32) [concrete]
|
|
// CHECK:STDOUT: %assoc0.758: %Empty.assoc_type.7c7 = assoc_entity element0, @Empty.%A [concrete]
|
|
// CHECK:STDOUT: %.Self.as_type.05b: type = facet_access_type %.Self.aa8 [symbolic_self]
|
|
// CHECK:STDOUT: %Empty.lookup_impl_witness.4e5: <witness> = lookup_impl_witness %.Self.aa8, @Empty, @Empty(%i32) [symbolic_self]
|
|
// CHECK:STDOUT: %impl.elem0.36f: type = impl_witness_access %Empty.lookup_impl_witness.4e5, element0 [symbolic_self]
|
|
// CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
|
|
// CHECK:STDOUT: %Empty_where.type.9ab: type = facet_type <@Empty, @Empty(%i32) where %impl.elem0.36f = %ptr.235> [concrete]
|
|
// CHECK:STDOUT: %pattern_type.efe: type = pattern_type %Empty_where.type.9ab [concrete]
|
|
// CHECK:STDOUT: %complete_type.5db: <witness> = complete_type_witness %Empty.type.d26 [concrete]
|
|
// CHECK:STDOUT: %complete_type.157: <witness> = complete_type_witness %Empty_where.type.9ab [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: %U.patt: @H.%pattern_type (%pattern_type.382) = binding_pattern U [concrete]
|
|
// CHECK:STDOUT: %U.param_patt: @H.%pattern_type (%pattern_type.382) = value_param_pattern %U.patt, call_param0 [concrete]
|
|
// CHECK:STDOUT: %V.patt: %pattern_type.98f = symbolic_binding_pattern V, 1 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: %T.loc21_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc21_6.1 (constants.%T)]
|
|
// CHECK:STDOUT: %U.param: @H.%Empty_where.type (%Empty_where.type.b70) = value_param call_param0
|
|
// CHECK:STDOUT: %.loc21_28.1: type = splice_block %.loc21_28.2 [symbolic = %Empty_where.type (constants.%Empty_where.type.b70)] {
|
|
// CHECK:STDOUT: %Empty.ref: %Empty.type.d5a = name_ref Empty, file.%Empty.decl [concrete = constants.%Empty.generic]
|
|
// CHECK:STDOUT: %T.ref.loc21_25: type = name_ref T, %T.loc21_6.2 [symbolic = %T.loc21_6.1 (constants.%T)]
|
|
// CHECK:STDOUT: %Empty.type.loc21_26.2: type = facet_type <@Empty, @Empty(constants.%T)> [symbolic = %Empty.type.loc21_26.1 (constants.%Empty.type.752200.2)]
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: %.Self.ref: @H.%Empty.type.loc21_26.1 (%Empty.type.752200.2) = name_ref .Self, %.Self.4 [symbolic = %.Self.1 (constants.%.Self.ac8)]
|
|
// CHECK:STDOUT: %.loc21_34.1: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = specific_constant @A.%assoc0, @Empty(constants.%T) [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
|
|
// CHECK:STDOUT: %A.ref: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = name_ref A, %.loc21_34.1 [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
|
|
// CHECK:STDOUT: %.Self.as_type.loc21_34.2: type = facet_access_type %.Self.ref [symbolic = %.Self.as_type.loc21_34.1 (constants.%.Self.as_type.4e9)]
|
|
// CHECK:STDOUT: %.loc21_34.2: type = converted %.Self.ref, %.Self.as_type.loc21_34.2 [symbolic = %.Self.as_type.loc21_34.1 (constants.%.Self.as_type.4e9)]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_34.2: type = impl_witness_access constants.%Empty.lookup_impl_witness.e0b, element0 [symbolic = %impl.elem0.loc21_34.1 (constants.%impl.elem0.c5c)]
|
|
// CHECK:STDOUT: %T.ref.loc21_39: type = name_ref T, %T.loc21_6.2 [symbolic = %T.loc21_6.1 (constants.%T)]
|
|
// CHECK:STDOUT: %ptr.loc21_40.2: type = ptr_type %T.ref.loc21_39 [symbolic = %ptr.loc21_40.1 (constants.%ptr.79f)]
|
|
// CHECK:STDOUT: %.loc21_28.2: type = where_expr %.Self.4 [symbolic = %Empty_where.type (constants.%Empty_where.type.b70)] {
|
|
// CHECK:STDOUT: requirement_base_facet_type constants.%Empty.type.752200.2
|
|
// CHECK:STDOUT: requirement_rewrite %impl.elem0.loc21_34.2, %ptr.loc21_40.2
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %U: @H.%Empty_where.type (%Empty_where.type.b70) = bind_name U, %U.param
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: %V.loc21_43.2: type = bind_symbolic_name V, 1 [symbolic = %V.loc21_43.1 (constants.%V)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @H(%T.loc21_6.2: type, %V.loc21_43.2: type) {
|
|
// CHECK:STDOUT: %T.loc21_6.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc21_6.1 (constants.%T)]
|
|
// CHECK:STDOUT: %Empty.type.loc21_26.1: type = facet_type <@Empty, @Empty(%T.loc21_6.1)> [symbolic = %Empty.type.loc21_26.1 (constants.%Empty.type.752200.2)]
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: %require_complete.loc21_34: <witness> = require_complete_type %Empty.type.loc21_26.1 [symbolic = %require_complete.loc21_34 (constants.%require_complete.059)]
|
|
// CHECK:STDOUT: %Empty.assoc_type: type = assoc_entity_type @Empty, @Empty(%T.loc21_6.1) [symbolic = %Empty.assoc_type (constants.%Empty.assoc_type.3cf698.2)]
|
|
// CHECK:STDOUT: %assoc0: @H.%Empty.assoc_type (%Empty.assoc_type.3cf698.2) = assoc_entity element0, @Empty.%A [symbolic = %assoc0 (constants.%assoc0.3715ce.2)]
|
|
// CHECK:STDOUT: %.Self.as_type.loc21_34.1: type = facet_access_type %.Self.1 [symbolic = %.Self.as_type.loc21_34.1 (constants.%.Self.as_type.4e9)]
|
|
// CHECK:STDOUT: %Empty.lookup_impl_witness: <witness> = lookup_impl_witness %.Self.1, @Empty, @Empty(%T.loc21_6.1) [symbolic = %Empty.lookup_impl_witness (constants.%Empty.lookup_impl_witness.e0b)]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_34.1: type = impl_witness_access %Empty.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc21_34.1 (constants.%impl.elem0.c5c)]
|
|
// CHECK:STDOUT: %ptr.loc21_40.1: type = ptr_type %T.loc21_6.1 [symbolic = %ptr.loc21_40.1 (constants.%ptr.79f)]
|
|
// CHECK:STDOUT: %Empty_where.type: type = facet_type <@Empty, @Empty(%T.loc21_6.1) where %impl.elem0.loc21_34.1 = %ptr.loc21_40.1> [symbolic = %Empty_where.type (constants.%Empty_where.type.b70)]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %Empty_where.type [symbolic = %pattern_type (constants.%pattern_type.382)]
|
|
// CHECK:STDOUT: %V.loc21_43.1: type = bind_symbolic_name V, 1 [symbolic = %V.loc21_43.1 (constants.%V)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %require_complete.loc21_17: <witness> = require_complete_type %Empty_where.type [symbolic = %require_complete.loc21_17 (constants.%require_complete.63d)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn(%U.param: @H.%Empty_where.type (%Empty_where.type.b70)) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @H(constants.%T, constants.%V) {
|
|
// CHECK:STDOUT: %T.loc21_6.1 => constants.%T
|
|
// CHECK:STDOUT: %Empty.type.loc21_26.1 => constants.%Empty.type.752200.2
|
|
// CHECK:STDOUT: %.Self.1 => constants.%.Self.ac8
|
|
// CHECK:STDOUT: %require_complete.loc21_34 => constants.%require_complete.059
|
|
// CHECK:STDOUT: %Empty.assoc_type => constants.%Empty.assoc_type.3cf698.2
|
|
// CHECK:STDOUT: %assoc0 => constants.%assoc0.3715ce.2
|
|
// CHECK:STDOUT: %.Self.as_type.loc21_34.1 => constants.%.Self.as_type.4e9
|
|
// CHECK:STDOUT: %Empty.lookup_impl_witness => constants.%Empty.lookup_impl_witness.e0b
|
|
// CHECK:STDOUT: %impl.elem0.loc21_34.1 => constants.%impl.elem0.c5c
|
|
// CHECK:STDOUT: %ptr.loc21_40.1 => constants.%ptr.79f
|
|
// CHECK:STDOUT: %Empty_where.type => constants.%Empty_where.type.b70
|
|
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.382
|
|
// CHECK:STDOUT: %V.loc21_43.1 => constants.%V
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @H(constants.%i32, bool) {
|
|
// CHECK:STDOUT: %T.loc21_6.1 => constants.%i32
|
|
// CHECK:STDOUT: %Empty.type.loc21_26.1 => constants.%Empty.type.d26
|
|
// CHECK:STDOUT: %.Self.1 => constants.%.Self.aa8
|
|
// CHECK:STDOUT: %require_complete.loc21_34 => constants.%complete_type.5db
|
|
// CHECK:STDOUT: %Empty.assoc_type => constants.%Empty.assoc_type.7c7
|
|
// CHECK:STDOUT: %assoc0 => constants.%assoc0.758
|
|
// CHECK:STDOUT: %.Self.as_type.loc21_34.1 => constants.%.Self.as_type.05b
|
|
// CHECK:STDOUT: %Empty.lookup_impl_witness => constants.%Empty.lookup_impl_witness.4e5
|
|
// CHECK:STDOUT: %impl.elem0.loc21_34.1 => constants.%impl.elem0.36f
|
|
// CHECK:STDOUT: %ptr.loc21_40.1 => constants.%ptr.235
|
|
// CHECK:STDOUT: %Empty_where.type => constants.%Empty_where.type.9ab
|
|
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.efe
|
|
// CHECK:STDOUT: %V.loc21_43.1 => bool
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %require_complete.loc21_17 => constants.%complete_type.157
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|