Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,47 @@ jobs:
$PSNativeCommandUseErrorActionPreference = $true
python eng\release\python\verify_python_release.py source

test-pod-vectors:
if: needs.changes.outputs.docs_only == 'false'
needs: [changes, format]
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-msvc
runner: windows-latest
host: X64
- target: i686-pc-windows-msvc
runner: windows-latest
host: X64
- target: aarch64-pc-windows-msvc
runner: windows-11-arm
host: Arm64
env:
POD_TEST_TARGET: ${{ matrix.target }}
POD_TEST_HOST: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Verify native POD test host
shell: pwsh
run: |
$hostArchitecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
if ($hostArchitecture -ne $env:POD_TEST_HOST) {
throw "POD tests require a native $env:POD_TEST_HOST host, found $hostArchitecture"
}
Write-Host "POD vectors: host=$hostArchitecture, target=$env:POD_TEST_TARGET"
- name: Execute optimized collection and callback regressions
shell: pwsh
run: |
$PSNativeCommandUseErrorActionPreference = $true
cargo test --locked --release -p dynwinrt --target $env:POD_TEST_TARGET --lib -- `
vector:: collection_element:: native_callback:: map::

# Rust test programs are independent builds, not reusable runtime packages.
test-rust:
if: needs.changes.outputs.docs_only == 'false'
Expand Down Expand Up @@ -645,16 +686,16 @@ jobs:
# Stable check identities also complete on intentional documentation-only skips.
test:
if: ${{ always() }}
needs: [changes, format, test-rust]
needs: [changes, format, test-rust, test-pod-vectors]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Require Rust validation
env:
NEEDS: ${{ toJSON(needs) }}
REQUIRED_JOBS: changes,format,test-rust
REQUIRED_JOBS: changes,format,test-rust,test-pod-vectors
DOCS_ONLY: ${{ needs.changes.outputs.docs_only }}
DOCS_SKIPPABLE_JOBS: test-rust
DOCS_SKIPPABLE_JOBS: test-rust,test-pod-vectors
run: |
.\eng\ci\assert-success.ps1 -NeedsJson $env:NEEDS -RequiredJobs ($env:REQUIRED_JOBS -split ',') `
-DocsOnly $env:DOCS_ONLY -SkippableJobs ($env:DOCS_SKIPPABLE_JOBS -split ',')
Expand Down Expand Up @@ -794,6 +835,7 @@ jobs:
changes,
format,
test-rust,
test-pod-vectors,
test,
build-codegen-x64,
build-bindings-x64,
Expand All @@ -811,9 +853,9 @@ jobs:
- name: Require every Build job
env:
NEEDS: ${{ toJSON(needs) }}
REQUIRED_JOBS: changes,format,test-rust,test,build-codegen-x64,build-bindings-x64,build-js-test-hooks,build-arm64,e2e-runtime,e2e-native,e2e,dynwinrt,dynwinrt-codegen
REQUIRED_JOBS: changes,format,test-rust,test-pod-vectors,test,build-codegen-x64,build-bindings-x64,build-js-test-hooks,build-arm64,e2e-runtime,e2e-native,e2e,dynwinrt,dynwinrt-codegen
DOCS_ONLY: ${{ needs.changes.outputs.docs_only }}
DOCS_SKIPPABLE_JOBS: test-rust,build-codegen-x64,build-bindings-x64,build-js-test-hooks,build-arm64,e2e-runtime,e2e-native
DOCS_SKIPPABLE_JOBS: test-rust,test-pod-vectors,build-codegen-x64,build-bindings-x64,build-js-test-hooks,build-arm64,e2e-runtime,e2e-native
run: |
.\eng\ci\assert-success.ps1 -NeedsJson $env:NEEDS -RequiredJobs ($env:REQUIRED_JOBS -split ',') `
-DocsOnly $env:DOCS_ONLY -SkippableJobs ($env:DOCS_SKIPPABLE_JOBS -split ',')
28 changes: 20 additions & 8 deletions bindings/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,31 @@ complete set of closed collection IIDs before creating a native object.
These limits apply to **producing** collections, including generated input
conversions, not to consuming collections returned by Windows.

**Phase one (#161), proposed for this release:** the following matrix describes
the proposed capability, subject to PR review, final integration, and platform
CI. POD vector support is independent of Classic COM/Win32 and does not expand
map admission.

| Element / key / value | x64 | ARM64 | i686 |
|---|---|---|---|
| Boolean, integers, Char16, enum, HRESULT | Supported | Supported | Up to 4 bytes; I64/U64 rejected |
| HSTRING; owned nullable interface/object references | Supported | Supported | Supported |
| POD structs in populated vectors or maps | Sizes 1, 2, 4, 8 | Up to 8 bytes, non-HFA only | Up to 4 bytes |
| Additional POD structs in **empty vectors only** | Larger than 8 bytes | Larger than 16 bytes, non-HFA only | None |
| Validated POD structs in empty or populated vectors | Supported | Supported, including HFAs | Supported |
| POD struct map keys/values (unchanged) | Sizes 1, 2, 4, 8 | Up to 8 bytes, non-HFA only | Up to 4 bytes |
| Top-level F32/F64/GUID; structs recursively containing HSTRING or references | Rejected, even empty | Rejected, even empty | Rejected, even empty |

POD means a validated, reference-free native layout. HFA means an aggregate of
one to four same-width floating-point values, including nested aggregates.
Thus `Point`/`Size` work on x64 but are rejected on ARM64 even when empty;
`PointInt32` works on x64 and ARM64. ARM64 also rejects empty `RectInt32`,
`Rect`, and `BasicGeoposition` vectors. `ManipulationDelta` (20 bytes, five floats,
non-HFA) supports empty
vectors on x64 and ARM64. Large map keys/values are rejected even for empty maps.
Examples include `Point`/`Size`, `PointInt32`, `RectInt32`, `Rect`,
`BasicGeoposition`, and nested PODs such as `ManipulationDelta` and
`ManipulationVelocities`; these are not a runtime whitelist. Empty vectors are
real, non-null, fully mutable collections. Large map keys/values and ARM64 HFA
map elements remain rejected even for empty maps.
Struct ABI entrypoints use cached libffi callbacks where the word fast path
does not apply. A process that prohibits executable callback allocation can
reject construction before publishing an object.
See the [POD vector architecture](../../docs/architecture/winrt-pod-vectors.md)
for layout, storage, callback lifetime, and remaining limitations.

Structs and typed enums require exact type identity, not a matching byte size
or shape. Scalars require the matching value variant, except U16 inputs for
Expand All @@ -408,7 +418,9 @@ the same checks. The metadata-free Rust `create_value_vector`, `create_vector`,
and `create_map` constructors require `unsafe`: callers must prove the native
ABI, ownership, element types, and complete IID set themselves.
The metadata-free `create_value_vector` retains packed-byte equality, including
padding, rather than metadata-directed field equality.
padding, rather than metadata-directed field equality. Its original restricted
word/empty-indirect ABI contract is unchanged; it does not gain checked POD
vector support.
Complete native struct collection support is tracked in
[microsoft/dynwinrt#161](https://github.com/microsoft/dynwinrt/issues/161).

Expand Down
31 changes: 20 additions & 11 deletions bindings/js/__test__/collection-struct-equality.e2e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,23 @@ test('checked Point map keys compare fields numerically', { skip: process.arch !
}
})

test('Point collection admission is unchanged on non-x64 targets', { skip: process.arch === 'x64' }, (t) => {
const keep = own(t)
const source = keep(point(0, 1))
const value = keep(DynWinRtValue.i32(7))
for (const items of [[], [source]]) {
assert.throws(() => DynWinRtValue.createVector(items, pointType))
assert.throws(() =>
DynWinRtValue.createMap(items, items.map(() => value), pointType, DynWinRtType.i32()),
)
}
})
test(
'Point vectors work without broadening map admission on non-x64 targets',
{ skip: process.arch === 'x64' },
(t) => {
const keep = own(t)
const source = keep(point(0, 1))
const value = keep(DynWinRtValue.i32(7))
for (const items of [[], [source]]) {
assert.equal(keep(DynWinRtValue.createVector(items, pointType)).isNull(), false)
assert.throws(() =>
DynWinRtValue.createMap(
items,
items.map(() => value),
pointType,
DynWinRtType.i32(),
),
)
}
},
)
40 changes: 20 additions & 20 deletions bindings/js/__test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1918,10 +1918,6 @@ test('create empty vectors for large struct element types', (t) => {
DynWinRtType.i32(),
DynWinRtType.i32(),
])
if (process.arch !== 'x64') {
t.throws(() => DynWinRtValue.createVector([], rectType))
return
}
const vector = DynWinRtValue.createVector([], rectType)
const vectorIid = DynWinRtType.parameterized(WinGuid.parse('913337e9-11a1-4345-a3a2-4e7f956e222d'), [rectType]).iid()

Expand Down Expand Up @@ -2128,7 +2124,7 @@ test('collection producers retain direct strings and nullable references with th
}
})

test('collection producers enforce the architecture-specific small POD boundary', (t) => {
test('POD vectors are complete while maps retain their architecture-specific boundary', (t) => {
const cases = [
{
name: 'CollectionBoundary.Byte',
Expand Down Expand Up @@ -2183,7 +2179,7 @@ test('collection producers enforce the architecture-specific small POD boundary'
const supported =
process.arch === 'x64' || (process.arch === 'arm64' && !entry.hfa) || (process.arch === 'ia32' && entry.size <= 4)
for (const producer of collectionProducerCases(type, [])) {
if (supported) {
if (producer.name === 'vector' || supported) {
t.false(producer.create().isNull())
} else {
t.throws(producer.create, undefined, entry.name)
Expand All @@ -2195,14 +2191,19 @@ test('collection producers enforce the architecture-specific small POD boundary'
t.is(entry.read(fromMap.asStruct()), entry.expected)
t.is(keyLookup.toNumber(), 0)
} else {
for (const producer of collectionProducerCases(type, [value.toValue()])) {
const vector = DynWinRtValue.createVector([value.toValue()], type)
const output = invokeCollectionReader(collectionVectorReader(type), vector, 6, [DynWinRtValue.u32(0)])
t.is(entry.read(output.asStruct()), entry.expected)
output.release()
vector.release()
for (const producer of collectionProducerCases(type, [value.toValue()]).slice(1)) {
t.throws(producer.create, undefined, entry.name)
}
}
}
})

test('collection producers restrict large POD to ABI-compatible empty vectors', (t) => {
test('collection producers support empty and nonempty large POD vectors but not maps', (t) => {
const cases = [
{
name: 'Windows.Graphics.RectInt32',
Expand Down Expand Up @@ -2236,19 +2237,18 @@ test('collection producers restrict large POD to ABI-compatible empty vectors',
]
for (const entry of cases) {
const type = DynWinRtType.structType(entry.name, entry.fields)
const emptySupported = process.arch === 'x64' || (process.arch === 'arm64' && entry.size > 16 && !entry.hfa)
if (emptySupported) {
const vector = DynWinRtValue.createVector([], type)
t.is(invokeCollectionReader(collectionVectorReader(type), vector, 7, []).toNumber(), 0)
for (const items of [[], [DynWinRtStruct.create(type).toValue()]]) {
const vector = DynWinRtValue.createVector(items, type)
t.is(invokeCollectionReader(collectionVectorReader(type), vector, 7, []).toNumber(), items.length)
if (items.length) {
const value = invokeCollectionReader(collectionVectorReader(type), vector, 6, [DynWinRtValue.u32(0)])
t.false(value.isNull())
value.release()
}
vector.release()
} else {
t.throws(() => DynWinRtValue.createVector([], type))
}
for (const producer of collectionProducerCases(type, []).slice(1)) {
t.throws(producer.create, undefined, producer.name)
}
for (const producer of collectionProducerCases(type, [DynWinRtStruct.create(type).toValue()])) {
t.throws(producer.create, undefined, producer.name)
for (const producer of collectionProducerCases(type, items).slice(1)) {
t.throws(producer.create, undefined, producer.name)
}
}
}
})
Expand Down
28 changes: 20 additions & 8 deletions bindings/py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,31 @@ complete set of closed collection IIDs before creating a native object.
These limits apply to **producing** collections, including conversion of Python
sequences/mappings, not to consuming collections returned by Windows.

**Phase one (#161), proposed for this release:** the following matrix describes
the proposed capability, subject to PR review, final integration, and platform
CI. POD vector support is independent of Classic COM/Win32 and does not expand
map admission.

| Element / key / value | x64 | ARM64 | i686 |
|---|---|---|---|
| Boolean, integers, Char16, enum, HRESULT | Supported | Supported | Up to 4 bytes; I64/U64 rejected |
| HSTRING; owned nullable interface/object references | Supported | Supported | Supported |
| POD structs in populated vectors or maps | Sizes 1, 2, 4, 8 | Up to 8 bytes, non-HFA only | Up to 4 bytes |
| Additional POD structs in **empty vectors only** | Larger than 8 bytes | Larger than 16 bytes, non-HFA only | None |
| Validated POD structs in empty or populated vectors | Supported | Supported, including HFAs | Supported |
| POD struct map keys/values (unchanged) | Sizes 1, 2, 4, 8 | Up to 8 bytes, non-HFA only | Up to 4 bytes |
| Top-level F32/F64/GUID; structs recursively containing HSTRING or references | Rejected, even empty | Rejected, even empty | Rejected, even empty |

POD means a validated, reference-free native layout. HFA means an aggregate of
one to four same-width floating-point values, including nested aggregates.
Thus `Point`/`Size` work on x64 but are rejected on ARM64 even when empty;
`PointInt32` works on x64 and ARM64. ARM64 also rejects empty `RectInt32`,
`Rect`, and `BasicGeoposition` vectors. `ManipulationDelta` (20 bytes, five floats,
non-HFA) supports empty
vectors on x64 and ARM64. Large map keys/values are rejected even for empty maps.
Examples include `Point`/`Size`, `PointInt32`, `RectInt32`, `Rect`,
`BasicGeoposition`, and nested PODs such as `ManipulationDelta` and
`ManipulationVelocities`; these are not a runtime whitelist. Empty vectors are
real, non-null, fully mutable collections. Large map keys/values and ARM64 HFA
map elements remain rejected even for empty maps.
Struct ABI entrypoints use cached libffi callbacks where the word fast path
does not apply. A process that prohibits executable callback allocation can
reject construction before publishing an object.
See the [POD vector architecture](../../docs/architecture/winrt-pod-vectors.md)
for layout, storage, callback lifetime, and remaining limitations.

Structs and typed enums require exact type identity, not a matching byte size
or shape. Scalars require the matching value variant, except U16 inputs for
Expand All @@ -159,7 +169,9 @@ the same checks. The metadata-free Rust `create_value_vector`, `create_vector`,
and `create_map` constructors require `unsafe`: callers must prove the native
ABI, ownership, element types, and complete IID set themselves.
The metadata-free `create_value_vector` retains packed-byte equality, including
padding, rather than metadata-directed field equality.
padding, rather than metadata-directed field equality. Its original restricted
word/empty-indirect ABI contract is unchanged; it does not gain checked POD
vector support.
Unsupported layouts raise
`RuntimeError`; HRESULT-backed type, range, or QueryInterface failures raise
`OSError`. Complete native struct collection support is tracked in
Expand Down
44 changes: 24 additions & 20 deletions bindings/py/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def test_collection_producers_retain_direct_strings_and_nullable_references_with
incompatible.release()


def test_collection_producers_enforce_architecture_specific_small_pod_boundary():
def test_pod_vectors_work_without_broadening_architecture_specific_map_boundary():
is_x86 = sys.maxsize == 2**31 - 1
is_arm64 = sysconfig.get_platform() == "win-arm64"
cases = [
Expand All @@ -921,8 +921,8 @@ def test_collection_producers_enforce_architecture_specific_small_pod_boundary()
value = DynWinRTStruct.create(typ)
getattr(value, setter)(index, expected)
supported = not ((is_x86 and size > 4) or (is_arm64 and hfa))
for create in _collection_producer_cases(typ, []):
if supported:
for producer_index, create in enumerate(_collection_producer_cases(typ, [])):
if producer_index == 0 or supported:
assert not create().is_null()
else:
with pytest.raises(RuntimeError):
Expand All @@ -935,14 +935,19 @@ def test_collection_producers_enforce_architecture_specific_small_pod_boundary()
assert getattr(from_map.as_struct(), getter)(index) == expected
assert key_lookup.to_number() == 0
else:
for create in _collection_producer_cases(typ, [value.to_value()]):
vector = DynWinRTValue.create_vector([value.to_value()], typ)
output = _invoke_collection_reader(
_collection_vector_reader(typ), vector, 6, [DynWinRTValue.from_u32(0)]
)
assert getattr(output.as_struct(), getter)(index) == expected
output.release()
vector.release()
for create in _collection_producer_cases(typ, [value.to_value()])[1:]:
with pytest.raises(RuntimeError):
create()


def test_collection_producers_restrict_large_pod_to_abi_compatible_empty_vectors():
is_x86 = sys.maxsize == 2**31 - 1
is_arm64 = sysconfig.get_platform() == "win-arm64"
def test_collection_producers_support_large_pod_vectors_but_not_maps():
cases = [
("Windows.Graphics.RectInt32", [DynWinRTType.i32_type()] * 4, False, 16),
("Windows.Foundation.Rect", [DynWinRTType.f32_type()] * 4, True, 16),
Expand All @@ -957,22 +962,21 @@ def test_collection_producers_restrict_large_pod_to_abi_compatible_empty_vectors
]
for name, fields, hfa, size in cases:
typ = DynWinRTType.struct_type(name, fields)
empty_supported = not is_x86 and (not is_arm64 or (size > 16 and not hfa))
if empty_supported:
vector = DynWinRTValue.create_vector([], typ)
for items in [[], [DynWinRTStruct.create(typ).to_value()]]:
vector = DynWinRTValue.create_vector(items, typ)
assert _invoke_collection_reader(
_collection_vector_reader(typ), vector, 7, []
).to_number() == 0
).to_number() == len(items)
if items:
output = _invoke_collection_reader(
_collection_vector_reader(typ), vector, 6, [DynWinRTValue.from_u32(0)]
)
assert not output.is_null()
output.release()
vector.release()
else:
with pytest.raises(RuntimeError):
DynWinRTValue.create_vector([], typ)
for create in _collection_producer_cases(typ, [])[1:]:
with pytest.raises(RuntimeError):
create()
for create in _collection_producer_cases(typ, [DynWinRTStruct.create(typ).to_value()]):
with pytest.raises(RuntimeError):
create()
for create in _collection_producer_cases(typ, items)[1:]:
with pytest.raises(RuntimeError):
create()


def test_collection_producers_reject_floating_scalars_and_guids_even_when_empty():
Expand Down
Loading
Loading