Commit 83ba1f3
committed
winmd-inspect: project WinRT generic interfaces through an associated ABI type
The generic-interface rendering projected each type-variable slot onto a
fixed-size raw pointer: the ABI protocol was NON-generic, a `VAR` slot erased
to the opaque interface pointer, and the wrapper `unsafeBitCast` the typed
value to (and the result back from) that pointer. That is size-correct only for
a REFERENCE instantiation (`IVector<IFoo>`, a pointer either way); for a VALUE
instantiation (`IReference<Int32>`, `IVector<Int32>`) the slot's `Element` is a
4-byte value, and a fixed-size bitcast to an 8-byte pointer TRAPS — reads
garbage past the value. Replace the raw-pointer erasure of a generic slot with
the windows-rs `Type::Abi` mechanism: an associated-ABI-type projection that is
size-correct for both kinds.
- A new bundled runtime-support source, `Resources/Support/ABIProjectable.swift`,
defines the projection protocol: `ABIProjectable` with an
`associatedtype ABI` and `toABI()`/`fromABI(_:)` conversions — the Swift
analogue of windows-rs's `Type` trait. A value type conforms with
`ABI == Self` (identity, the `CopyType`/`CloneType` case) and every
WinRT-blittable primitive is made to conform; a reference type conforms via
`ABIReference` with `ABI == UnsafeMutableRawPointer` (the opaque COM
pointer, the `InterfaceType` case). It is emitted alongside the projected
interfaces, not compiled into the tool.
- The generic wrapper is now `struct IVector<Element: ABIProjectable>` and the
ABI protocol is generic over the same parameters — `protocol
IVectorABI<Element>` with an `associatedtype Element: ABIProjectable` — its
requirements spelling each projected slot as `Element.ABI`. The wrapper
forwards through `Element.toABI()` / `Element.fromABI(_:)` rather than a
fixed-size `unsafeBitCast`, so a value instantiation crosses the vtable AS
the value (`Element.ABI == Element`) and a reference instantiation as the
opaque pointer — size-correct for both, exactly as windows-rs writes a
generic vtable slot as `AbiType<T>` rather than a fixed `*mut c_void`.
- `SignatureType.abi(…)` projects an UNBOUND type-level `VAR` through its
declared name's `.ABI` member (the new `projection` dialect string) instead
of collapsing it to the opaque pointer; a new `SignatureType.projects`
reports such a slot. A CONCRETE reference (a `CLASS` named type) and a
method-level `MVAR` still erase to the opaque pointer — a pointer either
way, so their cast is size-safe. The argument-dependent specialisation
(`substituting:`) is unchanged: a bound `VAR` resolves to its concrete
argument.
- `Database+SQL` gains `projects(return:)`/`projects(parameter:)` beside the
existing `reference(…)`; `Shell` composes the projected slot's ABI spelling
(`Element.ABI`) and the `toABI()`/`fromABI(_:)` forwarding into the render
context; the `com.mustache` `{{#generic}}` arm emits the parameterised ABI
protocol (with its `associatedtype` declarations) and the projecting
wrapper. A generic base is inherited parameterised by the interface's own
arguments (`IVectorABI<Element>: IIterableABI<Element>`). The non-generic
`{{^generic}}` path is byte-identical.
The projected shape is swiftc-typecheck- and run-verified end to end for BOTH a
VALUE instantiation (`IVector<Int32>`: the ABI slot IS `CInt`, the wrapper does
NO pointer bitcast, size-correct) and a REFERENCE instantiation
(`IVector<IFoo>`: the slot is the opaque pointer, projected through
`ABIReference`). The original PR219 concern-1 bug is fixed: no value slot
carries a size-unsafe `unsafeBitCast`.1 parent f160ca0 commit 83ba1f3
14 files changed
Lines changed: 1173 additions & 164 deletions
File tree
- Sources
- WinMDSynthesis
- WinMD
- winmd-inspect
- Resources
- Languages
- Queries
- Support
- Templates
- Tests
- WinMDSynthesisTests
- WinMDTests
- winmd-inspectTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
108 | 127 | | |
109 | 128 | | |
110 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
| |||
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| 70 | + | |
62 | 71 | | |
63 | 72 | | |
64 | 73 | | |
| |||
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| 80 | + | |
71 | 81 | | |
72 | 82 | | |
73 | 83 | | |
| |||
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
197 | | - | |
198 | | - | |
199 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
200 | 225 | | |
201 | 226 | | |
202 | 227 | | |
203 | | - | |
| 228 | + | |
| 229 | + | |
204 | 230 | | |
205 | 231 | | |
206 | 232 | | |
207 | 233 | | |
208 | 234 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 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 | + | |
213 | 278 | | |
214 | 279 | | |
215 | 280 | | |
216 | 281 | | |
217 | 282 | | |
218 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
219 | 286 | | |
220 | 287 | | |
221 | 288 | | |
| |||
256 | 323 | | |
257 | 324 | | |
258 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
259 | 336 | | |
| 337 | + | |
260 | 338 | | |
261 | 339 | | |
262 | 340 | | |
263 | 341 | | |
264 | | - | |
265 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
266 | 345 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
271 | 369 | | |
272 | 370 | | |
273 | 371 | | |
| |||
337 | 435 | | |
338 | 436 | | |
339 | 437 | | |
| 438 | + | |
340 | 439 | | |
341 | 440 | | |
342 | 441 | | |
| |||
353 | 452 | | |
354 | 453 | | |
355 | 454 | | |
356 | | - | |
357 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
358 | 458 | | |
359 | 459 | | |
360 | 460 | | |
| 461 | + | |
361 | 462 | | |
362 | 463 | | |
363 | 464 | | |
364 | | - | |
365 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
366 | 468 | | |
367 | 469 | | |
368 | 470 | | |
| |||
371 | 473 | | |
372 | 474 | | |
373 | 475 | | |
374 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
375 | 481 | | |
376 | | - | |
377 | | - | |
| 482 | + | |
| 483 | + | |
378 | 484 | | |
379 | 485 | | |
380 | 486 | | |
| |||
0 commit comments