Add builtins for compound assignment operators. (#5335)

Provide builtins for compound assignments instead of defining them in
the prelude as a use of a binary operator and an assignment. This allows
us to lower compound assignment directly to LLVM operations instead of
producing a function call. In the short term this also allows us to
define a type-generic compound assignment in the prelude.
This commit is contained in:
Richard Smith
2025-04-21 20:38:11 +00:00
committed by GitHub
parent 2bdea71c25
commit b5ae988a08
39 changed files with 1373 additions and 312 deletions
+8 -8
View File
@@ -696,16 +696,16 @@ static auto IsValidBuiltinDeclaration(Context& context,
const SemIR::Function& function,
SemIR::BuiltinFunctionKind builtin_kind)
-> bool {
// Find the list of call parameters other than the implicit return slot.
auto call_params = context.inst_blocks().Get(function.call_params_id);
if (function.return_slot_pattern_id.has_value()) {
call_params = call_params.drop_back();
}
// Form the list of parameter types for the declaration.
llvm::SmallVector<SemIR::TypeId> param_type_ids;
auto implicit_param_patterns =
context.inst_blocks().GetOrEmpty(function.implicit_param_patterns_id);
auto param_patterns =
context.inst_blocks().GetOrEmpty(function.param_patterns_id);
param_type_ids.reserve(implicit_param_patterns.size() +
param_patterns.size());
for (auto param_id : llvm::concat<const SemIR::InstId>(
implicit_param_patterns, param_patterns)) {
param_type_ids.reserve(call_params.size());
for (auto param_id : call_params) {
// TODO: We also need to track whether the parameter is declared with
// `var`.
param_type_ids.push_back(context.insts().Get(param_id).type_id());