Skip to content

5.9.0 Windows macro support #68335

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

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
904e09a
build: quote possibly empty parameters
compnerd Sep 1, 2023
f5fd980
swift-plugin-server: adjust API for portability
compnerd Sep 1, 2023
aea45ff
Update PluginServer.h
compnerd Sep 3, 2023
02b4200
Update PluginServer.h
compnerd Sep 4, 2023
f9c7502
Update swift-plugin-server.swift
compnerd Sep 4, 2023
28cfbb6
[Macros] Replace use of `free` for Swift-allocated pointer
DougGregor Sep 1, 2023
831c90d
Use MallocAllocator Allocate/Deallocate consistently.
DougGregor Sep 1, 2023
2e204a7
[Swift bridging] Use Swift(U)Int consistently for bridging
DougGregor Sep 1, 2023
f443045
Define the C++ Swift(U)Int types using the same logic as SwiftShims
DougGregor Sep 1, 2023
c22874b
Switch order of _WIN64/_WIN32 checks in computation of C types for In…
DougGregor Sep 1, 2023
70b459f
Fix handling of Swift(U)Int for Windows
DougGregor Sep 1, 2023
1b38a72
Apply suggestions from code review
DougGregor Sep 1, 2023
fbc0613
Apply suggestions from code review
DougGregor Sep 2, 2023
d6a507e
ASTGen: adjust for type changes
compnerd Sep 2, 2023
37f01b5
AST,Basic: update support for process execution on Windows
compnerd Sep 1, 2023
d40038c
Update PluginRegistry.cpp
compnerd Sep 3, 2023
c454d49
Update Program.cpp
compnerd Sep 4, 2023
0484890
ASTGen: account for alternate path separators
compnerd Sep 2, 2023
d1af465
ASTGen: special case the Apple and Linux platforms
compnerd Sep 3, 2023
e10f05b
SourceKit: handle Windows paths for request options
compnerd Sep 2, 2023
0b1a8ff
tests: replace shell with python for portability
compnerd Sep 3, 2023
f2b1cdd
Update process_fine_grained_swiftdeps.py
compnerd Sep 3, 2023
a71d788
Update process_fine_grained_swiftdeps.py
compnerd Sep 3, 2023
926b7cc
tests: add missing `env`
compnerd Sep 4, 2023
0b01e36
tests: remove gratuitous use of `tee`
compnerd Sep 4, 2023
e5bf67f
test: introduce a new `%swift-plugin-dir` macro
compnerd Sep 4, 2023
2dabb05
test: mark a job incompatible with Swift parser
compnerd Sep 3, 2023
d5befb2
test: loosen expectations to support Windows
compnerd Sep 4, 2023
599f27b
test: sink `-no-toolchain-stdlib-rpath` into lit
compnerd Sep 4, 2023
6953818
Update lit.cfg
compnerd Sep 4, 2023
e1ccd70
test: introduce a helper for building mock plugins
compnerd Sep 4, 2023
bf106b8
Update windows-link-job.swift
compnerd Sep 4, 2023
bde32eb
Driver: virtualise the plugin path handling
compnerd Sep 4, 2023
1226704
ASTGen: add a workaround for CSC conformance visibility
compnerd Sep 4, 2023
a282a60
Update CBasicBridging.h
compnerd Sep 6, 2023
78f7f68
Update CBasicBridging.h
compnerd Sep 6, 2023
c85ec02
Update CBasicBridging.h
compnerd Sep 6, 2023
37856b1
Update lit.cfg
compnerd Sep 6, 2023
8ec669d
Update Generics.swift
compnerd Sep 6, 2023
328195a
Update PluginHost.swift
compnerd Sep 6, 2023
b3053ea
ASTGen: more type changes
compnerd Sep 6, 2023
7e258fa
Update Types.swift
compnerd Sep 6, 2023
7467c04
Update Exprs.swift
compnerd Sep 6, 2023
6fc440e
Update CASTBridging.cpp
compnerd Sep 6, 2023
fbd57e4
build: adjust the build to support non-Apple environments
compnerd Sep 1, 2023
f8b216d
build: fix the build of the toolchain
compnerd Sep 7, 2023
787fff9
Update LibcShims.cpp
compnerd Sep 7, 2023
b0146b7
build: copy the import libraries to the correct location
compnerd Sep 8, 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
18 changes: 15 additions & 3 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,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 +325,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
30 changes: 17 additions & 13 deletions lib/AST/CASTBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static SourceLoc getSourceLocFromPointer(const void *loc) {

namespace {
struct BridgedDiagnosticImpl {
typedef llvm::MallocAllocator Allocator;

InFlightDiagnostic inFlight;
std::vector<StringRef> textBlobs;

Expand All @@ -37,8 +39,10 @@ namespace {

~BridgedDiagnosticImpl() {
inFlight.flush();

Allocator allocator;
for (auto text: textBlobs) {
free((void*)text.data());
allocator.Deallocate(text.data(), text.size());
}
}
};
Expand All @@ -48,11 +52,11 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine,
BridgedDiagnosticSeverity severity,
const void *sourceLocPtr,
const unsigned char *textPtr,
long textLen) {
SwiftInt textLen) {
StringRef origText{
reinterpret_cast<const char *>(textPtr), size_t(textLen)};
llvm::MallocAllocator mallocAlloc;
StringRef text = origText.copy(mallocAlloc);
BridgedDiagnosticImpl::Allocator alloc;
StringRef text = origText.copy(alloc);

SourceLoc loc = getSourceLocFromPointer(sourceLocPtr);

Expand Down Expand Up @@ -95,15 +99,15 @@ void SwiftDiagnostic_fixItReplace(BridgedDiagnostic diagPtr,
const void *replaceStartLocPtr,
const void *replaceEndLocPtr,
const unsigned char *newTextPtr,
long newTextLen) {
SwiftInt newTextLen) {

SourceLoc startLoc = getSourceLocFromPointer(replaceStartLocPtr);
SourceLoc endLoc = getSourceLocFromPointer(replaceEndLocPtr);

StringRef origReplaceText{
reinterpret_cast<const char *>(newTextPtr), size_t(newTextLen)};
llvm::MallocAllocator mallocAlloc;
StringRef replaceText = origReplaceText.copy(mallocAlloc);
BridgedDiagnosticImpl::Allocator alloc;
StringRef replaceText = origReplaceText.copy(alloc);

BridgedDiagnosticImpl *impl = static_cast<BridgedDiagnosticImpl *>(diagPtr);
impl->textBlobs.push_back(replaceText);
Expand All @@ -118,7 +122,7 @@ void SwiftDiagnostic_finish(BridgedDiagnostic diagPtr) {

BridgedIdentifier
SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str,
long len) {
SwiftInt len) {
return const_cast<void *>(
static_cast<ASTContext *>(ctx)
->getIdentifier(
Expand All @@ -145,7 +149,7 @@ void *SwiftImportDecl_create(void *ctx, void *dc, void *importLoc, char kind,
getSourceLocFromPointer(kindLoc), std::move(importPath).get());
}

void *BridgedSourceLoc_advanced(void *loc, long len) {
void *BridgedSourceLoc_advanced(void *loc, SwiftInt len) {
SourceLoc l = getSourceLocFromPointer(loc).getAdvancedLoc(len);
return const_cast<void *>(l.getOpaquePointerValue());
}
Expand Down Expand Up @@ -216,7 +220,7 @@ 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) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
auto stringRef = Context.AllocateCopy(
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
Expand All @@ -226,7 +230,7 @@ void *SwiftStringLiteralExpr_create(void *ctx,

void *SwiftIntegerLiteralExpr_create(void *ctx,
const unsigned char *_Nullable string,
long len, void *TokenLoc) {
SwiftInt len, void *TokenLoc) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
auto stringRef = Context.AllocateCopy(
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
Expand Down Expand Up @@ -582,7 +586,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc,

void *GenericTypeParamDecl_create(void *ctx, void *declContext,
BridgedIdentifier name, void *nameLoc,
void *_Nullable eachLoc, long index,
void *_Nullable eachLoc, SwiftInt index,
bool isParameterPack) {
return GenericTypeParamDecl::createParsed(
static_cast<DeclContext *>(declContext),
Expand Down Expand Up @@ -695,6 +699,6 @@ bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *out) {
auto size = message.size();
auto outPtr = malloc(size);
memcpy(outPtr, message.data(), size);
*out = BridgedData{(const char *)outPtr, (unsigned long)size};
*out = BridgedData{(const char *)outPtr, (SwiftUInt)size};
return false;
}
Loading