Skip to content

Document shift-left Win32 metadata annotation proposal - #2295

Draft
Jevan Saks (jevansaks) wants to merge 2 commits into
microsoft:mainfrom
jevansaks:user/jevansa/shift-left-annotation-spec
Draft

Document shift-left Win32 metadata annotation proposal#2295
Jevan Saks (jevansaks) wants to merge 2 commits into
microsoft:mainfrom
jevansaks:user/jevansa/shift-left-annotation-spec

Conversation

@jevansaks

Copy link
Copy Markdown
Member

Summary

  • add the reviewed shift-left Win32 metadata annotation specification
  • add the HTML gap-review presentation used for the team walkthrough
  • document windows-rs fidelity issues that require tooling changes rather than SDK header changes
  • document the confirmed header families omitted by the original monolithic windows-rs scrape

Key decisions captured

  • use SAL-style casing with an owned _Win32_ prefix, such as _Win32_Retval_ and _Win32_Retained_
  • place return-oriented annotations before the complete function declaration
  • reuse existing SAL and MIDL semantics where available
  • remove ProjectAs from the proposed vocabulary and consolidate exact-result behavior under _Win32_Preserve_result_
  • retain raw HANDLE declarations and put lifecycle metadata only on producer returns and output parameters

This PR is documentation-only and is intended as the review package for the SDK and windows-rs design discussion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 78d1f91d-a6a2-4264-b049-36c8d156ac9d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 78d1f91d-a6a2-4264-b049-36c8d156ac9d

@jonwis Jon Wiswall (jonwis) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, a few comments/nits. Looking forward to the update!

`_Outptr_result_maybenull_` use lowercase word segments. The Win32 additions
intentionally use PascalCase rather than copying that historical inconsistency.

`_Out_retval_` is not an SDK SAL macro and must not be described as one. For

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like bot-chatter; what's it trying to tell me?

_In_ DWORD count);
```

Do not place custom return annotations after the closing parenthesis. The earlier

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have the bot run through all these and remove the "previously" or "this has changed since" kind of stuff. Tell it to only state the current net state goal, rather than the path taken. (I have an explicit note of that in my "writing as me" docs... don't include the path taken unless it's requested or necessary to explain a surprising change.)


```cpp
struct
DESCRIPTION {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a sample attribute. Also, maybe see if clang-format supports formatting code-in-markdown-blocks?

public metadata name while references continue to use the native typedef.

```cpp
typedef BOOL (WINAPI *PUBLIC_CALLBACK)(DWORD value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

| P/Invoke module override | `_Win32_ImportLibrary_("name.dll")` | Function. Overrides import-library scan results. |
| `SupportedOSPlatform("windows...")` | One fixed `_Windows_SupportedOS_*_` macro from the menu below | Function, method, record, enum, or typedef. The macro expands to the canonical version string so authors cannot mistype it. |
| preserve exact return/result | `_Win32_PreserveResult_` | Function or method. Replaces both `CanReturnErrorsAsSuccess` and `CanReturnMultipleSuccessValues`; COM metadata uses standard `MethodImplAttributes.PreserveSig`. |
| `Agile` | `_Win32_Agile_` | Class/struct/interface declaration. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; agile usually goes on the class instead of the interface.

| `RAIIFree("CloseX")` | `_Win32_RAIIFree_(CloseX)` | Producer function/method return or output parameter only. |
| `InvalidHandleValue(value)` | `_Win32_InvalidHandle_(value)` | Producer function/method return or output parameter only. Repeatable; signed decimal and hexadecimal C literals are accepted. |
| `NullNullTerminated` | Existing SAL `_NullNull_terminated_` | Return, parameter, field, or typedef. No custom annotation is required. |
| `Retained` | `_Win32_Retained_` | Parameter. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More description? We had talked about a " is the end of the retained lifetime" annotation.

| `RetVal` | MIDL `[retval]` or existing direction SAL plus `_Win32_Retval_` | Parameter. windows-rs parses `[retval]` from MIDL-generated header comments; C/C++-only declarations use the custom annotation. |
| `ComOutPtr` | `_COM_Outptr_` and standard SAL variants | Parameter. No new Win32 metadata annotation is required; shape-based inference is compatibility-only. |
| native constness | Native C/C++ `const` | Parameter or field. Const loss is a windows-rs RDL/winmd fidelity bug, not a header-annotation requirement. |
| scoped enum | guarded `enum class` | Emitted as `ScopedEnum`; normal branch retains the original ABI type. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want this to be the default for enums? In some world we upgrade all the enums to be enum class yyy so the naming works out.

```cpp
BOOL WINAPI OpenPrinterW(
_In_ LPWSTR name,
_Out_

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I'm noticing here is that my eye skims over this attribute-per-line as if each were parameters.

Could we define this instead:

#define _Win32_RAIIFree(CloserFunc, ...) /* something using __VA_ARGS__ */

BOOL WINAPI OpenPrinterW(
    _In_ LPWSTR name,
    _Out_ _Win32_RAIIFree(ClosePrinter, 0, INVALID_HANDLE_VALUE) HANDLE* printer);

The unified pipeline must preserve fixes already present in direct windows-rs
generation:

1. Read `__declspec(align(...))`/Clang alignment independently from packing. `CONTEXT`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a sample showing use of CONTEXT ?


### AllJoyn - 545 initially missing P/Invokes

The `AllJoyn` partition defines `QCC_OS_GROUP_WINDOWS` and directly includes:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start a thread internally on what we can do with this set of types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants