Skip to content

Commit aa64816

Browse files
Merge branch 'main' into inline-array
2 parents ed5b3ca + 077a01f commit aa64816

File tree

227 files changed

+5421
-1557
lines changed

Some content is hidden

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

227 files changed

+5421
-1557
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
/unittests/AST/ @hborla @slavapestov @xedin
270270
/unittests/AST/*Evaluator* @CodaFi @slavapestov
271271
/unittests/DependencyScan/ @artemcm @cachemeifyoucan
272-
/unittests/FrontendTool/ @artemcm @tshortli
272+
/unittests/Frontend*/ @artemcm @tshortli
273273
/unittests/Parse/ @ahoppen @bnbarham @CodaFi @DougGregor @hamishknight @rintaro
274274
/unittests/Reflection/ @slavapestov
275275
/unittests/SIL/ @jckarter

Runtimes/Core/cmake/modules/CompilerSettings.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ if(NOT HAVE_SWIFT_ASYNC_CALL)
4949
endif()
5050

5151
check_compiler_flag(CXX "-mcx16" HAVE_CXX_MCX16)
52-
if(HAVE_CXX_MCX16)
52+
if(HAVE_CXX_MCX16 AND
53+
(CMAKE_CXX_COMPILER_ARCHITECTURE_ID MATCHES "(X86)|(X64)" OR
54+
CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86)|(x86_64)|(amd64)|(AMD64)"))
5355
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-mcx16>)
5456
endif()

Runtimes/Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Once the migration is completed, we will be deleting this script. It
2020
is a temporary workaround to avoid trying to keep multiple sets of files in
2121
sync.
2222

23+
> [!NOTE]
24+
> This script does not add new files to any CMakeLists.txt. Any new files
25+
> that are copied over will need to be added manually to ensure that
26+
> they will be built by CMake.
27+
2328
## Layering
2429

2530
```

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
5353
self.inExclusiveRange.insert(beginInst)
5454
}
5555

56+
// Note: 'ends' are simply the instructions to insert in the range. 'self.ends' might not return the same sequence
57+
// as this 'ends' argument because 'self.ends' will not include block exits.
5658
init<S: Sequence>(begin beginInst: Instruction, ends: S, _ context: some Context) where S.Element: Instruction {
5759
self = InstructionRange(begin: beginInst, context)
5860
insert(contentsOf: ends)

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CopyToBorrowOptimization.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ private struct Uses {
124124
// E.g. the none-case of a switch_enum of an Optional.
125125
private(set) var nonDestroyingLiverangeExits: Stack<Instruction>
126126

127-
var allLifetimeEndingInstructions: [Instruction] {
128-
Array(destroys.lazy.map { $0 }) + Array(nonDestroyingLiverangeExits)
129-
}
130-
131127
private(set) var usersInDeadEndBlocks: Stack<Instruction>
132128

133129
init(_ context: FunctionPassContext) {
@@ -323,7 +319,16 @@ private func createEndBorrows(for beginBorrow: Value, atEndOf liverange: Instruc
323319
// destroy_value %2
324320
// destroy_value %3 // The final destroy. Here we need to create the `end_borrow`(s)
325321
//
326-
for endInst in collectedUses.allLifetimeEndingInstructions {
322+
323+
var allLifetimeEndingInstructions = InstructionWorklist(context)
324+
allLifetimeEndingInstructions.pushIfNotVisited(contentsOf: collectedUses.destroys.lazy.map { $0 })
325+
allLifetimeEndingInstructions.pushIfNotVisited(contentsOf: collectedUses.nonDestroyingLiverangeExits)
326+
327+
defer {
328+
allLifetimeEndingInstructions.deinitialize()
329+
}
330+
331+
while let endInst = allLifetimeEndingInstructions.pop() {
327332
if !liverange.contains(endInst) {
328333
let builder = Builder(before: endInst, context)
329334
builder.createEndBorrow(of: beginBorrow)

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 101 additions & 65 deletions
Large diffs are not rendered by default.

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ extension LifetimeDependence.Scope {
350350
self = .initialized(.yield(result))
351351
return
352352
}
353+
// @inout arguments belong to the coroutine because they are valid for the duration of the yield, and, if local
354+
// mutation or reassignment were relevant, then the dependence would be on an access scope instead.
353355
self = .yield(result)
354356
}
355357
}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation
13331333
/// scope ending instruction such as `begin_access` (ending with `end_access`) and `begin_borrow` (ending with
13341334
/// `end_borrow`).
13351335
public protocol ScopedInstruction {
1336+
var instruction: Instruction { get }
1337+
13361338
var endOperands: LazyFilterSequence<UseList> { get }
13371339

13381340
var endInstructions: EndInstructions { get }
@@ -1349,7 +1351,12 @@ extension Instruction {
13491351
}
13501352

13511353
/// Instructions beginning a borrow-scope which must be ended by `end_borrow`.
1352-
public protocol BorrowIntroducingInstruction : SingleValueInstruction, ScopedInstruction {}
1354+
public protocol BorrowIntroducingInstruction : SingleValueInstruction, ScopedInstruction {
1355+
}
1356+
1357+
extension BorrowIntroducingInstruction {
1358+
public var instruction: Instruction { get { self } }
1359+
}
13531360

13541361
final public class EndBorrowInst : Instruction, UnaryInstruction {
13551362
public var borrow: Value { operand.value }
@@ -1428,6 +1435,8 @@ final public class EndAccessInst : Instruction, UnaryInstruction {
14281435
}
14291436

14301437
extension BeginAccessInst : ScopedInstruction {
1438+
public var instruction: Instruction { get { self } }
1439+
14311440
public var endOperands: LazyFilterSequence<UseList> {
14321441
return uses.lazy.filter { $0.instruction is EndAccessInst }
14331442
}
@@ -1462,6 +1471,8 @@ final public class AbortApplyInst : Instruction, UnaryInstruction {
14621471
}
14631472

14641473
extension BeginApplyInst : ScopedInstruction {
1474+
public var instruction: Instruction { get { self } }
1475+
14651476
public var endOperands: LazyFilterSequence<UseList> {
14661477
return token.uses.lazy.filter { $0.isScopeEndingUse }
14671478
}

docs/DebuggingTheCompiler.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ passing the flag `-Xfrontend -debug-constraints`:
219219
$ swift repl -Xfrontend -debug-constraints
220220
1> let foo = 1
221221

222+
### Debugging Evaluator Cycles
223+
224+
When triggering code in the type checker, one can by mistake cause a cycle in
225+
the request evaluator. The error looks as follows:
226+
227+
```
228+
<unknown>:0: error: circular reference
229+
file.swift:18:22: note: through reference here
230+
16 |
231+
17 | extension MyType {
232+
18 | public static func test() -> MyType { ... }
233+
| `- note: through reference here
234+
19 | }
235+
20 |
236+
```
237+
238+
To determine the actual circular request that is occuring, one can pass in the
239+
flag `-debug-cycles` to the compiler which will cause the compiler to dump out
240+
the linear chain of requests that led to the cycle.
241+
222242
## Debugging on SIL Level
223243

224244
### Options for Dumping the SIL

include/swift/ABI/GenericContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,14 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
711711
getGenericValueDescriptors().data()};
712712
}
713713

714+
static size_t trailingTypeCount() {
715+
return TrailingObjects::trailingTypeCount();
716+
}
717+
718+
size_t sizeWithTrailingTypeCount(size_t n) const {
719+
return TrailingObjects::sizeWithTrailingTypeCount(n);
720+
}
721+
714722
protected:
715723
size_t numTrailingObjects(OverloadToken<GenericContextHeaderType>) const {
716724
return asSelf()->isGeneric() ? 1 : 0;

0 commit comments

Comments
 (0)