Commit 480b0e3
committed
winmd-inspect: disambiguate colliding names with fabricated namespaces
Disambiguate the names two reached declarations would otherwise share, so every
signature spelling resolves to the declaration it names and the generated source
compiles. Builds on the nesting slice, adding the collision tally, the
fabricated namespace containers, and the frontier logic.
The projection is one flat top-level Swift scope, so a name is ambiguous when
two or more of the top-level declarations the closure emits bear it *of any
kind* — a second value type, an interface or delegate, or a runtime class.
Because only a value type can be wrapped, an ambiguous value type is spelled and
emitted fully namespace-qualified under fabricated namespace `enum` containers
(`A.Point`/`B.Point`), while the same-named `protocol` stays bare. Ambiguity is
counted over the *projected* (arity-stripped) name the emission carries and only
over the reached declarations, so an unreachable same-named type never forces a
wrap; the qualification keys off the value type's raw `namespace.name` identity
(so a same-named generic protocol does not borrow it) and confirms the reference
resolves locally (so an external same-named type spells bare). The decode
spelling, the emit nesting, and the collision tally derive from one source on
`Storage`, so they cannot drift.
The per-scope validation reconciles every declaration scope — the top-level
roots and each container's direct children — so members bear distinct labels: a
residual clash faults rather than emitting uncompilable output. Two same-named
top-level protocols fault `ambiguous`; a fabricated namespace container
shadowing an emitted type, or a generic interface/delegate's synthesized
`internal protocol <name>ABI` colliding with a co-emitted type, or a fabricated
container shadowing a signature-referenced frontier type the closure spells but
does not emit, faults `collision`. The `<name>ABI` occupant is counted only when
the *selected* template actually declares it — read off the rendered body, not
assumed from the metadata arity — so a `-I` template that omits the helper does
not fault a spurious collision against a real same-named type. A frontier — a
name the closure spells but
does not emit — is derived once from the emitted-set complement rather than
enumerated per reason: the walk records every spelled reference (a
signature-named type or an interface's named base) as its emitted top-level
spelling paired with the `TypeDef` `Id` it resolves to, and a reference is a
frontier exactly when that `Id` (its outermost encloser's, so a nested `A.Inner`
turns on its root `A`, not on `Inner`) is absent from the emitted set. One rule
then covers every way a name goes unemitted — a runtime class, a GUID-less
shape, a `known`-bridged or layout-rejected value type, a metadata-nested
protocol, a value type under a non-container, and an external reference
(including an
external base the `bases` view names though the local-only `requires` walk does
not). The one frontier set serves both seams: the fabricated-namespace shadow
check faults a fabricated `enum` whose name a frontier reference visible in its
scope bears, keyed per reference to its owner — a root segment is a top-level
`enum` visible as a bare name from any scope, so it shadows a frontier of its
name wherever owned; an inner segment (the `B` of `enum A.enum B` wrapping
`A.B.Point`) is visible only from within its own subtree, so it shadows only a
reference owned by a type whose fabricated enclosing path includes it, where a
bare `B` binds outward to the enclosing `A.B`, not the external type — and
the reached-only ambiguity tally treats it
as a distinct top-level bearer — a reached `A.Point` beside a frontier `B.Point`
(external, layout-rejected, `known`-bridged to the same target, or an inherited
base) wraps and qualifies to `A.Point` rather than spelling a bare `Point` that
captures the frontier's reference. Deriving from the complement, not a name
subtraction, keeps a top-level frontier `A` reserved even when an unrelated
nested `Foo.A` is emitted, and reading the `known` bridge name as the spelling
lets a value type of that target name contend. A post-walk reachability prune
keeps only the declarations reachable from the seeds through emittable nodes,
dropping the orphans a discarded frontier would otherwise leave behind, and the
emit renders each kept body once the reached-only qualification sets are fixed,
so a body is spelled with the same set that folds it into the tree.
Integration tests cover two same-named value types each wrapped in its namespace
`enum`, a value type colliding with a same-named protocol, arity and
same-namespace-arity collisions, a generic type's ABI name colliding with a
metadata type, a fabricated container shadowing an emitted type (at the root and
a level down) and a frontier type (top-level, nested — whose enclosing root it
shadows —, an external interface base, and an external base a fabricated
`enum A` must not un-frontier merely because an unrelated nested `Foo.A` is
emitted), a reached value type wrapping against a frontier of the same name (an
external
referent, a layout-rejected value type, an external base, and a `known` bridge
target each), an unreachable same-named type leaving a reached one bare, an
inner fabricated segment shadowing a bare frontier reference owned by a type in
its subtree (faulting where a root-only check would let uncompilable source
through), and a `-I` template that omits the ABI helper leaving its generic type
uncontended.
The collision fixtures assemble their metadata through `WinMDFixture`, an
in-target `#~` assembler that interns the string and blob heaps and computes the
table ranges, so a fixture declares its rows rather than hand-maintaining the
byte offsets every edit would otherwise re-derive.1 parent 403b049 commit 480b0e3
8 files changed
Lines changed: 3500 additions & 387 deletions
File tree
- Sources
- SQLEngineWinMD
- WinMDSynthesis
- WinMD
- winmd-inspect
- Tests/winmd-inspectTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
1058 | 1060 | | |
1059 | 1061 | | |
1060 | 1062 | | |
1061 | | - | |
| 1063 | + | |
| 1064 | + | |
1062 | 1065 | | |
1063 | 1066 | | |
1064 | 1067 | | |
1065 | 1068 | | |
1066 | 1069 | | |
1067 | | - | |
| 1070 | + | |
| 1071 | + | |
1068 | 1072 | | |
1069 | 1073 | | |
1070 | 1074 | | |
| |||
1087 | 1091 | | |
1088 | 1092 | | |
1089 | 1093 | | |
1090 | | - | |
| 1094 | + | |
| 1095 | + | |
1091 | 1096 | | |
1092 | 1097 | | |
1093 | 1098 | | |
| |||
1107 | 1112 | | |
1108 | 1113 | | |
1109 | 1114 | | |
1110 | | - | |
| 1115 | + | |
| 1116 | + | |
1111 | 1117 | | |
1112 | 1118 | | |
1113 | 1119 | | |
| |||
1126 | 1132 | | |
1127 | 1133 | | |
1128 | 1134 | | |
1129 | | - | |
| 1135 | + | |
| 1136 | + | |
1130 | 1137 | | |
1131 | 1138 | | |
1132 | 1139 | | |
1133 | 1140 | | |
1134 | 1141 | | |
1135 | | - | |
| 1142 | + | |
| 1143 | + | |
1136 | 1144 | | |
1137 | 1145 | | |
1138 | 1146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
381 | 511 | | |
382 | 512 | | |
383 | 513 | | |
| |||
390 | 520 | | |
391 | 521 | | |
392 | 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 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
393 | 652 | | |
394 | 653 | | |
395 | 654 | | |
| |||
0 commit comments