Skip to content

Commit fd22790

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 7723322 + 4ff65cc commit fd22790

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+802
-86
lines changed

Runtimes/Supplemental/Synchronization/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,45 @@ target_link_libraries(swiftSynchronization PRIVATE
141141
$<$<PLATFORM_ID:Darwin>:swiftDarwin>
142142
$<$<PLATFORM_ID:Windows>:ClangModules>)
143143

144+
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
145+
# FIXME(#83765) `-whole-module-optimization` should not be needed. However,
146+
# without this, we will not properly optimize. On Windows i686 in particular,
147+
# we observe the formation of `__atomic_load` calls rather than the expected
148+
# native sequence.
149+
cmake_policy(GET CMP0157 _PolicyCMP0157)
150+
if(_PolicyCMP0157 STREQUAL NEW)
151+
set_target_properties(swiftSynchronization PROPERTIES
152+
Swift_COMPILATION_MODE wholemodule)
153+
else()
154+
target_compile_options(swiftSynchronization PRIVATE
155+
$<$<COMPILE_LANGUAGE:Swift>:-whole-module-optimization>)
156+
endif()
157+
158+
# WMO requires the early-swift-driver to be usable, which is not yet ready on
159+
# Windows. Workaround this by creating an empty stub for swiftCore, removing
160+
# the import library from the command line, and adding the library search path
161+
# associated with it. Due to the autolink, we will still link against the
162+
# library from the correct location but will also use an empty file for the
163+
# additional input allowing us to perform the WMO.
164+
if(CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
165+
get_target_property(_swiftCore_IMPORTED_IMPLIB_RELEASE swiftCore
166+
IMPORTED_IMPLIB_RELEASE)
167+
if(_swiftCore_IMPORTED_IMPLIB_RELEASE)
168+
# Compute the library directory to allow us to find the import library by
169+
# name.
170+
get_filename_component(_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME
171+
${_swiftCore_IMPORTED_IMPLIB_RELEASE} DIRECTORY)
172+
# Create a (empty) stub library
173+
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib")
174+
# Replace the import library with a stub to bypass the driver and frontend.
175+
# Add the library search path to allow linking via autolinking.
176+
set_target_properties(swiftCore PROPERTIES
177+
IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib"
178+
INTERFACE_LINK_DIRECTORIES ${_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME})
179+
endif()
180+
endif()
181+
endif()
182+
144183
install(TARGETS swiftSynchronization
145184
EXPORT SwiftSynchronizationTargets
146185
COMPONENT ${PROJECT_NAME}_runtime

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjectOutliner.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ private func optimizeObjectAllocation(allocRef: AllocRefInstBase, _ context: Fun
109109
type: allocRef.type, linkage: .private,
110110
// Only if it's a COW object we can be sure that the object allocated in the global is not mutated.
111111
// If someone wants to mutate it, it has to be copied first.
112-
isLet: endOfInitInst is EndCOWMutationInst)
112+
isLet: endOfInitInst is EndCOWMutationInst,
113+
markedAsUsed: false)
113114

114115
constructObject(of: allocRef, inInitializerOf: outlinedGlobal, storesToClassFields, storesToTailElements, context)
115116
context.erase(instructions: storesToClassFields)
@@ -555,7 +556,7 @@ private func replace(findStringCall: ApplyInst,
555556

556557
// Create an "opaque" global variable which is passed as inout to
557558
// _findStringSwitchCaseWithCache and into which the function stores the "cache".
558-
let cacheVar = context.createGlobalVariable(name: name, type: cacheType, linkage: .private, isLet: false)
559+
let cacheVar = context.createGlobalVariable(name: name, type: cacheType, linkage: .private, isLet: false, markedAsUsed: false)
559560

560561
let varBuilder = Builder(staticInitializerOf: cacheVar, context)
561562
let zero = varBuilder.createIntegerLiteral(0, type: wordTy)

SwiftCompilerSources/Sources/SIL/Context.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ extension MutatingContext {
114114
_bridged.notifyChanges(.Effects)
115115
}
116116

117-
public func createGlobalVariable(name: String, type: Type, linkage: Linkage, isLet: Bool) -> GlobalVariable {
117+
public func createGlobalVariable(name: String, type: Type, linkage: Linkage, isLet: Bool, markedAsUsed: Bool) -> GlobalVariable {
118118
let gv = name._withBridgedStringRef {
119-
_bridged.createGlobalVariable($0, type.bridged, linkage.bridged, isLet)
119+
_bridged.createGlobalVariable($0, type.bridged, linkage.bridged, isLet,
120+
markedAsUsed)
120121
}
121122
return gv.globalVar
122123
}

include/swift/AST/Decl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
10681068
/// behaviors for it and, if it's an extension, its members.
10691069
bool isObjCImplementation() const;
10701070

1071+
/// True if this declaration should never have its implementation made
1072+
/// available to any client. This overrides cross-module optimization and
1073+
/// optimizations that might use the implementation, such that the only
1074+
/// implementation of this function is the one compiled into its owning
1075+
/// module. Practically speaking, this prohibits serialization of the SIL
1076+
/// for this definition.
1077+
bool isNeverEmittedIntoClient() const;
1078+
10711079
using AuxiliaryDeclCallback = llvm::function_ref<void(Decl *)>;
10721080

10731081
/// Iterate over the auxiliary declarations for this declaration,

include/swift/AST/DeclAttr.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ SIMPLE_DECL_ATTR(requires_stored_property_inits, RequiresStoredPropertyInits,
201201
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | UnreachableInABIAttr,
202202
27)
203203

204-
// Unused '28'
204+
SIMPLE_DECL_ATTR(_neverEmitIntoClient, NeverEmitIntoClient,
205+
OnVar | OnSubscript | OnAbstractFunction,
206+
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
207+
28)
208+
205209
// Unused '29'
206210

207211
SIMPLE_DECL_ATTR(nonobjc, NonObjC,

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ ERROR(foreign_reference_types_invalid_retain_release, none,
261261

262262
ERROR(foreign_reference_types_retain_non_void_or_self_return_type, none,
263263
"specified retain function '%0' is invalid; "
264-
"retain function must have 'void' or parameter return type",
264+
"retain function must either return have 'void', the reference count as an integer, or the parameter type",
265265
(StringRef))
266266
ERROR(foreign_reference_types_release_non_void_return_type, none,
267267
"specified release function '%0' is invalid; "
268-
"release function must have 'void' return type",
268+
"release function must either return 'void' or the reference count as an integer",
269269
(StringRef))
270270
ERROR(foreign_reference_types_retain_release_not_a_function_decl, none,
271271
"specified %select{retain|release}0 function '%1' is not a function",

include/swift/IRGen/Linking.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,14 @@ class LinkEntity {
18501850
bool isTypeKind() const { return isTypeKind(getKind()); }
18511851

18521852
bool isAlwaysSharedLinkage() const;
1853+
1854+
/// Whether the link entity's definitions must be considered non-unique.
1855+
///
1856+
/// This applies only in the Embedded Swift linkage model, and is used for
1857+
/// any symbols that have not been explicitly requested to have unique
1858+
/// definitions (e.g., with @_used).
1859+
bool hasNonUniqueDefinition() const;
1860+
18531861
#undef LINKENTITY_GET_FIELD
18541862
#undef LINKENTITY_SET_FIELD
18551863

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ struct BridgedGlobalVar {
596596
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
597597
BRIDGED_INLINE bool isLet() const;
598598
BRIDGED_INLINE void setLet(bool value) const;
599+
BRIDGED_INLINE bool markedAsUsed() const;
600+
BRIDGED_INLINE void setMarkedAsUsed(bool value) const;
599601
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getType() const;
600602
BRIDGED_INLINE BridgedLinkage getLinkage() const;
601603
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SourceLoc getSourceLocation() const;
@@ -1449,7 +1451,8 @@ struct BridgedContext {
14491451
bool hasSelfParam,
14501452
BridgedFunction fromFunc) const;
14511453
SWIFT_IMPORT_UNSAFE BridgedGlobalVar createGlobalVariable(BridgedStringRef name, BridgedType type,
1452-
BridgedLinkage linkage, bool isLet) const;
1454+
BridgedLinkage linkage, bool isLet,
1455+
bool markedAsUsed) const;
14531456
void moveFunctionBody(BridgedFunction sourceFunc, BridgedFunction destFunc) const;
14541457

14551458
// Function-local SIL modifications

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,14 @@ bool BridgedGlobalVar::isLet() const { return getGlobal()->isLet(); }
932932

933933
void BridgedGlobalVar::setLet(bool value) const { getGlobal()->setLet(value); }
934934

935+
bool BridgedGlobalVar::markedAsUsed() const {
936+
return getGlobal()->markedAsUsed();
937+
}
938+
939+
void BridgedGlobalVar::setMarkedAsUsed(bool value) const {
940+
getGlobal()->setMarkedAsUsed(value);
941+
}
942+
935943
BridgedType BridgedGlobalVar::getType() const {
936944
return getGlobal()->getLoweredType();
937945
}

include/swift/SIL/SILDeclRef.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ struct SILDeclRef {
399399
/// True if the function has the @backDeployed attribute.
400400
bool isBackDeployed() const;
401401

402+
/// True if this entity should have a non-unique definition based on the
403+
/// embedded linkage model.
404+
bool hasNonUniqueDefinition() const;
405+
406+
/// True if the declaration should have a non-unique definition based on the
407+
/// embedded linkage model.
408+
static bool declHasNonUniqueDefinition(const ValueDecl *decl);
409+
402410
/// Return the expected linkage for a definition of this declaration.
403411
SILLinkage getDefinitionLinkage() const;
404412

0 commit comments

Comments
 (0)