mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:51:04 +01:00
Support calling constexpr functions at compile time (#6878)
Example:
```carbon
import Cpp inline '''
constexpr int f(int a, int b) { return a + b; }
''';
let a: array(i32, Cpp.f(1, 2)) = (1, 2, 3);
```
This commit is contained in:
@@ -1469,6 +1469,14 @@ static auto ImportFunction(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
}
|
||||
|
||||
SemIR::FunctionFields::EvaluationMode evaluation_mode =
|
||||
SemIR::FunctionFields::EvaluationMode::None;
|
||||
if (clang_decl->isConsteval()) {
|
||||
evaluation_mode = SemIR::FunctionFields::EvaluationMode::MustEval;
|
||||
} else if (clang_decl->isConstexpr()) {
|
||||
evaluation_mode = SemIR::FunctionFields::EvaluationMode::Eval;
|
||||
}
|
||||
|
||||
auto [decl_id, function_id] = MakeFunctionDecl(
|
||||
context, import_ir_inst_id, decl_block_id, /*build_generic=*/false,
|
||||
/*is_definition=*/false,
|
||||
@@ -1499,6 +1507,7 @@ static auto ImportFunction(Context& context, SemIR::LocId loc_id,
|
||||
.return_patterns_id = function_params_insts->return_patterns_id,
|
||||
.virtual_modifier = virtual_modifier,
|
||||
.virtual_index = virtual_index,
|
||||
.evaluation_mode = evaluation_mode,
|
||||
.self_param_id = FindSelfPattern(
|
||||
context, function_params_insts->implicit_param_patterns_id),
|
||||
}});
|
||||
|
||||
Reference in New Issue
Block a user