Commit 7e34363
committed
winmd-inspect: nest metadata-nested value types into Swift nesting
Fold the flat closure emission into real Swift nesting, so a metadata-nested
value type emits as a nested type under its container chain and every signature
that names it resolves to that declaration. Disambiguating the names two reached
declarations would otherwise share is the next slice.
A metadata-nested value type emits as a real nested Swift type under its
enclosing-`TypeDef` container chain (`Outer.Inner`), and every signature that
names it spells the same dot-path, so the declaration and its uses agree and two
same-named nested types under different enclosers stay distinct. The walk emits
the enclosing value type too — even when only `Outer.Inner` is named and nothing
references `Outer` directly — so the container `Inner` nests inside actually
exists; a value type nests only when every enclosing level is an emitted
value-type container (`struct`/`enum`), else it is a dropped frontier the
consumer defines (an enclosing `protocol` cannot nest a value type, an excluded
runtime `class` is not emitted). An interface or delegate is a Swift `protocol`,
which cannot nest, so a metadata-nested one is a dropped frontier and only a
top-level one is a legal root. The flat emission folds into a containment forest
whose roots render in the walk's post-order, so a dependency precedes the type
naming it and a top-level type keeps its position.
A custom struct/enum template may open with a header comment and append a
brace-delimited footer around its main declaration; the child block is spliced
before the *main declaration's* closing brace, located off the syntax tree
(`Surface.inject`) — the primary `struct`/`enum` named for the container, its
member block's closing brace — so a `{` inside a comment or a string literal, a
leading helper before the declaration, and a trailing `extension` after it are
excluded by the grammar rather than a hand-tracked brace count. The child nests
inside the container, not above the declaration or into the footer.
A nested type's enclosing dot-path strips the CLR arity suffix from every
component, not only the leaf, and the strip lives at the single escape seam,
before each component is keyword-escaped, so a storage spelling and a
directly-resolved one escape identically and a generic instantiation's base
(`` `protocol`<…> ``) composes without a second strip that would cut the escape
backtick. But a *generic* encloser has no valid unqualified spelling — a member
of `Outer`1` is `Outer<T>.Inner`, needing the enclosing specialization the
projection does not yet emit, which the arity-stripped `Outer.Inner` misbinds
if the consumer supplies the generic `Outer` — so a reference into a type nested
under a generic encloser is dropped as an unsupported frontier rather than
spelled uncompilable, resolved (like a `TypeSpec` or a null index) to nothing.
An interface whose base is a metadata-nested interface names that base through
the same enclosing dot-path (`Outer.IChild`) its own nested declaration and a
signature naming it both wear, so the refinement resolves rather than reading
the bare `TypeName`, which binds no visible declaration. The selected base is
resolved to its local definition through the same `requires` scope-chain walk
the closure uses, so a base named directly through an `Interface_TypeDef` and
one named through an `Interface_TypeRef` — whose nested references the walk
follows to the local nested definition — alike carry the enclosing path; the
`.render *` batch resolves a `TypeRef` base by the same recursion. Each path
component is keyword-escaped separately. A top-level or external base resolves
to no enclosing path and spells bare, as does a base a `-I` override names that
matches no local definition.
Only a type's *primary* declaration nests. A custom template may frame a value
type with a file-scope `import` header or an `extension` footer, which Swift
permits only at file scope, so `nest` renders each node as a (header,
declaration, footer) triple: `partition` splits the header and footer off the
rendered body, only the declaration folds into the container, and the header and
footer bubble up — through every enclosing container — to the roots. A metadata-
nested child's `import`/`extension` therefore stays at file scope rather than
being indented into its parent's body, which would be invalid Swift.
A well-known spelling is keyed on a type's *own* raw identity, not the enclosing
dot-path the resolver qualifies a nested type to. A nested `Outer.Inner` mapped
`wellknown Inner InnerBridge` resolves on `("", "Inner")`, so the decode's
well-known lookup keys on the identity's leaf component — the raw name the walk
suppresses the declaration on — so the return spells the bridge `InnerBridge`
rather than the `Outer.Inner` the qualified identity would miss, leaving an
unresolved type whose declaration the walk already frontiered.
Integration tests cover two same-named nested value types each nested under its
encloser, an enclosing value type reached only through a nested member, a child
nested inside its container despite a header comment's braces, a trailing
footer, and a multiline string literal's braces, a reference into a type nested
under a generic encloser dropped as an unsupported frontier, a generic
instantiation whose
already-stripped keyword base keeps its escape, and a top-level interface whose
base is a nested interface — named through an `Interface_TypeDef`, and (resolved
by the scope-chain walk) through an `Interface_TypeRef` — spelled through its
enclosing path.
A `known` bridge resolves on the reference's *raw* identity, which the resolver
now preserves for exactly this lookup. `Storage.identifier` carries the leaf's
CLR arity suffix (`` Box`1 ``) while arity-stripping the enclosing path, so the
decode keys the well-known lookup on the raw leaf (backtick removed, `Box1`) and
a generic type spells its configured bridge (`BoxBridge<…>`) rather than the
projected `Box<…>` the shared `qualified` still produces for the base-label path.
And a nested reference under a `known`-bridged *encloser* spells through the
bridge — `wellknown Outer OuterBridge` makes `Outer.Inner` spell
`OuterBridge.Inner` — so a signature into a type whose encloser the closure
suppressed as imported resolves against the consumer's type, not an unemitted
`Outer`.
Only a nesting render qualifies a nested inheritance base. The closure emits a
nested interface's enclosing container, so `IRoot`'s clause names its base
through the enclosing path (`Outer.IChild`) that resolves against it. A flat
render (`.render`, `.render *`) emits every interface at the top level and nests
nothing, so the same base must spell its bare leaf (`IChild`) — the top-level
declaration the flat render emits it as — rather than an enclosing path with no
container to resolve against. A `Mode` flag the two render entry points set lets
`refine` tell the paths apart, so the flat inheritance stays consistent with the
flat declarations it names.
The closure's own frontier check normalizes a generic's name like the decode
does. The walk frontiers a reached dependency whose identity a `known` bridge
names; it now drops the arity backtick from the raw `TypeName` (`` Box`1 `` →
`Box1`) before the lookup, matching the decode's normalization, so a bridged
generic is suppressed here rather than emitted as a local `Box<T>` whose
declaration would redeclare the imported `BoxBridge<T>` the decode spells.1 parent 9b38385 commit 7e34363
8 files changed
Lines changed: 3403 additions & 207 deletions
File tree
- Sources
- WinMDSynthesis
- WinMD
- winmd-inspect
- Resources/Render
- Tests
- WinMDSynthesisTests
- winmd-inspectTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 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 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 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 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
227 | 556 | | |
0 commit comments