Skip to content

♻️ refactor(mq-check): extract get_non_keyword_children, add error helpers, improve type formatting#1399

Merged
harehare merged 3 commits intomainfrom
chore/mq-check-refactor
Mar 6, 2026
Merged

♻️ refactor(mq-check): extract get_non_keyword_children, add error helpers, improve type formatting#1399
harehare merged 3 commits intomainfrom
chore/mq-check-refactor

Conversation

@harehare
Copy link
Copy Markdown
Owner

@harehare harehare commented Mar 6, 2026

  • Move keyword filtering logic to get_non_keyword_children for reuse
  • Add InferenceContext::report_mismatch and report_no_matching_overload for error reporting
  • Add format_type_list for error message formatting
  • Refactor unify to use report_mismatch for cleaner error handling
  • Minor normalization and early exit improvements

…lpers, improve type formatting

- Move keyword filtering logic to get_non_keyword_children for reuse
- Add InferenceContext::report_mismatch and report_no_matching_overload for error reporting
- Add format_type_list for error message formatting
- Refactor unify to use report_mismatch for cleaner error handling
- Minor normalization and early exit improvements
Copilot AI review requested due to automatic review settings March 6, 2026 13:53
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

Refactors mq-check’s type inference/type-checking internals by extracting shared helper logic (non-keyword child extraction, error reporting helpers, and type list formatting) and applying small performance/clarity improvements while keeping behavior largely the same.

Changes:

  • Centralize mismatch / overload error construction via new InferenceContext helper methods and use them from unification.
  • Extract keyword-filtered child collection into get_non_keyword_children and reuse it in constraint generation and narrowing.
  • Minor optimizations: pre-allocate union normalization, early-return in apply_subst for empty substitutions, and early-exit overload selection on perfect matches.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/mq-check/src/unify.rs Uses InferenceContext::report_mismatch to reduce duplicated mismatch error construction.
crates/mq-check/src/types.rs Adds format_type_list and minor perf improvements to union normalization and substitution application.
crates/mq-check/src/narrowing.rs Switches to shared non-keyword child extraction helper for call argument analysis.
crates/mq-check/src/infer.rs Adds error reporting helpers and reuses shared type-list formatting; adds overload-resolution early exit.
crates/mq-check/src/constraint.rs Introduces get_non_keyword_children and refactors call-argument extraction to use it; minor import/path cleanups.

Comment on lines +575 to +581
pub fn format_type_list(types: &[Type]) -> String {
types
.iter()
.map(|t| t.display_renumbered())
.collect::<Vec<_>>()
.join(", ")
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

New helper format_type_list is user-visible via error message formatting but currently has no unit test coverage in types.rs's existing test module. Adding a small test for empty / single / multiple types would help prevent regressions in diagnostics formatting.

Copilot generated this review using guidance from repository custom instructions.
Copilot AI review requested due to automatic review settings March 6, 2026 14:03
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

crates/mq-check/src/infer.rs:407

  • The early-exit condition treats 100 * params.len() as a “perfect”/maximum overload score, but Type::match_score can exceed 100 for structural matches (e.g., arrays add +20; functions sum param+ret scores). This can cause resolve_overload to break before evaluating a later overload with a higher score, potentially selecting the wrong overload. Consider removing this early break, or computing a true upper bound for the current overload’s maximum possible score (e.g., summing param.match_score(param) for each param) before early exiting.
                        None => {
                            best_match = Some((overload.clone(), total_score));
                        }
                        Some((_, best_score)) if total_score > *best_score => {
                            best_match = Some((overload.clone(), total_score));
                        }
                        _ => {}
                    }
                }
            }
        }

        best_match.map(|(ty, _score)| self.instantiate_fresh(&ty))
    }

@harehare harehare merged commit 2c20e82 into main Mar 6, 2026
4 checks passed
@harehare harehare deleted the chore/mq-check-refactor branch March 6, 2026 14:35
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