Infallible return values and more efficient out parameters #2248
Infallible return values and more efficient out parameters #2248
Conversation
|
@kennykerr we just noticed that
Any idea why this changed? |
|
I mentioned this in the PR description above. Testing this transformation revealed that it negatively affects certain methods that logically return very large structs, like DirectX matrixes, so I put a cap on the size of the structs that would be candidates for this transformation. Unfortunately, the metadata for return values is not very helpful at this point so I have to use a heuristic. The heuristic was just a little too generous before. windows-rs/crates/libs/metadata/src/reader/mod.rs Lines 1324 to 1349 in f5373bb |
|
Ack, |
|
@kennykerr in hindsight I'm not sure what kind of RVO or other optimizations Rust would perform here (also considering lack of If so, the only place this might be useful is when updating fields already in a struct, though I suspect most would be constructed by moving |
Now that we're starting to get more accurate optional parameter metadata thanks to microsoft/win32metadata#1005 we can more accurately represent infallible return values. These are functions and COM interface methods that have a
voidreturn type in metadata but also have a trailing out parameter that may be treated as a logical return value. For example,GetLocalTimegoes from:To this:
And
ID2D1DeviceContext's GetTarget method goes from:To this:
A
Resultis used to allow detection of null COM interface pointer values.I now also more carefully detect large structs and avoid transforming those to avoid large stack usage. For example,
IDCompositionDevice2'sGetFrameStatisticsmethod now returns theDCOMPOSITION_FRAME_STATISTICSvalue as an output parameter. Any structure larger than 128 bits (the size ofGUID) is passed by reference rather than by return value. This is especially useful for DirectX matrix structures.Fixes #2246