Skip to content

Conversation

@LunaStev
Copy link
Member

This PR significantly upgrades the Wave compiler's ability to handle multi-file projects by implementing a recursive import expansion system. It also strengthens the LLVM backend with stricter type validation for functions and variables, ensuring that code generation is both robust and type-safe.

Key Changes

1. Recursive Import System

  • Dependency Resolution: Refactored local_import into local_import_unit, which now tracks absolute paths to perform deep dependency tree flattening via expand_imports_recursive.
  • Transitive Support: The compiler now correctly identifies and includes nested imports across multiple files, enabling modular project structures.
  • Standalone Mode Restrictions:
    • Disabled external crate imports (e.g., foo::bar) when running in standalone wavec mode.
    • Implemented graceful skipping for std::* imports to serve as placeholders for the upcoming standard library.

2. Enhanced LLVM Codegen & Type Safety

  • Strict Argument Validation: Added checks to ensure function call arguments exactly match the parameter types defined in the function signature.
  • Type-Safe Initializers: Variable initializers are now validated against their declared types to prevent implicit or unsafe casts during code generation.
  • Refined Conditional Logic:
    • Improved truthiness evaluation in if statements by explicitly comparing integers and floats against zero to produce valid LLVM i1 types.
    • Enhanced pointer null-checking logic.
    • Fixed Basic Block termination bugs that previously led to LLVM verification failures in complex branching scenarios.

3. Runner & Infrastructure

  • Multi-file Integration: Integrated the expansion logic into run_wave_file, allowing the runner to compile projects spanning multiple .wave files.
  • Configuration: Cleaned up repository metadata by removing the custom GitHub funding link.

Technical Details

  • Import Expansion: The expansion process uses a HashSet to prevent circular dependencies and redundant file processing.
  • Codegen Coercion: Instead of raw bit-casting, the backend now uses proper comparison instructions (icmp / fcmp) for conditional expressions to maintain IR integrity.

Introduce recursive import expansion for codegen and strengthen type
safety in LLVM IR generation.

Changes:
- Import System:
  - Refactor `local_import` to `local_import_unit`, returning both AST
    and absolute path for recursive resolution.
  - Implement `expand_imports_recursive` to flatten the dependency tree,
    ensuring nested imports are correctly included in the final AST.
  - Disable external imports (`foo::bar`) in standalone `wavec` mode.
  - Skip `std::*` imports gracefully (placeholders for future stdlib).
- LLVM Codegen:
  - Add strict type checking for function arguments in `FunctionCall`.
  - Validate return types against expected types.
  - Ensure variable initializers match declared types to prevent
    implicit unsafe casts.
  - Fix conditional branching logic in `if` statements:
    - Explicitly compare integers/floats against zero to produce `i1`.
    - Handle pointer null checks.
    - Correctly terminate basic blocks to avoid LLVM verification errors.
- Runner:
  - Integrate `expand_imports_for_codegen` into `run_wave_file`,
    enabling multi-file compilation support.
- Config:
  - Remove custom funding link.

This update enables modular project structures by supporting transitive
imports and improves compiler robustness with stricter type validation.

Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Dec 29, 2025
@LunaStev LunaStev merged commit c7b21d1 into wavefnd:master Dec 29, 2025
2 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