Skip to content

lowering: native data class fields name their user types - #159

Merged
simontreanor merged 1 commit into
mainfrom
lowering/native-typed-fields
Sep 28, 2026
Merged

simontreanor merged 1 commit into
mainfrom
lowering/native-typed-fields

Conversation

@simontreanor

Copy link
Copy Markdown
Owner

Follow-up to #155/#158. In native output, a data class field declared as a non-generic user sum type or record now names it, as a string forward reference since the union alias comes after the classes:

class Add:
    _0: "Expr"
    _1: "Expr"
...
Expr = Num | Add | Mul | Neg

instead of Any. Generic types and anything else keep Any.

mypy 2.3.1 accepts all three benchmarks with the usual --allow-redefinition-new --local-partial-types. All single-file examples give identical output natively, and cargo test passes.

Measured (manual native-bench run 36367746170, CPython 3.12): expr_eval mypyc 1.37x of hand-written (was 1.40x in #155), collatz 0.08x, map_build 1.32x. The project build step also passed.

A field declared as a non-generic user sum type or record now names it in
native output, as a string since the union alias comes after the classes
(Add._0: "Expr"), instead of Any. mypy accepts it with the same flags, and
mypyc can keep the field typed rather than boxing every read.
@simontreanor
simontreanor merged commit 1627b85 into main Sep 28, 2026
21 checks passed
@simontreanor
simontreanor deleted the lowering/native-typed-fields branch September 28, 2026 01: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.

1 participant