Skip to content

✨ feat(mq-check): add constraint origin and contextual help to type errors#1452

Merged
harehare merged 3 commits intomainfrom
feat/improve-type-error-diagnostics-context
Mar 15, 2026
Merged

✨ feat(mq-check): add constraint origin and contextual help to type errors#1452
harehare merged 3 commits intomainfrom
feat/improve-type-error-diagnostics-context

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 15, 2026 09:31
… 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
@harehare harehare force-pushed the feat/improve-type-error-diagnostics-context branch from e116df8 to 968d409 Compare March 15, 2026 09:32
Copy link
Copy Markdown
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 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 ConstraintOrigin plumbing through constraint generation, unification, and error reporting to produce contextual help in type errors.
  • Refactor type-checker deferred resolution passes into a dedicated deferred module and split constraint generation into submodules.
  • Improve HIR symbol lookup/performance via name_index, symbols_for_source, and a stable insertion_order used 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).

@harehare harehare merged commit 5bb4b48 into main Mar 15, 2026
4 checks passed
@harehare harehare deleted the feat/improve-type-error-diagnostics-context branch March 15, 2026 11:59
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.

2 participants