← Back to Pull requests

types: Move where we reject UnionAlls that cross TypeEgal #63770

Open
Keno opened this pull request with 843 lines diff across 10 files
View on GitHub
Keno Keno commented on Oct 12, 2026 21:55 UTC
Author

The type system does not allow UnionAlls quantified over TypeEgal, e.g. TypeEgal{T} where T. I had originally implemented this by disallowing free typevars inside TypeEgal entirely, but we've since given those well-defined egality semantics. Disallowing free typevars there is a bit annoying, particularly after the UnionAll refactor, so instead move this restriction to the UnionAll constructor, which already does various validity checks. I think that's a better design.

Diff: 843 lines (+388 / -455) across 10 files Reviewer: vtjnash Review duration: 8339m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.56) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.56 · 843 lines diff across 10 files
0.56
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 4 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Real PR Conversation Timeline
7 items
vtjnash vtjnash commented on Oct 13, 2026 02:00 UTC
Contributor

This does sound much clearer semantics. Though I'm not sure an error is necessary -- if the object doesn't participate in TypeVar placeholders, it can just disallow walking through it and TypeEgal{T} where T simply returns TypeEgal{T} without the UnionAll binder remaining when it has nothing to bind.

Keno Keno commented on Oct 13, 2026 02:03 UTC
Author

No, I would like to stop doing that particular construction normalization in the first place, so it would be confusing. Not to mention that Tuple{TypeEgal{T}, Type{T}} where T would be very confusing.

vtjnash vtjnash commented on Oct 13, 2026 03:41 UTC
Reviewer

Right now that is probably supposed to print as something like Tuple{TypeEgal{T<:Any}, Type{T}} where T (or in the future perhaps Tuple{TypeEgal{TypeIndex(0)}, Type{T}} where T), since an unbound variable doesn't have a where clause to refer to. So I think that's mostly a defect in the printer, not necessary a reason to do or not keep it as an error after this PR.

Keno Keno commented on Oct 13, 2026 03:44 UTC
Author

Ok, but what's the reason to allow it?

vtjnash vtjnash commented on Oct 13, 2026 04:16 UTC
Reviewer

Just seemed like it might fall out of seemingly innocent code that just wants to unwrap_unionall / rewrap_unionall -- so every error that UnionAll throws (not specific to UnionAll, just that being the case here) is something that might end up having to be modeled in other places. E.g. it sounds awkward that rewrap_unionall(Tuple{TypeEgal{Vector.body}, S}, S) fails only if S == Vector

Keno Keno commented on Oct 13, 2026 04:45 UTC
Author

Yeah, I can see that argument, but I do really think that TypeEgal{T} where T ought to error. I think anything else is just very misleading, since it feels like the kind of thing that could maybe work (and who knows, maybe we want to make it work in the future). Let's revisit this after the UnionAll refactor, since the internal APIs will look different.

Reviewers
Assignees
Keno Keno
Labels
risk: low confidence: 89.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 56.2% (MEDIUM) · Higher = larger blast radius
56.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 89.8% · Lower = rushed or shallow review
89.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.7% · Safe to merge
5.7%