-
Notifications
You must be signed in to change notification settings - Fork 1
fix: ensure code generation compiles #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes compilation issues in the code generation pipeline by adding support for multi-file WIT packages, dependency resolution, resource methods, and external package type references. The changes ensure that generated C++ stubs compile successfully across the entire WIT test suite.
Key changes:
- Implemented package registry and dependency resolver for multi-file WIT package support
- Added tracking for resource methods and proper name prefixing to avoid type conflicts
- Introduced
empty_case<N>template to handle variants with multiple empty cases - Ported Python test utilities to C++ for cross-platform compatibility
Reviewed Changes
Copilot reviewed 48 out of 51 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/wit-codegen/wit_visitor.hpp | Added currentResource field to track resource context during parsing |
| tools/wit-codegen/wit_visitor.cpp | Enhanced resource parsing to track context and handle world-level types, fixed package version handling in use statements |
| tools/wit-codegen/wit_parser.hpp | Added external_dependencies and package_id fields to ParseResult |
| tools/wit-codegen/wit_parser.cpp | Implemented dependency collection from use statements and world imports/exports |
| tools/wit-codegen/wit-codegen.cpp | Added multi-file package support with dependency resolution and registry |
| tools/wit-codegen/utils.hpp | Added stdin/stdout/stderr to reserved keywords list |
| tools/wit-codegen/types.hpp | Added resource_name field to FunctionSignature |
| tools/wit-codegen/type_mapper.hpp | Added external type resolution support |
| tools/wit-codegen/type_mapper.cpp | Implemented qualify_identifier and resolveExternalType functions, enhanced type resolution for cross-package references |
| tools/wit-codegen/package_registry.hpp | New: Package registry for managing WIT packages |
| tools/wit-codegen/package_registry.cpp | Implementation of package registry functionality |
| tools/wit-codegen/dependency_resolver.hpp | New: Dependency resolver for WIT packages |
| tools/wit-codegen/dependency_resolver.cpp | Implementation of dependency resolution |
| tools/wit-codegen/code_generator.hpp | Added registry and dependency parameters to generation functions |
| tools/wit-codegen/code_generator.cpp | Enhanced code generation with external package support, function name conflict resolution, and guest wrapper generation |
| tools/wit-codegen/CMakeLists.txt | Added new source files to build |
| test/validate_stubs.cpp | C++ port of Python validation script |
| test/validate_all_wit_bindgen.cpp | C++ port of Python validation script for wit-bindgen suite |
| test/tmp_popen_test.cpp | Test utility for subprocess execution |
| test/summarize_stub_compilation.cpp | C++ port of Python summarization script |
| test/host-util.hpp | Fixed narrowing conversion warning |
| test/StubGenerationTests.cmake | Updated to use C++ test utilities, added parallel build support |
| test/README.md | Updated documentation for new test utilities |
| test/CompileStubsSummary.cmake | New: CMake script for stub compilation summary |
| test/CMakeLists.txt | Added MSVC warning suppressions for WebAssembly ABI |
| samples/wamr/main.cpp | Simplified context creation and used guest wrapper functions |
| samples/wamr/CMakeLists.txt | Added MSVC warning suppressions |
| include/wamr.hpp | Made create_lift_lower_context lookup cabi_realloc internally |
| include/cmcpp/variant.hpp | Added empty_case template to handle multiple empty variant cases |
Comments suppressed due to low confidence (1)
tools/wit-codegen/code_generator.cpp:1
- Potential arithmetic overflow: The expression
ret + new_sizeis evaluated before the cast, which could overflow if the sum exceeds the maximum value of the underlying type. Consider casting operands before addition to prevent overflow.
#include "code_generator.hpp"
14bc06b to
0b9ebc6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19 +/- ##
==========================================
+ Coverage 78.13% 84.34% +6.21%
==========================================
Files 21 22 +1
Lines 1537 1476 -61
Branches 131 129 -2
==========================================
+ Hits 1201 1245 +44
+ Misses 236 141 -95
+ Partials 100 90 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bcacfbb to
5c53a02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 51 out of 54 changed files in this pull request and generated 1 comment.
test/host-util.hpp
Outdated
|
|
||
| uint32_t ret = align_to(last_alloc, alignment); | ||
| last_alloc = ret + new_size; | ||
| last_alloc = static_cast<uint32_t>(ret + new_size); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding overflow check before casting. If ret + new_size exceeds UINT32_MAX, the cast will silently truncate, potentially causing incorrect memory allocation.
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
No description provided.