Skip to content

Commit 05d4664

Browse files
authored
Merge branch 'main' into unsafe
2 parents 0f6e0b7 + d32cbba commit 05d4664

File tree

185 files changed

+2404
-630
lines changed

Some content is hidden

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

185 files changed

+2404
-630
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ extension LifetimeDependence {
195195
if arg.isIndirectResult {
196196
return nil
197197
}
198-
self.scope = Scope(base: arg, context)!
198+
guard let scope = Scope(base: arg, context) else {
199+
// Ignore invalid argument types.
200+
return nil
201+
}
202+
self.scope = scope
199203
self.dependentValue = arg
200204
}
201205

@@ -309,7 +313,7 @@ extension LifetimeDependence.Scope {
309313
}
310314
self = scope
311315
case .none:
312-
// lifetime dependence requires a nontrivial value"
316+
// lifetime dependence requires a nontrivial value
313317
return nil
314318
case .unowned:
315319
self = .unknown(base)

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
5656
public var isEnum: Bool { bridged.isEnumOrBoundGenericEnum() }
5757
public var isFunction: Bool { bridged.isFunction() }
5858
public var isMetatype: Bool { bridged.isMetatype() }
59+
public var isClassExistential: Bool { bridged.isClassExistential() }
5960
public var isNoEscapeFunction: Bool { bridged.isNoEscapeFunction() }
6061
public var containsNoEscapeFunction: Bool { bridged.containsNoEscapeFunction() }
6162
public var isThickFunction: Bool { bridged.isThickFunction() }
@@ -65,6 +66,8 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
6566

6667
public var isMoveOnly: Bool { bridged.isMoveOnly() }
6768

69+
// Note that invalid types are not considered Escapable. This makes it difficult to make any assumptions about
70+
// nonescapable types.
6871
public func isEscapable(in function: Function) -> Bool {
6972
bridged.isEscapable(function.bridged)
7073
}

SwiftCompilerSources/Sources/SIL/Utilities/WalkUtils.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,17 @@ extension ValueDefUseWalker {
360360
return unmatchedPath(value: operand, path: path)
361361
}
362362
case is BeginBorrowInst, is CopyValueInst, is MoveValueInst,
363-
is UpcastInst, is UncheckedRefCastInst, is EndCOWMutationInst, is EndInitLetRefInst,
363+
is UpcastInst, is EndCOWMutationInst, is EndInitLetRefInst,
364364
is RefToBridgeObjectInst, is BridgeObjectToRefInst, is MarkUnresolvedNonCopyableValueInst:
365365
return walkDownUses(ofValue: (instruction as! SingleValueInstruction), path: path)
366+
case let urc as UncheckedRefCastInst:
367+
if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential {
368+
// Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of
369+
// init_existential_ref and open_existential_ref).
370+
// We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind.
371+
return leafUse(value: operand, path: path)
372+
}
373+
return walkDownUses(ofValue: urc, path: path)
366374
case let beginDealloc as BeginDeallocRefInst:
367375
if operand.index == 0 {
368376
return walkDownUses(ofValue: beginDealloc, path: path)
@@ -680,10 +688,18 @@ extension ValueUseDefWalker {
680688
case let oer as OpenExistentialRefInst:
681689
return walkUp(value: oer.existential, path: path.push(.existential, index: 0))
682690
case is BeginBorrowInst, is CopyValueInst, is MoveValueInst,
683-
is UpcastInst, is UncheckedRefCastInst, is EndCOWMutationInst, is EndInitLetRefInst,
691+
is UpcastInst, is EndCOWMutationInst, is EndInitLetRefInst,
684692
is BeginDeallocRefInst,
685693
is RefToBridgeObjectInst, is BridgeObjectToRefInst, is MarkUnresolvedNonCopyableValueInst:
686694
return walkUp(value: (def as! Instruction).operands[0].value, path: path)
695+
case let urc as UncheckedRefCastInst:
696+
if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential {
697+
// Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of
698+
// init_existential_ref and open_existential_ref).
699+
// We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind.
700+
return rootDef(value: urc, path: path)
701+
}
702+
return walkUp(value: urc.fromInstance, path: path)
687703
case let arg as Argument:
688704
if let phi = Phi(arg) {
689705
for incoming in phi.incomingValues {

benchmark/cxx-source/CxxSetToCollection.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
// to a Swift collection.
1515

1616
import TestsUtils
17-
18-
#if SWIFT_PACKAGE
19-
// FIXME: Needs fix for https://github.com/apple/swift/issues/61547.
20-
21-
public let benchmarks = [BenchmarkInfo]()
22-
23-
#else
24-
2517
import CxxStdlibPerformance
2618
import Cxx
2719
import CxxStdlib // FIXME(rdar://128520766): this import should be redundant
@@ -72,5 +64,3 @@ public func run_CxxSetOfU32_forEach(_ n: Int) {
7264
}
7365
}
7466
}
75-
76-
#endif

benchmark/cxx-source/CxxVectorSum.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
// as compared to the C++ implementation of such sum.
1515

1616
import TestsUtils
17-
18-
#if SWIFT_PACKAGE
19-
// FIXME: Needs fix for https://github.com/apple/swift/issues/61547.
20-
21-
public let benchmarks = [BenchmarkInfo]()
22-
23-
#else
24-
2517
import CxxStdlibPerformance
2618
import Cxx
2719
import CxxStdlib // FIXME(rdar://128520766): this import should be redundant
@@ -127,4 +119,3 @@ public func run_CxxVectorOfU32_Sum_Swift_Reduce(_ n: Int) {
127119
}
128120
blackHole(sum)
129121
}
130-
#endif

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Build the toolchain with optimizations, debuginfo, and assertions, using Ninja:
264264
```sh
265265
utils/build-script --skip-build-benchmarks \
266266
--swift-darwin-supported-archs "$(uname -m)" \
267-
--sccache --release-debuginfo --swift-disable-dead-stripping \
267+
--release-debuginfo --swift-disable-dead-stripping \
268268
--bootstrapping=hosttools
269269
```
270270
- Linux:

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ Also similar to `@_silgen_name`, but a function declared with
465465
`@_extern(c)` is assumed to use the C ABI, while `@_silgen_name`
466466
assumes the Swift ABI.
467467

468+
It is always better to refer to C declarations by importing their
469+
native declarations from a header or module using Swift's C interop
470+
support when possible.
471+
468472
## `@_fixed_layout`
469473

470474
Same as `@frozen` but also works for classes.
@@ -1106,9 +1110,43 @@ Darwin) is maintained, unless "raw:" is used, in which case the name provided is
11061110
expected to already be mangled.
11071111

11081112
Since this has label-like behavior, it may not correspond to any declaration;
1109-
if so, it is assumed that the function/global is implemented in C.
1110-
1111-
A function defined by `@_silgen_name` is assumed to use the Swift ABI.
1113+
if so, it is assumed that the function/global is implemented possibly
1114+
in some other language; that implementation however is assumed to use
1115+
the Swift ABI as if it were defined in Swift.
1116+
1117+
There are very few legitimate uses for this attribute. There are many
1118+
ways to misuse it:
1119+
1120+
- Don't use `@_silgen_name` to access C functions, since those use the C ABI.
1121+
Import a header or C module to access C functions.
1122+
- Don't use `@_silgen_name` to export Swift functions to C/ObjC. `@_cdecl` or
1123+
`@objc` can do that.
1124+
- Don't use `@_silgen_name` to link to `swift_*` symbols from the Swift runtime.
1125+
Calls to these functions have special semantics to the compiler, and accessing
1126+
them directly will lead to unpredictable compiler crashes and undefined
1127+
behavior. Use language features, or if you must, the `Builtin` module, instead.
1128+
- Don't use `@_silgen_name` for dynamic linker discovery. Swift symbols cannot
1129+
be reliably recovered through C interfaces like `dlsym`. If you want to
1130+
implement a plugin-style interface, use `Bundle`/`NSBundle` if available, or
1131+
export your plugin entry points as C entry points using `@_cdecl`.
1132+
1133+
Legitimate uses may include:
1134+
1135+
- Use `@_silgen_name` if you're implementing the Swift runtime.
1136+
- Use `@_silgen_name` if you need to make a change to an ABI-stable
1137+
declaration's signature that would normally alter its mangled name, but you
1138+
need to preserve the old mangled name for ABI compatibility. You will need
1139+
to be careful that the change doesn't materially affect the actual calling
1140+
convention of the function in an incompatible way.
1141+
- Use `@_silgen_name` if certain declarations need to have predictable symbol
1142+
names, such as to be easily referenced by linker scripts or other highly
1143+
customized build environments (and it's OK for those predictable symbols to
1144+
reference functions with a Swift ABI).
1145+
- Use `@_silgen_name` to interface build products that must be linked
1146+
together but built completely separately, such that one can't import the other
1147+
normally. For this to work, the declaration(s) and definition must exactly
1148+
match, using the exact same definitions of any referenced types or other
1149+
declarations. The compiler can't help you if you mismatch.
11121150

11131151
For more details, see the
11141152
[Standard Library Programmer's Manual](https://github.com/swiftlang/swift/blob/main/docs/StandardLibraryProgrammersManual.md#_silgen_name).

include/swift/AST/ASTContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ class ASTContext final {
734734
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
735735
FuncDecl *getIsOSVersionAtLeastDecl() const;
736736

737+
// Retrieve the declaration of Swift._stdlib_isVariantOSVersionAtLeast.
738+
FuncDecl *getIsVariantOSVersionAtLeastDecl() const;
739+
740+
// Retrieve the declaration of
741+
// Swift._stdlib_isOSVersionAtLeastOrVariantVersionAtLeast.
742+
FuncDecl *getIsOSVersionAtLeastOrVariantVersionAtLeast() const;
743+
737744
/// Look for the declaration with the given name within the
738745
/// passed in module.
739746
void lookupInModule(ModuleDecl *M, StringRef name,

include/swift/AST/Attr.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,7 @@ class BackDeployedAttr : public DeclAttribute {
23162316
const llvm::VersionTuple Version;
23172317

23182318
/// Returns true if this attribute is active given the current platform.
2319-
bool isActivePlatform(const ASTContext &ctx) const;
2319+
bool isActivePlatform(const ASTContext &ctx, bool forTargetVariant) const;
23202320

23212321
static bool classof(const DeclAttribute *DA) {
23222322
return DA->getKind() == DeclAttrKind::BackDeployed;
@@ -2745,7 +2745,8 @@ class DeclAttributes {
27452745

27462746
/// Returns the `@backDeployed` attribute that is active for the current
27472747
/// platform.
2748-
const BackDeployedAttr *getBackDeployed(const ASTContext &ctx) const;
2748+
const BackDeployedAttr *getBackDeployed(const ASTContext &ctx,
2749+
bool forTargetVariant) const;
27492750

27502751
SWIFT_DEBUG_DUMPER(dump(const Decl *D = nullptr));
27512752
void print(ASTPrinter &Printer, const PrintOptions &Options,

include/swift/AST/Builtins.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,12 @@ BUILTIN_MISC_OPERATION(ResumeNonThrowingContinuationReturning,
786786
/// targetOSVersionAtLeast has type (Builtin.Int32, Builtin.Int32, Builtin.Int32) -> Builtin.Int32
787787
BUILTIN_MISC_OPERATION(TargetOSVersionAtLeast, "targetOSVersionAtLeast", "n", Special)
788788

789+
/// targetVariantOSVersionAtLeast has type (Builtin.Int32, Builtin.Int32, Builtin.Int32) -> Builtin.Int32
790+
BUILTIN_MISC_OPERATION(TargetVariantOSVersionAtLeast, "targetVariantOSVersionAtLeast", "n", Special)
791+
792+
/// targetOSVersionOrVariantOSVersionAtLeast has type (Builtin.UInt32, Builtin.UInt32, Builtin.UInt32, Builtin.UInt32, Builtin.UInt32, Builtin.UInt32) -> Builtin.UInt32
793+
BUILTIN_MISC_OPERATION(TargetOSVersionOrVariantOSVersionAtLeast, "targetOSVersionOrVariantOSVersionAtLeast", "n", Special)
794+
789795
/// Resume a throwing continuation normally with the given result.
790796
BUILTIN_MISC_OPERATION(ResumeThrowingContinuationReturning,
791797
"resumeThrowingContinuationReturning", "", Special)

0 commit comments

Comments
 (0)