Skip to content

Commit 60e41d6

Browse files
authored
Merge pull request #75727 from bnbarham/manually-merge-main-to-rebranch
[rebranch] Manually merge main to rebranch
2 parents 245fd5b + 7bdf1e1 commit 60e41d6

File tree

80 files changed

+1864
-745
lines changed

Some content is hidden

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

80 files changed

+1864
-745
lines changed

SwiftCompilerSources/Sources/Optimizer/Analysis/AliasAnalysis.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ struct AliasAnalysis {
309309
if destroy.destroyedValue.type.isNoEscapeFunction {
310310
return .noEffects
311311
}
312+
if destroy.isDeadEnd {
313+
// We don't have to take deinit effects into acount for a `destroy_value [dead_end]`.
314+
// Such destroys are lowered to no-ops and will not call any deinit.
315+
return .noEffects
316+
}
312317
return defaultEffects(of: destroy, on: memLoc)
313318

314319
default:
@@ -569,11 +574,7 @@ private enum MemoryLocation {
569574
var isLetValue: Bool {
570575
switch self {
571576
case .memoryAddress(let addr):
572-
switch addr.accessBase {
573-
case .global(let global): return global.isLet
574-
case .class(let rea): return rea.fieldIsLet
575-
default: return false
576-
}
577+
return addr.accessBase.isLet
577578
case .modifyAccessScope:
578579
return false
579580
}

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
571571
switch uacUse.instruction {
572572
case is IsUniqueInst:
573573
break
574-
case is LoadInst, is LoadBorrowInst:
574+
case is LoadInst, is LoadBorrowInst, is ApplyInst, is TryApplyInst:
575575
if followLoads(at: path) {
576576
return .abortWalk
577577
}

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,6 @@ private struct EscapesToValueVisitor : EscapeVisitor {
625625
}
626626

627627
extension Function {
628-
var globalOfGlobalInitFunction: GlobalVariable? {
629-
if isGlobalInitFunction,
630-
let ret = returnInstruction,
631-
let atp = ret.returnedValue as? AddressToPointerInst,
632-
let ga = atp.address as? GlobalAddrInst {
633-
return ga.global
634-
}
635-
return nil
636-
}
637-
638628
var initializedGlobal: GlobalVariable? {
639629
if !isGlobalInitOnceFunction {
640630
return nil

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ final public class UnmanagedAutoreleaseValueInst : RefCountingInst {}
506506

507507
final public class DestroyValueInst : Instruction, UnaryInstruction {
508508
public var destroyedValue: Value { operand.value }
509+
510+
/// True if this `destroy_value` is inside a dead-end block is only needed to formally
511+
/// end the lifetime of its operand.
512+
/// Such `destroy_value` instructions are lowered to no-ops.
513+
public var isDeadEnd: Bool { bridged.DestroyValueInst_isDeadEnd() }
509514
}
510515

511516
final public class DestroyAddrInst : Instruction, UnaryInstruction {

SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@ private extension PointerToAddressInst {
434434
}
435435
return walker.result
436436
}
437+
438+
var resultOfGlobalAddressorCall: GlobalVariable? {
439+
if isStrict,
440+
let apply = pointer as? ApplyInst,
441+
let callee = apply.referencedFunction,
442+
let global = callee.globalOfGlobalInitFunction
443+
{
444+
return global
445+
}
446+
return nil
447+
}
437448
}
438449

439450
/// The `EnclosingScope` of an access is the innermost `begin_access`
@@ -507,6 +518,9 @@ private struct AccessPathWalker : AddressUseDefWalker {
507518
if let p2ai = address as? PointerToAddressInst {
508519
if let originatingAddr = p2ai.originatingAddress {
509520
return walkUp(address: originatingAddr, path: path)
521+
} else if let global = p2ai.resultOfGlobalAddressorCall {
522+
self.result = AccessPath(base: .global(global), projectionPath: path.projectionPath)
523+
return .continueWalk
510524
} else {
511525
self.result = AccessPath(base: .pointer(p2ai), projectionPath: path.projectionPath)
512526
return .continueWalk
@@ -628,3 +642,15 @@ extension ValueUseDefWalker where Path == SmallProjectionPath {
628642
}
629643
}
630644
}
645+
646+
extension Function {
647+
public var globalOfGlobalInitFunction: GlobalVariable? {
648+
if isGlobalInitFunction,
649+
let ret = returnInstruction,
650+
let atp = ret.returnedValue as? AddressToPointerInst,
651+
let ga = atp.address as? GlobalAddrInst {
652+
return ga.global
653+
}
654+
return nil
655+
}
656+
}

include/swift/AST/ASTBridging.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/Attr.h"
2727
#include "swift/AST/DiagnosticConsumer.h"
2828
#include "swift/AST/DiagnosticEngine.h"
29+
#include "swift/AST/IfConfigClauseRangeInfo.h"
2930
#include "swift/AST/Stmt.h"
3031
#endif
3132

@@ -190,6 +191,75 @@ bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,
190191
SWIFT_NAME("getter:BridgedASTContext.majorLanguageVersion(self:)")
191192
unsigned BridgedASTContext_majorLanguageVersion(BridgedASTContext cContext);
192193

194+
SWIFT_NAME("BridgedASTContext.langOptsCustomConditionSet(self:_:)")
195+
bool BridgedASTContext_langOptsCustomConditionSet(BridgedASTContext cContext,
196+
BridgedStringRef cName);
197+
198+
SWIFT_NAME("BridgedASTContext.langOptsHasFeatureNamed(self:_:)")
199+
bool BridgedASTContext_langOptsHasFeatureNamed(BridgedASTContext cContext,
200+
BridgedStringRef cName);
201+
202+
SWIFT_NAME("BridgedASTContext.langOptsHasAttributeNamed(self:_:)")
203+
bool BridgedASTContext_langOptsHasAttributeNamed(BridgedASTContext cContext,
204+
BridgedStringRef cName);
205+
206+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetOS(self:_:)")
207+
bool BridgedASTContext_langOptsIsActiveTargetOS(BridgedASTContext cContext,
208+
BridgedStringRef cName);
209+
210+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetArchitecture(self:_:)")
211+
bool BridgedASTContext_langOptsIsActiveTargetArchitecture(BridgedASTContext cContext,
212+
BridgedStringRef cName);
213+
214+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetEnvironment(self:_:)")
215+
bool BridgedASTContext_langOptsIsActiveTargetEnvironment(BridgedASTContext cContext,
216+
BridgedStringRef cName);
217+
218+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetRuntime(self:_:)")
219+
bool BridgedASTContext_langOptsIsActiveTargetRuntime(BridgedASTContext cContext,
220+
BridgedStringRef cName);
221+
222+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetPtrAuth(self:_:)")
223+
bool BridgedASTContext_langOptsIsActiveTargetPtrAuth(BridgedASTContext cContext,
224+
BridgedStringRef cName);
225+
226+
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetPointerBitWidth(self:)")
227+
unsigned BridgedASTContext_langOptsTargetPointerBitWidth(BridgedASTContext cContext);
228+
229+
SWIFT_NAME("BridgedASTContext.langOptsGetTargetAtomicBitWidths(self:_:)")
230+
SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths(BridgedASTContext cContext,
231+
SwiftInt* _Nullable * _Nonnull cComponents);
232+
233+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
234+
EndianLittle,
235+
EndianBig,
236+
};
237+
238+
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetEndianness(self:)")
239+
BridgedEndianness BridgedASTContext_langOptsTargetEndianness(BridgedASTContext cContext);
240+
241+
SWIFT_NAME("BridgedASTContext.langOptsGetLanguageVersion(self:_:)")
242+
SwiftInt BridgedASTContext_langOptsGetLanguageVersion(BridgedASTContext cContext,
243+
SwiftInt* _Nullable * _Nonnull cComponents);
244+
245+
SWIFT_NAME("BridgedASTContext.langOptsGetCompilerVersion(self:_:)")
246+
SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
247+
SwiftInt* _Nullable * _Nonnull cComponents);
248+
249+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedCanImportVersion : size_t {
250+
CanImportUnversioned,
251+
CanImportVersion,
252+
CanImportUnderlyingVersion,
253+
};
254+
255+
SWIFT_NAME("BridgedASTContext.canImport(self:importPath:location:versionKind:versionComponents:numVersionComponents:)")
256+
bool BridgedASTContext_canImport(BridgedASTContext cContext,
257+
BridgedStringRef importPath,
258+
BridgedSourceLoc canImportLoc,
259+
BridgedCanImportVersion versionKind,
260+
const SwiftInt * _Nullable versionComponents,
261+
SwiftInt numVersionComponents);
262+
193263
//===----------------------------------------------------------------------===//
194264
// MARK: AST nodes
195265
//===----------------------------------------------------------------------===//
@@ -1844,6 +1914,49 @@ BridgedParameterList BridgedParameterList_createParsed(
18441914
BridgedASTContext cContext, BridgedSourceLoc cLeftParenLoc,
18451915
BridgedArrayRef cParameters, BridgedSourceLoc cRightParenLoc);
18461916

1917+
//===----------------------------------------------------------------------===//
1918+
// MARK: #if handling
1919+
//===----------------------------------------------------------------------===//
1920+
1921+
/// Bridged version of IfConfigClauseRangeInfo::ClauseKind.
1922+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedIfConfigClauseKind : size_t {
1923+
IfConfigActive,
1924+
IfConfigInactive,
1925+
IfConfigEnd
1926+
};
1927+
1928+
/// Bridged version of IfConfigClauseRangeInfo.
1929+
struct BridgedIfConfigClauseRangeInfo {
1930+
BridgedSourceLoc directiveLoc;
1931+
BridgedSourceLoc bodyLoc;
1932+
BridgedSourceLoc endLoc;
1933+
BridgedIfConfigClauseKind kind;
1934+
1935+
#ifdef USED_IN_CPP_SOURCE
1936+
swift::IfConfigClauseRangeInfo unbridged() const {
1937+
swift::IfConfigClauseRangeInfo::ClauseKind clauseKind;
1938+
switch (kind) {
1939+
case IfConfigActive:
1940+
clauseKind = swift::IfConfigClauseRangeInfo::ActiveClause;
1941+
break;
1942+
1943+
case IfConfigInactive:
1944+
clauseKind = swift::IfConfigClauseRangeInfo::InactiveClause;
1945+
break;
1946+
1947+
case IfConfigEnd:
1948+
clauseKind = swift::IfConfigClauseRangeInfo::EndDirective;
1949+
break;
1950+
}
1951+
1952+
return swift::IfConfigClauseRangeInfo(directiveLoc.unbridged(),
1953+
bodyLoc.unbridged(),
1954+
endLoc.unbridged(),
1955+
clauseKind);
1956+
}
1957+
#endif
1958+
};
1959+
18471960
//===----------------------------------------------------------------------===//
18481961
// MARK: Plugins
18491962
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)