Skip to content

Conversation

@GordonSmith
Copy link
Owner

No description provided.

@GordonSmith GordonSmith requested a review from Copilot October 15, 2025 16:04
Copy link
Contributor

Copilot AI left a 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_size is 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"

@GordonSmith GordonSmith force-pushed the NO_PY branch 5 times, most recently from 14bc06b to 0b9ebc6 Compare October 15, 2025 20:03
@codecov
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 81.48148% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.34%. Comparing base (3934d24) to head (0ea2029).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
include/cmcpp/string.hpp 68.75% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GordonSmith GordonSmith force-pushed the NO_PY branch 2 times, most recently from bcacfbb to 5c53a02 Compare October 16, 2025 10:58
@GordonSmith GordonSmith requested a review from Copilot October 16, 2025 10:58
Copy link
Contributor

Copilot AI left a 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.


uint32_t ret = align_to(last_alloc, alignment);
last_alloc = ret + new_size;
last_alloc = static_cast<uint32_t>(ret + new_size);
Copy link

Copilot AI Oct 16, 2025

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.

Copilot uses AI. Check for mistakes.
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
@GordonSmith GordonSmith merged commit 65aeb57 into main Oct 16, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant