mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:41:08 +01:00
Support accessing associated functions by member access into facets (#4872)
For an expression such as `(Type as Interface).AssocFn()`, track the `Self` type `Type` in the result of the member access so that it's available when checking the function call. This introduces a new kind of type, `ImplFunctionType`, that represents the type of a function that is expected within an impl, modeled as the type of the function within the interface plus a value to use as `Self`. Calls to values of this type behave like calls to the underlying function except that the `Self` parameter is pre-bound to the self type from the facet. In order to support this, fix an issue where the imported list of generic bindings lost their association with their enclosing generic. This adds a little complexity to `import_ref`, including a new recursive cycle that I intend to address in a follow-up PR. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
dcfccd3187
commit
fcfb1345d5
+5
-4
@@ -603,8 +603,8 @@ fn NotEmptyStruct() {
|
||||
// CHECK:STDOUT: %Impls.type: type = fn_type @Impls [template]
|
||||
// CHECK:STDOUT: %Impls: %Impls.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %J_where.type: type = facet_type <@J where TODO> [template]
|
||||
// CHECK:STDOUT: %V: %J_where.type = bind_symbolic_name V, 0 [symbolic]
|
||||
// CHECK:STDOUT: %V.patt: %J_where.type = symbolic_binding_pattern V, 0 [symbolic]
|
||||
// CHECK:STDOUT: %V: %J_where.type = bind_symbolic_name V, 0 [symbolic]
|
||||
// CHECK:STDOUT: %.Self: %J.type = bind_symbolic_name .Self [symbolic]
|
||||
// CHECK:STDOUT: %Y: %J_where.type = bind_symbolic_name Y, 0 [symbolic]
|
||||
// CHECK:STDOUT: %Y.patt: %J_where.type = symbolic_binding_pattern Y, 0 [symbolic]
|
||||
@@ -625,7 +625,8 @@ fn NotEmptyStruct() {
|
||||
// CHECK:STDOUT: import Core//prelude
|
||||
// CHECK:STDOUT: import Core//prelude/...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Main.import_ref = import_ref Main//state_constraints, inst17 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.8fd = import_ref Main//state_constraints, inst17 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.81e: %J_where.type = import_ref Main//state_constraints, loc13_10, loaded [symbolic = @Impls.%V (constants.%V)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
@@ -671,7 +672,7 @@ fn NotEmptyStruct() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: interface @J [from "state_constraints.carbon"] {
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = imports.%Main.import_ref
|
||||
// CHECK:STDOUT: .Self = imports.%Main.import_ref.8fd
|
||||
// CHECK:STDOUT: witness = ()
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -696,7 +697,7 @@ fn NotEmptyStruct() {
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: generic fn @Impls(constants.%V: %J_where.type) [from "state_constraints.carbon"] {
|
||||
// CHECK:STDOUT: generic fn @Impls(imports.%Main.import_ref.81e: %J_where.type) [from "state_constraints.carbon"] {
|
||||
// CHECK:STDOUT: %V: %J_where.type = bind_symbolic_name V, 0 [symbolic = %V (constants.%V)]
|
||||
// CHECK:STDOUT: %V.patt: %J_where.type = symbolic_binding_pattern V, 0 [symbolic = %V.patt (constants.%V.patt)]
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -42,7 +42,7 @@ fn G(U: Empty(i32) where .A = i32*) {
|
||||
// CHECK:STDOUT: %assoc0.68f673.2: %Empty.assoc_type.54c14f.2 = assoc_entity element0, @Empty.%A [symbolic]
|
||||
// CHECK:STDOUT: %.Self.as_type.a75: type = facet_access_type %.Self.c95 [symbolic]
|
||||
// CHECK:STDOUT: %.Self.as_wit.da4: <witness> = facet_access_witness %.Self.c95 [symbolic]
|
||||
// CHECK:STDOUT: %Empty.facet.bea: %Empty.type.3e5fde.1 = facet_value %.Self.as_type.a75, %.Self.as_wit.da4 [symbolic]
|
||||
// CHECK:STDOUT: %Empty.facet.bea: %Empty.type.3e5fde.2 = facet_value %.Self.as_type.a75, %.Self.as_wit.da4 [symbolic]
|
||||
// CHECK:STDOUT: %impl.elem0.41c: type = impl_witness_access %.Self.as_wit.da4, element0 [symbolic]
|
||||
// CHECK:STDOUT: %ptr.79f: type = ptr_type %T [symbolic]
|
||||
// CHECK:STDOUT: %Empty_where.type.4ed: type = facet_type <@Empty, @Empty(%T) where %impl.elem0.41c = %ptr.79f> [symbolic]
|
||||
@@ -59,7 +59,7 @@ fn G(U: Empty(i32) where .A = i32*) {
|
||||
// CHECK:STDOUT: %assoc0.0c3: %Empty.assoc_type.a46 = assoc_entity element0, @Empty.%A [template]
|
||||
// CHECK:STDOUT: %.Self.as_type.920: type = facet_access_type %.Self.e6e [symbolic]
|
||||
// CHECK:STDOUT: %.Self.as_wit.581: <witness> = facet_access_witness %.Self.e6e [symbolic]
|
||||
// CHECK:STDOUT: %Empty.facet.a44: %Empty.type.3e5fde.1 = facet_value %.Self.as_type.920, %.Self.as_wit.581 [symbolic]
|
||||
// CHECK:STDOUT: %Empty.facet.933: %Empty.type.f0b = facet_value %.Self.as_type.920, %.Self.as_wit.581 [symbolic]
|
||||
// CHECK:STDOUT: %impl.elem0.797: type = impl_witness_access %.Self.as_wit.581, element0 [symbolic]
|
||||
// CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [template]
|
||||
// CHECK:STDOUT: %Empty_where.type.a58: type = facet_type <@Empty, @Empty(%i32) where %impl.elem0.797 = %ptr.235> [template]
|
||||
@@ -276,7 +276,7 @@ fn G(U: Empty(i32) where .A = i32*) {
|
||||
// CHECK:STDOUT: %assoc0 => constants.%assoc0.0c3
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @A(constants.%i32, constants.%Empty.facet.a44) {}
|
||||
// CHECK:STDOUT: specific @A(constants.%i32, constants.%Empty.facet.933) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @H(constants.%i32, bool) {
|
||||
// CHECK:STDOUT: %T.loc18_6.2 => constants.%i32
|
||||
|
||||
@@ -1185,8 +1185,8 @@ let K: (E where .F = .Self.G) = bool;
|
||||
// CHECK:STDOUT: %.Self.as_wit.cef: <witness> = facet_access_witness %.Self.9aa [symbolic]
|
||||
// CHECK:STDOUT: %impl.elem0.51b: type = impl_witness_access %.Self.as_wit.cef, element0 [symbolic]
|
||||
// CHECK:STDOUT: %N_where.type: type = facet_type <@N where %impl.elem0.51b = %empty_struct_type> [template]
|
||||
// CHECK:STDOUT: %T: %N_where.type = bind_symbolic_name T, 0 [symbolic]
|
||||
// CHECK:STDOUT: %T.patt: %N_where.type = symbolic_binding_pattern T, 0 [symbolic]
|
||||
// CHECK:STDOUT: %T: %N_where.type = bind_symbolic_name T, 0 [symbolic]
|
||||
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
|
||||
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %NestedRewrite.type: type = fn_type @NestedRewrite [template]
|
||||
@@ -1200,8 +1200,8 @@ let K: (E where .F = .Self.G) = bool;
|
||||
// CHECK:STDOUT: %.Self.as_wit.a35: <witness> = facet_access_witness %.Self.e46 [symbolic]
|
||||
// CHECK:STDOUT: %impl.elem1: type = impl_witness_access %.Self.as_wit.a35, element1 [symbolic]
|
||||
// CHECK:STDOUT: %A_where.type.791: type = facet_type <@A where %impl.elem1 = %empty_tuple.type and %impl.elem0.1d3 = bool> [template]
|
||||
// CHECK:STDOUT: %D: %A_where.type.791 = bind_symbolic_name D, 0 [symbolic]
|
||||
// CHECK:STDOUT: %D.patt: %A_where.type.791 = symbolic_binding_pattern D, 0 [symbolic]
|
||||
// CHECK:STDOUT: %D: %A_where.type.791 = bind_symbolic_name D, 0 [symbolic]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
|
||||
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
|
||||
// CHECK:STDOUT: }
|
||||
@@ -1221,11 +1221,13 @@ let K: (E where .F = .Self.G) = bool;
|
||||
// CHECK:STDOUT: %Main.import_ref.169 = import_ref Main//equal_constraint, inst17 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.020 = import_ref Main//equal_constraint, loc5_8, unloaded
|
||||
// CHECK:STDOUT: %Main.P = import_ref Main//equal_constraint, P, unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.bdf: %N_where.type = import_ref Main//equal_constraint, loc8_10, loaded [symbolic = @Equal.%T (constants.%T)]
|
||||
// CHECK:STDOUT: %Main.import_ref.b61 = import_ref Main//nested_rewrites, inst17 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.91a = import_ref Main//nested_rewrites, loc5_8, unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.55d = import_ref Main//nested_rewrites, loc6_8, unloaded
|
||||
// CHECK:STDOUT: %Main.B = import_ref Main//nested_rewrites, B, unloaded
|
||||
// CHECK:STDOUT: %Main.C = import_ref Main//nested_rewrites, C, unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.e0c: %A_where.type.791 = import_ref Main//nested_rewrites, loc9_18, loaded [symbolic = @NestedRewrite.%D (constants.%D)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
@@ -1269,14 +1271,14 @@ let K: (E where .F = .Self.G) = bool;
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: generic fn @Equal(constants.%T: %N_where.type) [from "equal_constraint.carbon"] {
|
||||
// CHECK:STDOUT: generic fn @Equal(imports.%Main.import_ref.bdf: %N_where.type) [from "equal_constraint.carbon"] {
|
||||
// CHECK:STDOUT: %T: %N_where.type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
|
||||
// CHECK:STDOUT: %T.patt: %N_where.type = symbolic_binding_pattern T, 0 [symbolic = %T.patt (constants.%T.patt)]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn(%T.param_patt: %N_where.type);
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: generic fn @NestedRewrite(constants.%D: %A_where.type.791) [from "nested_rewrites.carbon"] {
|
||||
// CHECK:STDOUT: generic fn @NestedRewrite(imports.%Main.import_ref.e0c: %A_where.type.791) [from "nested_rewrites.carbon"] {
|
||||
// CHECK:STDOUT: %D: %A_where.type.791 = bind_symbolic_name D, 0 [symbolic = %D (constants.%D)]
|
||||
// CHECK:STDOUT: %D.patt: %A_where.type.791 = symbolic_binding_pattern D, 0 [symbolic = %D.patt (constants.%D.patt)]
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user