From 658ec99e8262120ea955ac25fa8799dcbcdf824d Mon Sep 17 00:00:00 2001 From: danakj Date: Mon, 23 Dec 2024 14:59:10 -0500 Subject: [PATCH 1/4] Explain BoundMethod and function_id a bit more --- toolchain/sem_ir/typed_insts.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 6746c70371a13..793e34dd5445f 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -384,8 +384,10 @@ struct BoolLiteral { BoolValue value; }; -// A bound method, that combines a function with the value to use for its -// `self` parameter, such as `object.MethodName`. +// A bound method, that combines a function with the value to use for its `self` +// parameter, such as `object.MethodName`. It is a callable thing like the +// `FunctionType` it refers to through the type of the `function_id` +// instruction, rather than a call to the method itself like `Call`. struct BoundMethod { static constexpr auto Kind = InstKind::BoundMethod.Define( {.ir_name = "bound_method", From 6775b2090b96fc3efa420319a60febaee7c8f8d4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 6 Jan 2025 14:20:28 -0500 Subject: [PATCH 2/4] Update toolchain/sem_ir/typed_insts.h Co-authored-by: Jon Ross-Perkins --- toolchain/sem_ir/typed_insts.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 793e34dd5445f..976f2a38f022d 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -384,10 +384,9 @@ struct BoolLiteral { BoolValue value; }; -// A bound method, that combines a function with the value to use for its `self` -// parameter, such as `object.MethodName`. It is a callable thing like the -// `FunctionType` it refers to through the type of the `function_id` -// instruction, rather than a call to the method itself like `Call`. +// For member access such as `object.MethodName`, combines a member function +// with the value to use for `self`. This is a callable structure; `Call` will +// handle the argument assignment. struct BoundMethod { static constexpr auto Kind = InstKind::BoundMethod.Define( {.ir_name = "bound_method", From d50ed05ca142acfdd8d65178da4a9917cc579d1c Mon Sep 17 00:00:00 2001 From: danakj Date: Mon, 6 Jan 2025 14:24:30 -0500 Subject: [PATCH 3/4] Add function_id comment --- toolchain/sem_ir/typed_insts.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 976f2a38f022d..317e1f2a42f46 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -397,6 +397,9 @@ struct BoundMethod { // `self`, or whose address will be used to initialize `self` for an `addr // self` parameter. InstId object_id; + // The instruction from which to find the function being bound to an object. + // The actual function (e.g. FunctionType) comes from the this instruction's + // type id. InstId function_id; }; From df2e9dfc6fcd9f8210f359f6e8e5f8bf97683c53 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 7 Jan 2025 15:13:56 -0500 Subject: [PATCH 4/4] Update toolchain/sem_ir/typed_insts.h Co-authored-by: Jon Ross-Perkins --- toolchain/sem_ir/typed_insts.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 317e1f2a42f46..bf0668ee2f4f4 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -397,9 +397,7 @@ struct BoundMethod { // `self`, or whose address will be used to initialize `self` for an `addr // self` parameter. InstId object_id; - // The instruction from which to find the function being bound to an object. - // The actual function (e.g. FunctionType) comes from the this instruction's - // type id. + // The function being bound, whose type_id is always a `FunctionType`. InstId function_id; };