Conversation
… O(1) resolution
- Split hir.rs (2745 lines) into hir/lower.rs and hir/query.rs
- Extract simple_expr! macro to deduplicate 7 identical add_*_expr methods
- Merge symbol_insertion_order map into Symbol::insertion_order field
- Add name_index (FxHashMap<SmolStr, Vec<SymbolId>>) to HIR for O(1) name
resolution; replaces O(n) full-symbol scans in resolve_ref_symbol_of_scope
and resolve_ref_symbol_of_source
- Split lib.rs deferred resolution passes into deferred.rs module
- Split constraint.rs (2609 lines) into constraint/{categories,helpers,pipe}.rs
- Optimize small Union dedup to avoid HashSet allocation for ≤4 members
e116df8 to
968d409
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the type-checker’s diagnostics by attaching constraint origins and contextual “help” hints to type errors, while also improving HIR/query performance and stabilizing constraint-generation ordering.
Changes:
- Add
ConstraintOriginplumbing through constraint generation, unification, and error reporting to produce contextual help in type errors. - Refactor type-checker deferred resolution passes into a dedicated
deferredmodule and split constraint generation into submodules. - Improve HIR symbol lookup/performance via
name_index,symbols_for_source, and a stableinsertion_orderused to preserve source order across reloads.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/mq-hir/src/symbol.rs | Add insertion_order field to Symbol. |
| crates/mq-hir/src/resolve.rs | Use name_index for name-based symbol lookup to avoid O(n) scans. |
| crates/mq-hir/src/hir/query.rs | Add read-only HIR query helpers (symbols_for_source, unused_functions, etc.). |
| crates/mq-hir/src/hir/lower.rs | New CST→HIR lowering implementation; introduces/uses parent links and symbol insertion APIs. |
| crates/mq-check/src/constraint.rs | Introduce ConstraintOrigin, extend Constraint::Equal, and refactor into submodules; stabilize pass ordering via insertion order. |
| crates/mq-check/src/constraint/helpers.rs | New helper/index utilities for constraint generation (children index, piped args, pattern helpers, etc.). |
| crates/mq-check/src/constraint/pipe.rs | New pipe-chain constraint generation helpers for blocks/function bodies. |
| crates/mq-check/src/constraint/categories.rs | New symbol categorization for multi-pass constraint generation. |
| crates/mq-check/src/deferred.rs | Move deferred-resolution passes out of TypeChecker into a standalone module. |
| crates/mq-check/src/infer.rs | Add origin-aware mismatch reporting + overload “try:” help string formatting. |
| crates/mq-check/src/unify.rs | Thread ConstraintOrigin through unification and mismatch reporting. |
| crates/mq-check/src/lib.rs | Add optional context help field to several TypeError variants; wire deferred module. |
| crates/mq-check/src/types.rs | Optimize union normalization: O(n²) dedupe for tiny unions, HashSet for larger ones. |
| crates/mq-check/src/main.rs | Improve CLI type error rendering (numbered blocks, snippets, optional help lines). |
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.
No description provided.