Commit d2db140
Ralph Küpper
fix(instanceof): #7575 — a monomorphized generic class is an instance of the generic
`m instanceof MyMap` was false for a `class MyMap<K, V> extends Map<K, V>`
instance while `m instanceof Map` was true. The issue read this as a Map/Set
subclass / prototype-chain defect. It is neither: the mechanism is
MONOMORPHIZATION, and Map/Set had nothing to do with it.
Perry specializes generic classes. `class Gen<T> {}` plus `new Gen<number>()`
emits a SECOND class named `Gen$num` (monomorph::mangle::generate_specialized_name)
with its own class id, and the instance is stamped with that id — while
`x instanceof Gen` resolves the RHS to the GENERIC's id, which appears nowhere
in the specialization's parent chain. The bisect that pins it:
class Gen<T> extends Base {} new Gen<number>() -> instanceof Gen false
class Gen<T> extends Base {} new Gen() -> instanceof Gen true
class Conc extends Base {} new Conc() -> instanceof Conc true
class GenNoExtends<T> {} new G<number>() -> instanceof G false
The last row has no base class at all, so this was never about `super()`-to-a-
native-base wiring. `class MyMap<K, V> extends Map<K, V>` is simply the
idiomatic spelling, which is why it surfaced there.
HIR now records `Class::specialized_from`; codegen emits one
`js_register_class_generic_origin(spec, generic)` per specialization next to the
parent edges; and `instanceof`'s chain walk (now one shared, depth-bounded
`class_chain_reaches`, used by both the static and the dynamic-RHS path) follows
that edge as well as `extends`.
It is deliberately a SEPARATE edge, not a CLASS_REGISTRY parent edge: that chain
also resolves `super()` construction, static-method lookup and vtable dispatch,
so splicing the generic in between a specialization and its real base would
re-run the wrong constructor.
The Array-side sibling #7603 left unfixed is covered by the same mechanism —
`new GenArr<number>() instanceof GenArr` now holds. `constructor.name` still
reports the mangled `Gen$num`; that is the same root cause on a different
surface and is filed separately rather than folded in here.
Validated locally: new gap test byte-identical to node 26.5.1 and byte-identical
again under PERRY_GC_ZEAL=1 + PERRY_GC_PROTECT_FROMSPACE=1; 4 new runtime unit
tests over the walk (including that the edge stays directional and does not make
sibling specializations match); test_gap_6325 and test_gap_7570 tightened to
assert the subclass edge the issue asked for.1 parent bce1045 commit d2db140
19 files changed
Lines changed: 406 additions & 38 deletions
File tree
- crates
- perry-codegen/src
- codegen
- runtime_decls
- stmt
- perry-hir/src
- analysis
- ir
- lower_decl
- lower
- module_decl
- monomorph
- stable_hash
- perry-runtime/src/object
- test-files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
482 | 486 | | |
483 | 487 | | |
484 | 488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
515 | 515 | | |
516 | 516 | | |
517 | 517 | | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
518 | 550 | | |
519 | 551 | | |
520 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1275 | 1275 | | |
1276 | 1276 | | |
1277 | 1277 | | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1278 | 1283 | | |
1279 | 1284 | | |
1280 | 1285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| |||
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| 626 | + | |
626 | 627 | | |
627 | 628 | | |
628 | 629 | | |
| |||
696 | 697 | | |
697 | 698 | | |
698 | 699 | | |
| 700 | + | |
699 | 701 | | |
700 | 702 | | |
701 | 703 | | |
| |||
721 | 723 | | |
722 | 724 | | |
723 | 725 | | |
| 726 | + | |
724 | 727 | | |
725 | 728 | | |
726 | 729 | | |
| |||
1665 | 1668 | | |
1666 | 1669 | | |
1667 | 1670 | | |
| 1671 | + | |
1668 | 1672 | | |
1669 | 1673 | | |
1670 | 1674 | | |
| |||
1690 | 1694 | | |
1691 | 1695 | | |
1692 | 1696 | | |
| 1697 | + | |
1693 | 1698 | | |
1694 | 1699 | | |
1695 | 1700 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
271 | 284 | | |
272 | 285 | | |
273 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
| 1104 | + | |
1104 | 1105 | | |
1105 | 1106 | | |
1106 | 1107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
| 413 | + | |
412 | 414 | | |
413 | 415 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1304 | 1304 | | |
1305 | 1305 | | |
1306 | 1306 | | |
| 1307 | + | |
1307 | 1308 | | |
1308 | 1309 | | |
1309 | 1310 | | |
| |||
1911 | 1912 | | |
1912 | 1913 | | |
1913 | 1914 | | |
| 1915 | + | |
1914 | 1916 | | |
1915 | 1917 | | |
0 commit comments