Date: Tue, 15 Jul 2025 05:23:55 +0000
>You need to describe more what you want and how it would work, somewhat. The
above is too vague a description.
>I suppose you want it to mutate the executable file, so some constants would be
written to it. How would that be accomplished?
The example: (same as before, assume ctfunc is a existing keyword)
constinit inline std::vector<std::function<void()>, _compile_time_allocator> update_list = { };
template<typename T>
struct base {
ctfunc base() { // when somewhere uses it, it will not be run immediately
if(!has_registered) {
update_list.push_back(&T::update);
has_registered = true;
}
// int* temp = new int[100]; // error: operator new won't generate constant expressions
}
static ctfunc int example_func(int i) {
return i;
}
private:
static constinit inline bool has_registered = false;
};
// constexpr int a_var = base<int>::example_func(); // error: ...::example_func() won't generate constant expressions
int another_var = base<int>::example_func(0); // OK
constinit int third_var = ...::example_func(0); // OK
constinit inline std::vector another_list = update_list; // OK, but the condition is std::vector has ctfunc std::vector(const std::vector&)
constexpr fourth_var = 9;
constinit fifth_var = base<int>::example_func(fourth_var); // OK
constinit base<int> the_instance = { };
The process:
compile code & run constexpr/consteval -> run ctfunc & generate the executable file -> the end of compiling
In this example:
init fourth_var
call base<int>::example_func(int) for third_var
call std::vector<...>::vector(std::vector) for another_list
call base<int>::example_func(int) for fifth_var
call std::vector<std::function<void()>, _compile_time_allocator>(init_list) for update_list
call base<int>::base() for the_instance;
>For example, how is this different from code that gets run at load-time, before
main()?
All code of the example above won't run on load-time, but before the final executable file be generated, then we can save time on loading.
>How does one find the necessary
information in the binary to update? Don't answer debug information, because a
production-release build may not include it.
No the "update binary" because all of it has been executed before the binary be generated, and not depend on any debug information.
________________________________
发件人: Std-Discussion <std-discussion-bounces_at_[hidden]> 代表 Thiago Macieira via Std-Discussion <std-discussion_at_[hidden]>
发送时间: 2025年7月15日 4:26
收件人: std-discussion_at_[hidden]cpp.org <std-discussion_at_[hidden]>
抄送: Thiago Macieira <thiago_at_[hidden]>
主题: Re: [std-discussion] 回复: 回复: 回复: Compile-time Variables and Stateful Meta-programming / STMP
On Monday, 14 July 2025 01:14:00 Pacific Daylight Time SD SH via Std-Discussion
wrote:
> There is a new idea: execute code after compiling, before running, called
> pre-execution. Then we have 3 stages to run code:
> compile-time -> pre-execution -> runtime
> Pre-execution can use the result of compile-time code, while compile-time
> code cannot use the former, and runtime code is similar.
> Follow this idea, it won't break the existing compile-time features, and we
> can slove the problem before, and it costs less time than the last.
>
> Actually some projects and languages did it, such as Unreal Header Tool and
> build.rs of Rust.
>
> Do you think it's feasible or not?
You need to describe more what you want and how it would work, somewhat. The
above is too vague a description.
For example, how is this different from code that gets run at load-time, before
main()?
I suppose you want it to mutate the executable file, so some constants would be
written to it. How would that be accomplished? How does one find the necessary
information in the binary to update? Don't answer debug information, because a
production-release build may not include it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Principal Engineer - Intel Platform & System Engineering
--
Std-Discussion mailing list
Std-Discussion_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
above is too vague a description.
>I suppose you want it to mutate the executable file, so some constants would be
written to it. How would that be accomplished?
The example: (same as before, assume ctfunc is a existing keyword)
constinit inline std::vector<std::function<void()>, _compile_time_allocator> update_list = { };
template<typename T>
struct base {
ctfunc base() { // when somewhere uses it, it will not be run immediately
if(!has_registered) {
update_list.push_back(&T::update);
has_registered = true;
}
// int* temp = new int[100]; // error: operator new won't generate constant expressions
}
static ctfunc int example_func(int i) {
return i;
}
private:
static constinit inline bool has_registered = false;
};
// constexpr int a_var = base<int>::example_func(); // error: ...::example_func() won't generate constant expressions
int another_var = base<int>::example_func(0); // OK
constinit int third_var = ...::example_func(0); // OK
constinit inline std::vector another_list = update_list; // OK, but the condition is std::vector has ctfunc std::vector(const std::vector&)
constexpr fourth_var = 9;
constinit fifth_var = base<int>::example_func(fourth_var); // OK
constinit base<int> the_instance = { };
The process:
compile code & run constexpr/consteval -> run ctfunc & generate the executable file -> the end of compiling
In this example:
init fourth_var
call base<int>::example_func(int) for third_var
call std::vector<...>::vector(std::vector) for another_list
call base<int>::example_func(int) for fifth_var
call std::vector<std::function<void()>, _compile_time_allocator>(init_list) for update_list
call base<int>::base() for the_instance;
>For example, how is this different from code that gets run at load-time, before
main()?
All code of the example above won't run on load-time, but before the final executable file be generated, then we can save time on loading.
>How does one find the necessary
information in the binary to update? Don't answer debug information, because a
production-release build may not include it.
No the "update binary" because all of it has been executed before the binary be generated, and not depend on any debug information.
________________________________
发件人: Std-Discussion <std-discussion-bounces_at_[hidden]> 代表 Thiago Macieira via Std-Discussion <std-discussion_at_[hidden]>
发送时间: 2025年7月15日 4:26
收件人: std-discussion_at_[hidden]cpp.org <std-discussion_at_[hidden]>
抄送: Thiago Macieira <thiago_at_[hidden]>
主题: Re: [std-discussion] 回复: 回复: 回复: Compile-time Variables and Stateful Meta-programming / STMP
On Monday, 14 July 2025 01:14:00 Pacific Daylight Time SD SH via Std-Discussion
wrote:
> There is a new idea: execute code after compiling, before running, called
> pre-execution. Then we have 3 stages to run code:
> compile-time -> pre-execution -> runtime
> Pre-execution can use the result of compile-time code, while compile-time
> code cannot use the former, and runtime code is similar.
> Follow this idea, it won't break the existing compile-time features, and we
> can slove the problem before, and it costs less time than the last.
>
> Actually some projects and languages did it, such as Unreal Header Tool and
> build.rs of Rust.
>
> Do you think it's feasible or not?
You need to describe more what you want and how it would work, somewhat. The
above is too vague a description.
For example, how is this different from code that gets run at load-time, before
main()?
I suppose you want it to mutate the executable file, so some constants would be
written to it. How would that be accomplished? How does one find the necessary
information in the binary to update? Don't answer debug information, because a
production-release build may not include it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Principal Engineer - Intel Platform & System Engineering
--
Std-Discussion mailing list
Std-Discussion_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
Received on 2025-07-15 05:24:04