Skip to content

Refacotr stage 1#32

Merged
k5602 merged 82 commits intomainfrom
refacotr_s1
Sep 6, 2025
Merged

Refacotr stage 1#32
k5602 merged 82 commits intomainfrom
refacotr_s1

Conversation

@k5602
Copy link
Contributor

@k5602 k5602 commented Sep 4, 2025

This pull request introduces a major restructuring of the project into a Rust workspace, extracting core components into dedicated crates and refactoring the build and CI pipeline. The changes lay the groundwork for modular development, improved maintainability, and enhanced CI validation. Key updates include the creation of a workspace in Cargo.toml, extraction of the CLI into its own crate, addition of new AST and attribute crates, and the introduction of a comprehensive CI workflow.

Workspace and Project Structure

  • Defined a Rust workspace in Cargo.toml, listing all core and app crates, and refactored dependencies to use internal crate paths for modularization.
  • Added apps/vec as an example CLI binary, with its own manifest and main entry point delegating to the extracted CLI library. [1] [2]

Crate Extraction and Facade Design

  • Created veil-ast crate as a facade for AST types, using include! to expose the root AST source and providing feature flags for alternate re-exporting. [1] [2]
  • Added veil-attr crate for attribute and metadata structures, with optional serde support for serialization.
  • Extracted CLI logic into veil-cli crate, including its own binary (ve) and modular dependencies on other workspace crates.
  • Implemented a benchmarking utility in veil-cli, allowing repeated compilation runs and reporting timing statistics.

Build and CI Improvements

  • Added a root build script (build.rs) to increase Windows stack size for the main binary, configurable via environment variable, and emitting appropriate linker arguments based on toolchain.
  • Introduced a comprehensive CI workflow in .github/workflows/ci.yml for formatting, linting, and grammar validation across the workspace.

AST Enhancements

  • Extended AST enums (UnOp, BinOp) with new operators (pre/post increment/decrement, integer division), and implemented corresponding Display traits for improved formatting. [1] [2] [3] [4]
  • Simplified the logic for merging impl blocks in the AST by removing redundant type checks.

Features and Dev Dependencies

  • Added feature flags to control legacy code inclusion and dev dependencies for diagnostics in the workspace manifest.

This restructuring sets the stage for further migration of compiler passes into dedicated crates, enables robust CI validation, and improves developer experience through modularization and clear separation of responsibilities.

k5602 and others added 30 commits September 1, 2025 16:07
Add minimal lexer, diagnostics, and syntax crates

Add CI workflow for rustfmt and clippy

Add architecture and baselines reference docs

Add baseline capture scripts for AST and C emission

Add --no-cc flag to CLI to skip C compilation

Update CLI to support --no-cc for build, run, and test commands
Switch lexer to use veil-syntax crate for tokenization. Add a full Pest grammar for raw
tokenization, a RawToken type, and a lex_raw function. Map raw tokens to parser tokens, normalizing
integer formats and handling keywords/types. Update diagnostics to remove std::io and use
codespan_reporting errors. Allow clippy warnings in CI.
- Introduce `crates/ast` as a facade crate for AST types - Update workspace members and dependencies
to include veil-ast - Move AST source to `crates/ast/src/ast.rs` and update imports - Refactor root
crate to use veil_ast for AST - Make CLI module public for workspace usage - Clean up syntax tests
for minimal file parsing
Add pest grammar file and validation script. Remove old hand-written parser and lexer. Update syntax
crate to use pest for parsing and tokenization. Integrate grammar validation in CI workflow. Update
tests for new parser behavior.
- Attach TypeIds to expressions, statements, and patterns for deterministic typed snapshots (for
golden testing and tooling) - Add division diagnostics with fix-its for '/' vs '//' and '/=' vs
'//=' - Warn on non-exhaustive matches for union/intersection types - Validate postfix '?' usage
against function return types - Validate trait references for dyn trait types and impl trait_ref
existence - Record types for assignment and let statement sides - Implement basic pattern-type
compatibility checking - Add tests for new diagnostics and typed snapshot features
- Add veil-mono and veil-normalize crates to workspace - Implement monomorphization pass for generic
functions, structs, and impls - Implement normalization pass for HIR (pipeline, postfix ops, '?') -
Integrate both passes into CLI build pipeline - Add CLI flag to dump normalized HIR - Update codegen
backend to expect monomorphized AST - Add tests for normalization and typeck diagnostics
- Introduce veil-ir crate: intermediate representation for post-monomorphized HIR - Add
veil-codegen-c crate: IR→C backend emitting translation units with deterministic order - Add
veil-runtime crate and portable C runtime (iterator hooks: iter_has_next, iter_next) - Integrate IR
lowering and codegen-c backend into CLI build flow - Link veil-runtime automatically when
VEIL_RUNTIME_LIB_DIR is set - Add golden IR test suite for lowering correctness - Update
normalization and scripts to edition 2024 - Minor fixes to mono and normalize crates for edition and
visibility - Add runtime documentation and C Makefile for building/installing the runtime
- Add pass_timings and cache_stats flags to CLI build commands - Implement build.rs in compiler
crate to export git, rustc, and build metadata - Use build fingerprint in PassManager cache keys for
IR build - Update process_build to support per-pass timings and cache stats output
- Removes `#[cfg(feature = "extended_ir_ops")]` from IR arithmetic/bitwise ops - Changes IR
pretty-print header from `fn` to `function` - Improves build cache key by including transitive
import digests - Emits pass stats as JSON for CI diffing - Fixes runtime crate lint and attributes
for unsafe functions - Updates project init to use inline templates
- Parser now emits warnings for legacy '/' in module paths and canonicalizes all imports/exports to
use '::' per spec. All import resolution and prelude injection logic updated to handle both forms,
but prefers 'std::prelude'. - Migration plan updated to reflect canonical module path policy and
cutover.
- Accept `str` as a primitive type alias for `string` - Parse and lower `//` as a distinct integer
division operator (IDiv) - Update grammar to support new comment syntax (`/# ...`) - Add tests for
MVL parsing, type checking, and CLI integration - Emit actionable diagnostics for misuse of '//'
with non-integer types - Add feature flags for legacy and new pipeline in Cargo.toml
- Move CLI main.rs to crates/cli/src/main.rs and update Cargo.toml - Accept both "::" and "/" in
import paths, canonicalize "/" to "::" - Update parser and grammar for new logical operators (&, |)
and deprecate &&, || - Emit deprecation warnings for && and || usage - Add tests for logical
operator parsing and precedence - Extend grammar for struct literals, enum variants, and patterns -
Remove legacy CLI and codegen sources - Update prelude for compatibility - Fix module path
resolution for tests
This commit eliminates the "extended_ir_ops" feature from veil-ir and veil_codegen_c, making all IR
operations always available. Removes conditional compilation, feature flags, and fallback code
paths. Also cleans up unused test module imports and updates documentation examples to use /# for
comments.
- Use is_empty() instead of len() > 0 for symbol table check - Simplify Levenshtein distance
initialization - Use slices instead of Vec for struct literal fields - Remove unused imports and
helper functions from syntax tests - Fix string interpolation syntax in panic function - Fix
formatting in array impl blocks - Comment out todo in random function to avoid syntax error
- Introduce HirGenericRef and HirTraitRef structs for improved type safety - Update HirType variants
to use these references - Adjust lowering and type checking logic to match new representations -
Improve intersection type exhaustiveness warning message - Expand std prelude with basic utility and
math functions - Minor cleanup in std math and process modules - Fix test to remove stray comment in
integer division example
Improve Windows clang arg selection to check for MinGW headers and
prefer MSVC if missing
- Support ++/-- as prefix and postfix unary operators in parser, AST, HIR, IR, and type checker -
Inject automatic import of std/prelude for all files except prelude itself - Update grammar to parse
INC/DEC tokens in prefix and postfix positions - Add tests for division diagnostics, increment
operators, and prelude injection
- Correctly handle empty return statements as void - Improve parsing of range expressions and
primary expressions - Fix lowering of integer division operator - Update comment syntax to use /#
for line comments - Update tests and examples for new syntax and behavior
meetzli and others added 9 commits September 5, 2025 17:57
- Filter out test functions as well as main when generating test programs, and always add a return
statement if missing. - Print generated test program content in verbose mode. - Parse parenthesized
expressions and for-patterns more robustly. - Support i64 integer literals and infer i32/i64 type
from value. - Allow range types in comparisons and type compatibility. - Make numeric type
compatibility bidirectional for literals. - Fix code fences and formatting in language spec.
- Update type compatibility to allow comparisons and operations between ranges, booleans, optionals,
and integer types - Adjust parser to accept assignment expressions in match subjects and arms -
Update stdlib .veil modules to minimal stubs for testing imports and visibility
- Add BinOp::Pipeline to AST and parser - Lower pipeline operator to HirExprKind::Pipeline - Update
IR lowering to handle pipeline expressions - Infer local variable types from initialization
expressions - Always allocate unique locals for '_' discard variables
…tializing locals, instead of

defaulting to i32. Added tests for pipeline expressions.
conversion assigning to 'int' from 'const char *' [-Wint-conversion]
Error: C compiler failed with status: exit status: 1
- Add InstIR::Format for printf-style string formatting in IR
- Lower template strings to Format IR with type-aware format specifiers
- Generate C code for Format using malloc + snprintf
- Improve type inference for function calls in IR lowering
- Update test_pipeline.veil to print pipeline results using template
  strings
@meetzli meetzli requested a review from Copilot September 6, 2025 01:59
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 pull request introduces a major restructuring of the project into a Rust workspace, extracting core components into dedicated crates and refactoring the build and CI pipeline. The changes establish a foundation for modular development, improved maintainability, and enhanced CI validation.

Key changes:

  • Created a Rust workspace structure with dedicated crates for different compiler passes
  • Extracted CLI functionality into a separate veil-cli crate
  • Added new crates for AST, HIR, resolution, normalization, monomorphization, and IR generation
  • Introduced comprehensive CI workflow for formatting, linting, and validation

Reviewed Changes

Copilot reviewed 56 out of 167 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/syntax/Cargo.toml Syntax crate configuration with Pest grammar support and AST adapter
crates/runtime/src/lib.rs Runtime shims for C ABI iterator hooks with safety documentation
crates/runtime/Cargo.toml Runtime crate configuration with C linkage features
crates/resolve/src/visibility.rs Visibility checking implementation for symbol access control
crates/resolve/src/symbol_table.rs Symbol table implementation for tracking definitions and scopes
crates/resolve/src/scope.rs Scope management for nested lexical scoping rules
crates/resolve/src/resolver.rs Main resolver orchestrating symbol table building and name resolution
crates/resolve/src/module_graph.rs Module graph implementation for import dependency tracking
crates/resolve/src/lib.rs Resolution crate public API and re-exports
crates/resolve/src/errors.rs Error types for name resolution and module system validation
crates/resolve/Cargo.toml Resolve crate configuration with dependency graph support
crates/normalize/src/lib.rs Normalization pass for desugaring HIR constructs
crates/normalize/Cargo.toml Normalize crate configuration for HIR transformation
crates/mono/src/lib.rs Monomorphization pass for generic instantiation
crates/mono/Cargo.toml Monomorphization crate configuration
crates/lexer/src/lib.rs Minimal lexer stub for workspace structure
crates/lexer/Cargo.toml Lexer crate configuration
crates/ir/src/lib.rs Intermediate representation with HIR lowering
crates/ir/Cargo.toml IR crate configuration with serialization support

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +1001 to +1004
let error = ResolveError::new(ResolveErrorKind::InvalidTypeParameterUsage {
param_name: "break".to_string(),
context: "outside of loop".to_string(),
});
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect error kind for break statement. Should use a dedicated error kind for control flow validation, not InvalidTypeParameterUsage.

Copilot uses AI. Check for mistakes.
Comment on lines +1015 to +1017
let error = ResolveError::new(ResolveErrorKind::InvalidTypeParameterUsage {
param_name: "continue".to_string(),
context: "outside of loop".to_string(),
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect error kind for continue statement. Should use a dedicated error kind for control flow validation, not InvalidTypeParameterUsage.

Suggested change
let error = ResolveError::new(ResolveErrorKind::InvalidTypeParameterUsage {
param_name: "continue".to_string(),
context: "outside of loop".to_string(),
let error = ResolveError::new(ResolveErrorKind::InvalidContinueUsage {
message: "continue statement used outside of loop".to_string(),

Copilot uses AI. Check for mistakes.
Comment on lines +1208 to +1210
let error = ResolveError::new(ResolveErrorKind::InvalidTypeParameterUsage {
param_name: "await".to_string(),
context: "outside of async context".to_string(),
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect error kind for await expression. Should use a dedicated error kind for async context validation, not InvalidTypeParameterUsage.

Suggested change
let error = ResolveError::new(ResolveErrorKind::InvalidTypeParameterUsage {
param_name: "await".to_string(),
context: "outside of async context".to_string(),
// TODO: Add `AwaitOutsideAsyncContext` to `ResolveErrorKind` in errors.rs
let error = ResolveError::new(ResolveErrorKind::AwaitOutsideAsyncContext {
// Add any relevant context here, e.g., span or node id if available

Copilot uses AI. Check for mistakes.
k5602 and others added 15 commits September 6, 2025 13:08
- All variable declarations now use const for compile-time constants and var for immutable or
mutable runtime variables. - Updated parser, AST, HIR, IR, and type checker to support new const/var
distinction and var mut for explicit mutability. - Grammar and tests updated to remove let and use
const/var consistently. - Language spec and documentation revised to match new variable declaration
rules.
- Only mutable variables (`var mut`) can be assigned to after initialization - Immutable variables
(`var`) and constants (`const`) are not assignable - Add mutability tracking to type checker context
- Add tests for mutability enforcement and valid cases
Allow unsized array annotation to match sized array types
Remove unused code and dead functions from ast

Update thiserror to 2.0.16 in typeck and workspace

Clarify and improve error messages in normalize tests

Remove placeholder package management functions from CLI

Fix type checking for range and numeric binary operators

Update logical operator tests to use modern syntax
…nt parsing in syntax crate to

handle const/var statements and expression statements correctly - Update pest grammar to make stmt
non-silent, improving const parsing - Clarify and simplify ast crate docs and tests - Update README
and test files for correct mutability and operator examples - Minor roadmap and test file tweaks for
consistency
…ture

- Resolve merge conflicts in helpers lib.rs
- Update CLI test functionality with latest improvements from main
- Fix function signatures and remove recursive parameter
- Conditional import of std::fs for Windows-only code
- All tests passing, ready for PR merge
- Remove assert!(true) from AST tests
- Add allow attributes for recursive function clippy warnings
- Fix collapsible match patterns in monomorphization
- Replace PathBuf with Path references per clippy suggestions
- Remove duplicate normalize calls and fix conditional logic
- Increase Windows stack size from 16MB to 64MB to handle test recursion
- All clippy warnings resolved, tests passing
- Remove unused std::fs import from helpers lib.rs
- Increase Windows stack size to 1GB (1024MB) to handle deep recursion in test suite
- This should resolve the Windows CI STATUS_STACK_OVERFLOW error
- All other platforms unaffected, tests pass on Linux
@k5602 k5602 added this pull request to the merge queue Sep 6, 2025
Merged via the queue into main with commit 9f7344e Sep 6, 2025
12 checks passed
@k5602 k5602 deleted the refacotr_s1 branch September 6, 2025 21:24
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.

3 participants