mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
This does a few things: * Replaces the single `TypeId` in the `FacetTypeInfo` struct with a vector of `InterfaceId`, `SpecificId` pairs (sorted in id order) representing the set of interface requirements of the facet type. This will later be used to support facet types with multiple interface requirements (as in `I & J` or `I where .Self impls J`). * Replace `InterfaceType` instructions (used as the type of an `InterfaceDecl` instruction) with `FacetType` instructions (introduced in #4460) with a (newly introduced) `FacetTypeFromInterface()` function. * Replace code that consumed `InterfaceType` values with code that consumed `FaceType` values. I've generally left the assumption in the code that it is dealing with a single interface, using the (newly introduced) `FacetTypeInfo::TryAsSingleInterface`, and producing an error otherwise. There isn't yet support for the `&` operator or `where .Self impls`, so this is generally a good assumption for now, except you can get a facet type with no associated interfaces from a `type where`... expression. In some cases, the facet type value is pulled from the evaluation of an `InterfaceDecl` instruction, where the single interface assumption will hold permanently. * Some related cleans up: nicer stringification and formatting of facet types, suppression of some errors when there already was an error. There is still a lot left to do, including: * Type `type` should be a facet type with a reserved id, replacing the built-in instruction. * Code using `TryAsSingleInterface` should generally be upgraded to handle more than (or less than) one interface. Name lookup should be particularly exciting. * Operator `&` should be defined on facet types, unioning their interface and other requirements. * Requirements from a `where` clause don't do anything yet. * Impls and impl lookup need to resolve facet types, and do things like determine if all the associated constants are given values. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Geoff Romer <gromer@google.com>
61 lines
2.6 KiB
Plaintext
61 lines
2.6 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/impl/declaration.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/declaration.carbon
|
|
|
|
interface I {}
|
|
|
|
impl i32 as I;
|
|
|
|
// CHECK:STDOUT: --- declaration.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %I.type: type = facet_type <@I> [template]
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
|
|
// CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: .Int32 = %import_ref
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .I = %I.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {}
|
|
// CHECK:STDOUT: impl_decl @impl [template] {} {
|
|
// CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
|
|
// CHECK:STDOUT: %.loc13_6.1: type = value_of_initializer %int.make_type_32 [template = i32]
|
|
// CHECK:STDOUT: %.loc13_6.2: type = converted %int.make_type_32, %.loc13_6.1 [template = i32]
|
|
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I {
|
|
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: impl @impl: %.loc13_6.2 as %I.ref;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
|
|
// CHECK:STDOUT:
|