Conversation
373bfb3 to
69e0783
Compare
b45a8d1 to
a230a3d
Compare
550e0e9 to
1777d1d
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the initialization system within the compiler to move from explicit global initializer functions (__init__<name> and __user_init__<name>) to constructor-based initialization using LLVM's .init_array mechanism. The change consolidates init logic into a new plc_lowering::initializer module and introduces flags (--generate-external-constructors, --constructors-only) to control constructor generation for external libraries.
Changes:
- Replaced manual initializer generation with constructor functions (
<Type>__ctor) - Added linkage type
Includeto distinguish included files from external declarations - Removed legacy vtable and init globals from stdlib Rust implementations
- Updated test snapshots to reflect filtered alignment values and removed init modules
Reviewed changes
Copilot reviewed 122 out of 618 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
compiler/plc_lowering/src/initializer.rs |
New init lowering module implementing constructor generation |
compiler/plc_driver/src/pipelines/participant.rs |
Refactored InitParticipant to use new initializer |
compiler/plc_ast/src/ast.rs |
Added LinkageType::Include and helper methods |
compiler/plc_llvm/ |
New crate with C++ wrapper to set LLVM UseInitArray option |
libs/stdlib/src/timers.rs, libs/stdlib/src/flanks.rs, etc. |
Removed manual vtable/init globals |
libs/stdlib/tests/* |
Updated test helpers to use includes + compile_and_load |
compiler/plc_driver/src/cli.rs |
Added --generate-external-constructors and --constructors-only flags |
| Snapshot files | Updated for alignment filtering and removed __initializers modules |
Comments suppressed due to low confidence (1)
compiler/plc_lowering/src/initializer.rs:1
- The comment on line 4 in
compiler/plc_lowering/src/tests/initializer_tests.rscontains a typo: 'aligment' should be 'alignment'.
//! The initializer lowering module is responsible for additing initialization logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| use plc_source::SourceCode; | ||
|
|
||
| #[test] | ||
| fn var_input_with_initializer_parses_correctly() { |
There was a problem hiding this comment.
Corrected spelling of 'initialisers' to 'initializers' in the PR title for consistency with US English spelling used throughout the codebase.
move the initializer into the lowering crate change the initialization logic so that every pou or type has a _ctor
adjust the pipeline and the codegen to work with the new initializer logic. Fix some issue in the codegen/resolving logic
This PR refactors the initial value generation for PLC application
__ctorfunctions.__ctors) are created for every type and POU created in the current application{external}(used in the standard lib).Review notes:
The bulk of this change is in the
plc_loweringcrate under theinitializer.rsmodule.Changes to the codegen and resolver were needed to fix issues where an initialzer code was not working in the body of a function.
After the main feature was done, i went through all open issues that mentioned init and tried to add a testcase for the specific issue and fix it. i tagged the issues fixed in this PR.
I split the commits into the main code change, the additional changes required to the pipeline and other componets, the new tests, documentation changes, some formatting changes and the insta tests.
I kept the changes in the snapshot isolated to one commit for easier review.