Windows: expand the typed constants to cover broad usage#89575
Windows: expand the typed constants to cover broad usage#89575compnerd wants to merge 15 commits into
Conversation
|
@swift-ci please test Windows platform |
f926c82 to
4c4a3f8
Compare
201565e to
febfcc5
Compare
|
Due to early swift-driver using TSC, we cannot yet apply: swiftlang/swift-tools-support-core#564Please test with following PRs: @swift-ci please smoke test |
|
Please test with following PRs: @swift-ci please smoke test |
|
Please test with following PRs: @swift-ci please smoke test |
1 similar comment
|
Please test with following PRs: @swift-ci please smoke test |
|
Please test with following PRs: @swift-ci please smoke test |
1 similar comment
|
Please test with following PRs: @swift-ci please smoke test |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
|
Please test with following PRs: @swift-ci please test Windows platform |
Macro constants do not have Clang declarations, so APINotes `Globals` metadata cannot be applied through the normal declaration processing path. When importing a macro constant, preserve the macro's `IdentifierInfo` and owning Clang module, and ask Clang Sema whether APINotes provides a replacement type for that macro name. The owning module is needed for module APINotes sidecars such as `WinSDK.apinotes`; location-only lookup can otherwise fall back to directory `APINotes.apinotes` lookup and miss typed macro annotations. Thread the macro identifier through the importer so recursive macro aliases continue to use the originally imported macro name for APINotes lookup while still resolving through to the target macro value. Add APINotes coverage for typed macro constants, including an alias whose target has a different APINotes type. This verifies both that the alias keeps its own APINotes type and that it materializes the resolved target value.
The macro importer records C-style cast types when importing macro constants, but it did not apply the integer conversion to the evaluated constant value. This matters for Windows-style definitions such as `((DWORD)-1)`: the imported Swift declaration has an unsigned type, but the underlying APValue still represents the signed literal `-1`, which can produce an overflow warning when the constant is materialized as `DWORD`. Apply the unsigned integer cast to imported macro values before creating the Swift constant. This truncates or extends the APSInt to the cast type's width and marks it unsigned, matching C's modulo conversion for unsigned integer casts. Keep the existing cast acceptance behavior intact: builtin casts and `id` casts remain the supported forms. The new value adjustment is deliberately limited to non-bool unsigned integer casts so that `_Bool` truth-value conversion and other builtin cast behavior are not changed. Add coverage for builtin unsigned casts and unsigned typedef casts, including a verify test that catches the previous overflow diagnostic.
Add a WinSDK.apinotes sidecar and project it through the Windows SDK VFS overlay next to the virtual WinSDK module map. Install and resync the file with the existing Windows module-map overlay assets so both the runtimes overlay and the legacy stdlib VFS path expose it to ClangImporter. Seed the APINotes file with the WinSDK macro constants that have historically needed typed Swift overlay declarations. Remove the Swift wrappers for macro bodies that the importer can already synthesize as constants, letting APINotes provide the canonical WinSDK typedef spellings for those names. Keep the Swift wrappers for constants whose macro bodies still defeat value import, such as nested pointer casts, helper macros, and aggregate expressions. Those wrappers remain the value-synthesis path until the macro importer can evaluate those forms directly. Add a Windows-only typecheck test that verifies representative APINotes-backed constants keep their typed WinSDK spellings.
This migrates the various constants used in swift-inspect into the APINotes and cleans up the use in the project.
This migrates the Foundation set of typed aliases to the APINotes.
This integrates the typed mapping set from swift-platform-core (https://github.com/compnerd/swift-platform-core).
This adds additional constants used by SwiftPM.
This integrates the typed constants that swift-tools-support-core was holding onto.
This integrates remaining constants that have been encountered by Dia.
Add additional constants that were being carried by Swift Testing.
Migrate the annotations for the constants used by swift-system.
Migrate constants used by swift-subprocess.
Bump the swift-argument-parser pin to allow building with the canonically typed constants.
Bump the swift-system pin to allow building with the canonically typed constants.
|
Please test with following PRs: @swift-ci please test Windows platform |
Migrate constants used by swift-backtrace.
|
@swift-ci please test Windows platform |
|
@swift-ci please smoke test |
1 similar comment
|
@swift-ci please smoke test |
This pull request introduces support for
.apinotestype annotations for Windows SDK macros, allowing Swift to import Windows C macros with more accurate types as specified in APINotes files. The changes include updating the build system to install the newWinSDK.apinotesfile, enhancing the ClangImporter to use macro type overrides from APINotes, and cleaning up redundant Swift definitions for Windows constants now handled via APINotes. Test infrastructure and cases are also updated to verify the new behavior.Build system and VFS updates:
WinSDK.apinotesto the list of files installed and mapped in the Windows overlay and VFS configuration, ensuring it is available for the importer at build and runtime. [1] [2] [3] [4] [5]ClangImporter enhancements for macro type overrides:
Modified
ClangImporter::Implementation::importMacroand related functions to accept and propagate the ClangIdentifierInfopointer, enabling lookup of APINotes type information for macros. Introduced logic to override macro types using APINotes, and refactored macro importing code to support this. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]Updated file mapping logic to redirect
WinSDK.apinotesfor Windows overlays, ensuring the file is found by the importer.Swift standard library cleanup:
WinSDK.swiftthat are now imported directly from the SDK using APINotes type information. [1] [2] [3]Test infrastructure and coverage: