feat(compiler): Run frontend passes on library packages#29342
Open
mitchmindtree wants to merge 4 commits intomasterfrom
Open
feat(compiler): Run frontend passes on library packages#29342mitchmindtree wants to merge 4 commits intomasterfrom
mitchmindtree wants to merge 4 commits intomasterfrom
Conversation
The `test_network_retries_flag` COMMANDS script escaped hyphens in a grep pattern (`\-\-network-retries`). Newer grep versions emit "stray \ before -" warnings to stderr, causing the test to fail against its empty-stderr expectation. Switch to `grep -qF -- '--network-retries'` for a literal match.
Previously, each frontend pass's library branch was a no-op: library sources were parsed but not semantically validated, so type errors, name collisions, and interface cycles only surfaced once a downstream program consumed the library. Wire each of the nine frontend passes - NameValidation, GlobalVarsCollection, PathResolution, GlobalItemsCollection, CheckInterfaces, TypeChecking, Disambiguate, ProcessingAsync, and StaticAnalyzing - to invoke its real visitor or reconstructor on libraries. Replace the `ast.visit` / `ast.map` closure pairs with direct `match` expressions on the `Ast` enum so both branches can mutably borrow the visitor. Close gaps uncovered by enabling the passes: - `TypeChecking::visit_library` now visits interfaces, matching `visit_program_scope`. - Bespoke `visit_library` implementations in global_vars_collection, global_items_collection, check_interfaces, type_checking, and static_analysis now walk library stubs. Add `Library.stubs: IndexMap<Symbol, Stub>` paralleling `Program.stubs` so imported programs/libraries flow through the frontend passes. Update the parser constructor, `Display` impl, default `visit_library` / `reconstruct_library`, and every bespoke `reconstruct_library` / `consume_library` to thread the new field.
When a library package (`src/lib.leo`) is the primary compilation target, run the full frontend pipeline (name validation through static analysis) instead of parse-only. Non-primary library dependencies keep the existing parse-only path; their semantics are validated when their own package is built. - compiler: add `Compiler::build_library` (plus `*_from_directory` helpers) that parses, resolves import stubs, and runs `frontend_passes`. Extend `add_import_stubs` to populate `Library.stubs`: libraries have no explicit `imports` field, so deps are discovered via stubs whose parent set contains this library's name. - cli: route the primary library through `build_library_from_directory` when `package.compilation_units.last().name == unit.name`. The validated library is still turned into a `Stub::FromLibrary` so downstream tests in the same package can reference it. - tests: update `test_library` expectations to include the new "Building library" / "Validated" status lines.
Add CLI integration fixtures exercising the frontend passes that now run on library primaries: - test_library_build_type_error: `u32 + bool` rejected by type checking - test_library_build_undefined_name: unresolved `missing_fn()` call - test_library_build_interface_cycle: cyclic `interface A: B` / `B: A` - test_library_build_valid_interface: well-formed interface accepted - test_library_build_with_dep_lib: cross-library reference via stubs Add a compiler unit test asserting `build_library_from_directory` surfaces a type-checking error (`ETYC`) via the error handler. Fix an edge case where `parse_library` did not seed `Compiler::program_name`, which `add_import_stubs` relies on when identifying library deps by parent; the method now adopts the supplied `library_name` when no name was pre-set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Run all nine frontend passes (name validation through static analysis) on library packages when they are the primary compilation target. Previously, libraries were parse-only - type errors, undefined names, and interface cycles only surfaced when a downstream program consumed the library.
do_passto handleAst::Libraryvia its real visitor/reconstructor instead of a no-op.Library.stubs:IndexMap<Symbol, Stub>so imported programs/libraries flow through frontend passes; thread the field through all pass impls.Compiler::build_library/build_library_from_directory- parse, resolve import stubs, run frontend passes (no codegen).build_library; non-primary library deps remain parse-only.visit_interfacecall inTypeChecking::visit_library.Testing
Closes #29211
Follow-up