mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Basic support for implementing and using a parameterized interface. (#4203)
The main change here is to form a specific when checking an interface function against an impl function, instead of just substituting the `Self` type.
This commit is contained in:
@@ -109,3 +109,5 @@ class C {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @F.1(constants.%Self) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @F.1(constants.%C) {}
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -83,8 +83,12 @@ fn G(T:! Generic(B)) {
|
||||
// CHECK:STDOUT: %.9: type = interface_type @WithAssocFn, @WithAssocFn(%C) [template]
|
||||
// CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
|
||||
// CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
|
||||
// CHECK:STDOUT: %.10: <witness> = interface_witness (%F.2) [template]
|
||||
// CHECK:STDOUT: %.11: type = ptr_type %.3 [template]
|
||||
// CHECK:STDOUT: %F.type.3: type = fn_type @F.1, @WithAssocFn(%C) [template]
|
||||
// CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
|
||||
// CHECK:STDOUT: %.10: type = assoc_entity_type %.9, %F.type.3 [template]
|
||||
// CHECK:STDOUT: %.11: %.10 = assoc_entity element0, @WithAssocFn.%F.decl [template]
|
||||
// CHECK:STDOUT: %.12: <witness> = interface_witness (%F.2) [template]
|
||||
// CHECK:STDOUT: %.13: type = ptr_type %.3 [template]
|
||||
// CHECK:STDOUT: %struct: %X = struct_value () [template]
|
||||
// CHECK:STDOUT: %N: %T.1 = bind_symbolic_name N 1 [symbolic]
|
||||
// CHECK:STDOUT: %WithImplicitArgs.type: type = generic_interface_type @WithImplicitArgs [template]
|
||||
@@ -204,7 +208,7 @@ fn G(T:! Generic(B)) {
|
||||
// CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
|
||||
// CHECK:STDOUT: %return.var: ref %X = var <return slot>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.10]
|
||||
// CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.12]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .F = %F.decl
|
||||
@@ -289,12 +293,26 @@ fn G(T:! Generic(B)) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @Simple(constants.%C) {
|
||||
// CHECK:STDOUT: %T => constants.%C
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.1 => constants.%.7
|
||||
// CHECK:STDOUT: %Self.2 => constants.%Self.1
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @WithAssocFn(constants.%C) {
|
||||
// CHECK:STDOUT: %T => constants.%C
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.1 => constants.%.9
|
||||
// CHECK:STDOUT: %Self.2 => constants.%Self.2
|
||||
// CHECK:STDOUT: %F.type => constants.%F.type.3
|
||||
// CHECK:STDOUT: %F => constants.%F.3
|
||||
// CHECK:STDOUT: %.2 => constants.%.10
|
||||
// CHECK:STDOUT: %.3 => constants.%.11
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @F.1(constants.%C, constants.%C) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @WithImplicitArgs(constants.%T.1, constants.%N) {
|
||||
// CHECK:STDOUT: %T => constants.%T.1
|
||||
// CHECK:STDOUT: %N => constants.%N
|
||||
|
||||
@@ -102,23 +102,25 @@ impl C as AddWith(C) {
|
||||
// CHECK:STDOUT: %.3: type = interface_type @AddWith, @AddWith(%T) [symbolic]
|
||||
// CHECK:STDOUT: %Self.1: @AddWith.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
|
||||
// CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
|
||||
// CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
|
||||
// CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
|
||||
// CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @AddWith(%T) [symbolic]
|
||||
// CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %F.type.2 [symbolic]
|
||||
// CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @AddWith(%T) [symbolic]
|
||||
// CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %F.type.1 [symbolic]
|
||||
// CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.5 [symbolic]
|
||||
// CHECK:STDOUT: %.6: type = interface_type @AddWith, @AddWith(%C) [template]
|
||||
// CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
|
||||
// CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
|
||||
// CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
|
||||
// CHECK:STDOUT: %F.type.3: type = fn_type @F.1, @AddWith(%C) [template]
|
||||
// CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
|
||||
// CHECK:STDOUT: %.7: <witness> = interface_witness (%F.3) [template]
|
||||
// CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %F.type.3 [template]
|
||||
// CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.5 [template]
|
||||
// CHECK:STDOUT: %.9: <witness> = interface_witness (%F.2) [template]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %import_ref.1: %AddWith.type = import_ref Main//a, inst+4, loaded [template = constants.%AddWith]
|
||||
// CHECK:STDOUT: %import_ref.2 = import_ref Main//a, inst+10, unloaded
|
||||
// CHECK:STDOUT: %import_ref.3 = import_ref Main//a, inst+16, unloaded
|
||||
// CHECK:STDOUT: %import_ref.4: @AddWith.%F.type (%F.type.2) = import_ref Main//a, inst+12, loaded [symbolic = @AddWith.%F (constants.%F.1)]
|
||||
// CHECK:STDOUT: %import_ref.4: @AddWith.%F.type (%F.type.1) = import_ref Main//a, inst+12, loaded [symbolic = @AddWith.%F (constants.%F.1)]
|
||||
// CHECK:STDOUT: %import_ref.5 = import_ref Main//a, inst+12, unloaded
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -145,9 +147,9 @@ impl C as AddWith(C) {
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.1: type = interface_type @AddWith, @AddWith(%T) [symbolic = %.1 (constants.%.3)]
|
||||
// CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F.1, @AddWith(%T) [symbolic = %F.type (constants.%F.type.2)]
|
||||
// CHECK:STDOUT: %F: @AddWith.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
|
||||
// CHECK:STDOUT: %.2: type = assoc_entity_type @AddWith.%.1 (%.3), @AddWith.%F.type (%F.type.2) [symbolic = %.2 (constants.%.4)]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F.1, @AddWith(%T) [symbolic = %F.type (constants.%F.type.1)]
|
||||
// CHECK:STDOUT: %F: @AddWith.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
|
||||
// CHECK:STDOUT: %.2: type = assoc_entity_type @AddWith.%.1 (%.3), @AddWith.%F.type (%F.type.1) [symbolic = %.2 (constants.%.4)]
|
||||
// CHECK:STDOUT: %.3: @AddWith.%.2 (%.4) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.3 (constants.%.5)]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: interface {
|
||||
@@ -159,8 +161,8 @@ impl C as AddWith(C) {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: impl @impl: %C as %.6 {
|
||||
// CHECK:STDOUT: %F.decl: %F.type.3 = fn_decl @F.2 [template = constants.%F.3] {}
|
||||
// CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.7]
|
||||
// CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {}
|
||||
// CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.9]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .F = %F.decl
|
||||
@@ -194,5 +196,15 @@ impl C as AddWith(C) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @AddWith(constants.%C) {
|
||||
// CHECK:STDOUT: %T => constants.%C
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.1 => constants.%.6
|
||||
// CHECK:STDOUT: %Self => constants.%Self.2
|
||||
// CHECK:STDOUT: %F.type => constants.%F.type.3
|
||||
// CHECK:STDOUT: %F => constants.%F.3
|
||||
// CHECK:STDOUT: %.2 => constants.%.7
|
||||
// CHECK:STDOUT: %.3 => constants.%.8
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @F.1(constants.%C, constants.%C) {}
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -57,6 +57,7 @@ impl X as C(X).GenericAndParams(X) {}
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, @C(%X) [template]
|
||||
// CHECK:STDOUT: %.11: type = ptr_type %.8 [template]
|
||||
// CHECK:STDOUT: %.12: type = interface_type @GenericAndParams.2, @GenericAndParams.2(%X) [template]
|
||||
// CHECK:STDOUT: %.13: type = interface_type @GenericAndParams.2, @GenericAndParams.2(%X, %U) [symbolic]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
@@ -266,6 +267,10 @@ impl X as C(X).GenericAndParams(X) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @GenericAndParams.1(constants.%X) {
|
||||
// CHECK:STDOUT: %T => constants.%X
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.1 => constants.%.10
|
||||
// CHECK:STDOUT: %Self.2 => constants.%Self.3
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @C(constants.%X) {
|
||||
@@ -276,5 +281,14 @@ impl X as C(X).GenericAndParams(X) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @GenericAndParams.2(constants.%X) {
|
||||
// CHECK:STDOUT: %U => constants.%U
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %T => constants.%X
|
||||
// CHECK:STDOUT: %.1 => constants.%.13
|
||||
// CHECK:STDOUT: %Self.2 => constants.%Self.5
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @GenericAndParams.2(constants.%X, constants.%U) {
|
||||
// CHECK:STDOUT: %U => constants.%U
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user