Skip to content

5.9 Windows macros support changes #68334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c15f293
build: clean up dependency tracking for portability
compnerd Sep 1, 2023
f15a99b
build: quote possibly empty parameters
compnerd Sep 1, 2023
2d6a66e
swift-plugin-server: adjust API for portability
compnerd Sep 1, 2023
be13e0b
Update PluginServer.h
compnerd Sep 3, 2023
4eb70d9
Update PluginServer.h
compnerd Sep 4, 2023
89067bf
Update swift-plugin-server.swift
compnerd Sep 4, 2023
2227f8e
[Macros] Replace use of `free` for Swift-allocated pointer
DougGregor Sep 1, 2023
c640550
Use MallocAllocator Allocate/Deallocate consistently.
DougGregor Sep 1, 2023
22cee90
[Swift bridging] Use Swift(U)Int consistently for bridging
DougGregor Sep 1, 2023
ada2535
Define the C++ Swift(U)Int types using the same logic as SwiftShims
DougGregor Sep 1, 2023
5c48b70
Switch order of _WIN64/_WIN32 checks in computation of C types for In…
DougGregor Sep 1, 2023
9b073f5
Fix handling of Swift(U)Int for Windows
DougGregor Sep 1, 2023
225e03b
Apply suggestions from code review
DougGregor Sep 1, 2023
b68953f
Apply suggestions from code review
DougGregor Sep 2, 2023
9f53ff2
ASTGen: adjust for type changes
compnerd Sep 2, 2023
5f678b4
AST,Basic: update support for process execution on Windows
compnerd Sep 1, 2023
5ffa171
Update PluginRegistry.cpp
compnerd Sep 3, 2023
d7e411b
Update Program.cpp
compnerd Sep 4, 2023
880ebd4
ASTGen: account for alternate path separators
compnerd Sep 2, 2023
615ac94
ASTGen: special case the Apple and Linux platforms
compnerd Sep 3, 2023
dae120b
SourceKit: handle Windows paths for request options
compnerd Sep 2, 2023
80f5d52
tests: replace shell with python for portability
compnerd Sep 3, 2023
a6cd8ee
Update process_fine_grained_swiftdeps.py
compnerd Sep 3, 2023
ea22e66
Update process_fine_grained_swiftdeps.py
compnerd Sep 3, 2023
3981f75
tests: add missing `env`
compnerd Sep 4, 2023
cf14a6b
tests: remove gratuitous use of `tee`
compnerd Sep 4, 2023
b010ca7
test: introduce a new `%swift-plugin-dir` macro
compnerd Sep 4, 2023
af332c3
test: mark a job incompatible with Swift parser
compnerd Sep 3, 2023
b36f838
test: loosen expectations to support Windows
compnerd Sep 4, 2023
74a6533
test: sink `-no-toolchain-stdlib-rpath` into lit
compnerd Sep 4, 2023
f871032
Update lit.cfg
compnerd Sep 4, 2023
e9baa22
test: introduce a helper for building mock plugins
compnerd Sep 4, 2023
7dc7741
Update windows-link-job.swift
compnerd Sep 4, 2023
1e9d950
Driver: virtualise the plugin path handling
compnerd Sep 4, 2023
998a5d9
ASTGen: add a workaround for CSC conformance visibility
compnerd Sep 4, 2023
5802d59
Update CBasicBridging.h
compnerd Sep 6, 2023
be30bc3
Update CBasicBridging.h
compnerd Sep 6, 2023
7ddafec
Update CBasicBridging.h
compnerd Sep 6, 2023
bc29301
Update lit.cfg
compnerd Sep 6, 2023
4e8edd4
Update Generics.swift
compnerd Sep 6, 2023
796c4ce
Update PluginHost.swift
compnerd Sep 6, 2023
9401239
ASTGen: more type changes
compnerd Sep 6, 2023
c102ce8
Update Types.swift
compnerd Sep 6, 2023
9fd7a0f
Update Exprs.swift
compnerd Sep 6, 2023
b23238f
Update CASTBridging.cpp
compnerd Sep 6, 2023
48b9593
build: adjust the build to support non-Apple environments
compnerd Sep 1, 2023
0ff4ac6
build: fix the build of the toolchain
compnerd Sep 7, 2023
c79cd30
Update LibcShims.cpp
compnerd Sep 7, 2023
667a1f8
build: copy the import libraries to the correct location
compnerd Sep 8, 2023
49bc58f
swift-plugin-server: remove standard headers
compnerd Sep 6, 2023
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
29 changes: 20 additions & 9 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ function(force_target_link_libraries TARGET)
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})

foreach(DEPENDENCY ${ARGS_PUBLIC})
target_link_libraries(${TARGET} PRIVATE
${DEPENDENCY}
)
target_link_libraries(${TARGET} PRIVATE ${DEPENDENCY})
add_dependencies(${TARGET} ${DEPENDENCY})

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
DEPENDS ${DEPENDENCY}
)
target_sources(${TARGET} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
)
endforeach()
endfunction()
Expand Down Expand Up @@ -270,7 +269,8 @@ function(add_pure_swift_host_tool name)

# Option handling
set(options)
set(single_parameter_options)
set(single_parameter_options
SWIFT_COMPONENT)
set(multiple_parameter_options
DEPENDENCIES
SWIFT_DEPENDENCIES)
Expand Down Expand Up @@ -324,6 +324,17 @@ function(add_pure_swift_host_tool name)
target_include_directories(${name} PUBLIC
${SWIFT_HOST_LIBRARIES_DEST_DIR})

# Export this target.
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component)
add_dependencies(${APSHT_SWIFT_COMPONENT} ${name})
swift_install_in_component(TARGETS ${name}
COMPONENT ${APSHT_SWIFT_COMPONENT}
RUNTIME DESTINATION bin)
swift_is_installing_component(${APSHT_SWIFT_COMPONENT} is_installing)
endif()

if(NOT is_installing)
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
else()
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
endif()
endfunction()
3 changes: 3 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
else()
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
endif()
else()
target_link_directories(${target} PRIVATE
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
endif()

if(SWIFT_SWIFT_PARSER)
Expand Down
27 changes: 12 additions & 15 deletions include/swift/AST/CASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

typedef long SwiftInt;
typedef unsigned long SwiftUInt;

typedef struct {
const void *_Nullable data;
long numElements;
SwiftInt numElements;
} BridgedArrayRef;

typedef struct {
Expand All @@ -65,7 +62,7 @@ typedef struct {
void *_Nullable TrailingCommaLoc;
} BridgedTupleTypeElement;

typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : SwiftInt {
/// A type bound T : P, where T is a type that depends on a generic
/// parameter and P is some type that should bound T, either as a concrete
/// supertype or a protocol to which T must conform.
Expand All @@ -92,7 +89,7 @@ typedef struct {
} BridgedRequirementRepr;

/// Diagnostic severity when reporting diagnostics.
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt {
BridgedFatalError,
BridgedError,
BridgedWarning,
Expand All @@ -102,7 +99,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {

typedef void* BridgedDiagnostic;

typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt {
/// An expanded macro.
BridgedExpandedMacro = 0,
/// An external macro, spelled with either the old spelling (Module.Type)
Expand Down Expand Up @@ -130,7 +127,7 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine,
BridgedDiagnosticSeverity severity,
const void *_Nullable sourceLoc,
const unsigned char *_Nullable text,
long textLen);
SwiftInt textLen);

/// Highlight a source range as part of the diagnostic.
void SwiftDiagnostic_highlight(
Expand All @@ -141,14 +138,14 @@ void SwiftDiagnostic_fixItReplace(BridgedDiagnostic diag,
const void *_Nullable replaceStartLoc,
const void *_Nullable replaceEndLoc,
const unsigned char *_Nullable newText,
long newTextLen);
SwiftInt newTextLen);

/// Finish the given diagnostic and emit it.
void SwiftDiagnostic_finish(BridgedDiagnostic diag);

BridgedIdentifier
SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str,
long len);
SwiftInt len);

void *SwiftImportDecl_create(void *, void *, void *, char, void *,
BridgedArrayRef, BridgedArrayRef);
Expand All @@ -173,11 +170,11 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc);

void *SwiftStringLiteralExpr_create(void *ctx,
const unsigned char *_Nullable string,
long len, void *TokenLoc);
SwiftInt len, void *TokenLoc);

void *SwiftIntegerLiteralExpr_create(void *ctx,
const unsigned char *_Nullable string,
long len, void *TokenLoc);
SwiftInt len, void *TokenLoc);

void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc);

Expand All @@ -194,7 +191,7 @@ void *SingleValueStmtExpr_createWithWrappedBranches(void *ctx, void *S,
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then,
void *_Nullable elseLoc, void *_Nullable elseStmt);

typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt {
ASTNodeKindExpr,
ASTNodeKindStmt,
ASTNodeKindDecl
Expand All @@ -208,7 +205,7 @@ struct ASTNodeBridged {
void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements,
void *rbloc);

void *BridgedSourceLoc_advanced(void *loc, long len);
void *BridgedSourceLoc_advanced(void *loc, SwiftInt len);

void *ParamDecl_create(void *ctx, void *loc, void *_Nullable argLoc,
void *_Nullable argName, void *_Nullable paramLoc,
Expand Down Expand Up @@ -282,7 +279,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc,
BridgedArrayRef reqs, void *rAngleLoc);
void *GenericTypeParamDecl_create(void *ctx, void *declContext,
BridgedIdentifier name, void *nameLoc,
void *_Nullable eachLoc, long index,
void *_Nullable eachLoc, SwiftInt index,
_Bool isParameterPack);
void GenericTypeParamDecl_setInheritedType(void *ctx, void *Param, void *ty);

Expand Down
14 changes: 7 additions & 7 deletions include/swift/AST/PluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ class LoadedExecutablePlugin {

/// Represents the current process of the executable plugin.
struct PluginProcess {
const llvm::sys::procid_t pid;
const int inputFileDescriptor;
const int outputFileDescriptor;
const llvm::sys::ProcessInfo process;
const int input;
const int output;
bool isStale = false;

PluginProcess(llvm::sys::procid_t pid, int inputFileDescriptor,
int outputFileDescriptor);

PluginProcess(llvm::sys::ProcessInfo process, int input, int output)
: process(process), input(input), output(output) {}
~PluginProcess();

ssize_t write(const void *buf, size_t nbyte) const;
Expand Down Expand Up @@ -138,7 +137,8 @@ class LoadedExecutablePlugin {
llvm::erase_value(onReconnect, fn);
}

llvm::sys::procid_t getPid() { return Process->pid; }
llvm::sys::procid_t getPid() { return Process->process.Pid; }
llvm::sys::process_t getProcess() { return Process->process.Process; }

NullTerminatedStringRef getExecutablePath() {
return {ExecutablePath.c_str(), ExecutablePath.size()};
Expand Down
65 changes: 64 additions & 1 deletion include/swift/Basic/CBasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,69 @@
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.

// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include
// that header here because it belongs to the runtime, but we need the same
// logic for interoperability with Swift code in the compiler itself.
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
// result, using stdint.h here would pull in Darwin module (which includes
// libc). This creates a dependency cycle, so we can't use stdint.h in
// SwiftShims.
// On Linux, the story is different. We get the error message
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
// found"
// This is a known Clang/Ubuntu bug.

// Clang has been defining __INTxx_TYPE__ macros for a long time.
// __UINTxx_TYPE__ are defined only since Clang 3.5.
#if defined(_MSC_VER) && !defined(__clang__)
typedef __int64 __swiftc_int64_t;
typedef unsigned __int64 __swiftc_uint64_t;
typedef int __swiftc_int32_t;
typedef unsigned int __swiftc_uint32_t;
#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
#include <stdint.h>
typedef int64_t __swiftc_int64_t;
typedef uint64_t __swiftc_uint64_t;
typedef int32_t __swiftc_int32_t;
typedef uint32_t __swiftc_uint32_t;
typedef intptr_t __swiftc_intptr_t;
typedef uintptr_t __swiftc_uintptr_t;
#else
typedef __INT64_TYPE__ __swiftc_int64_t;
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ __swiftc_uint64_t;
#else
typedef unsigned __INT64_TYPE__ __swiftc_uint64_t;
#endif

typedef __INT32_TYPE__ __swiftc_int32_t;
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ __swiftc_uint32_t;
#else
typedef unsigned __INT32_TYPE__ __swiftc_uint32_t;
#endif
#endif

#define __swiftc_join3(a,b,c) a ## b ## c

#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t)
#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t)

#if defined(_MSC_VER) && !defined(__clang__)
#if defined(_WIN64)
typedef __swiftc_int64_t SwiftInt;
typedef __swiftc_uint64_t SwiftUInt;
#elif defined(_WIN32)
typedef __swiftc_int32_t SwiftInt;
typedef __swiftc_uint32_t SwiftUInt;
#else
#error unknown windows pointer width
#endif
#else
typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt;
typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt;
#endif

#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
Expand Down Expand Up @@ -48,7 +111,7 @@ extern "C" {

typedef struct BridgedData {
const char *_Nullable baseAddress;
unsigned long size;
SwiftUInt size;
} BridgedData;

void BridgedData_free(BridgedData data);
Expand Down
12 changes: 5 additions & 7 deletions include/swift/Basic/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ int ExecuteInPlace(const char *Program, const char **args,
const char **env = nullptr);

struct ChildProcessInfo {
llvm::sys::procid_t Pid;
int WriteFileDescriptor;
int ReadFileDescriptor;
llvm::sys::ProcessInfo ProcessInfo;
int Write;
int Read;

ChildProcessInfo(llvm::sys::procid_t Pid, int WriteFileDescriptor,
int ReadFileDescriptor)
: Pid(Pid), WriteFileDescriptor(WriteFileDescriptor),
ReadFileDescriptor(ReadFileDescriptor) {}
ChildProcessInfo(llvm::sys::ProcessInfo ProcessInfo, int Write, int Read)
: ProcessInfo(ProcessInfo), Write(Write), Read(Read) {}
};

/// This function executes the program using the argument provided.
Expand Down
5 changes: 4 additions & 1 deletion include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ class ToolChain {
void addLinkRuntimeLib(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &Arguments,
StringRef LibName) const;


virtual void addPluginArguments(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &Arguments) const {}

/// Validates arguments passed to the toolchain.
///
/// An override point for platform-specific subclasses to customize the
Expand Down
Loading