Skip to content

Commit 689ddaa

Browse files
authored
Merge pull request #14069 from dcci/lifetime-di
2 parents f3c691f + bf6fc3e commit 689ddaa

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
24362436
auto &Availability = CDElt.Availability;
24372437

24382438
B.setInsertionPoint(Release);
2439+
B.setCurrentDebugScope(Release->getDebugScope());
24392440

24402441
// Value types and root classes don't require any fancy handling.
24412442
// Just conditionally destroy each memory element, and for classes,
@@ -2507,10 +2508,12 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
25072508

25082509
// If true, self.init or super.init was called and self was consumed.
25092510
B.setInsertionPoint(ConsumedBlock->begin());
2511+
B.setCurrentDebugScope(ConsumedBlock->begin()->getDebugScope());
25102512
processUninitializedRelease(Release, true, B.getInsertionPoint());
25112513

25122514
// If false, self is uninitialized and must be freed.
25132515
B.setInsertionPoint(DeallocBlock->begin());
2516+
B.setCurrentDebugScope(DeallocBlock->begin()->getDebugScope());
25142517
destroyMemoryElements(Loc, Availability);
25152518
processUninitializedRelease(Release, false, B.getInsertionPoint());
25162519

@@ -2541,11 +2544,13 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
25412544

25422545
// If true, self was consumed or is fully initialized.
25432546
B.setInsertionPoint(LiveBlock->begin());
2547+
B.setCurrentDebugScope(LiveBlock->begin()->getDebugScope());
25442548
emitReleaseOfSelfWhenNotConsumed(Loc, Release);
25452549
isDeadRelease = false;
25462550

25472551
// If false, self is uninitialized and must be freed.
25482552
B.setInsertionPoint(DeallocBlock->begin());
2553+
B.setCurrentDebugScope(DeallocBlock->begin()->getDebugScope());
25492554
destroyMemoryElements(Loc, Availability);
25502555
processUninitializedRelease(Release, false, B.getInsertionPoint());
25512556

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-swift-frontend -emit-sil %s -Onone -Xllvm \
2+
// RUN: -sil-print-after=definite-init -Xllvm \
3+
// RUN: -sil-print-only-functions=$S2fs36RecursibleDirectoryContentsGeneratorC4path10fileSystemAcA12AbsolutePathV_AA04FileH0_ptKc33_F8B132991B28208F48606E87DC165393Llfc \
4+
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
5+
6+
// REQUIRES: objc_interop
7+
8+
9+
// CHECK: %49 = ref_element_addr %48 : $RecursibleDirectoryContentsGenerator, #RecursibleDirectoryContentsGenerator.fileSystem, loc {{.*}}:38:5, scope 2
10+
// CHECK: destroy_addr %49 : $*FileSystem, loc {{.*}}:38:5, scope 2
11+
12+
13+
import Foundation
14+
15+
public struct AbsolutePath {
16+
public init(_ absStr: String) {}
17+
}
18+
19+
public protocol FileSystem: class {
20+
func getDirectoryContents(_ path: AbsolutePath) throws -> [String]
21+
}
22+
public extension FileSystem {
23+
}
24+
25+
public var currentWorkingDirectory: AbsolutePath {
26+
let cwdStr = FileManager.default.currentDirectoryPath
27+
return AbsolutePath(cwdStr)
28+
}
29+
public class RecursibleDirectoryContentsGenerator {
30+
private var current: (path: AbsolutePath, iterator: IndexingIterator<[String]>)
31+
private let fileSystem: FileSystem
32+
fileprivate init(
33+
path: AbsolutePath,
34+
fileSystem: FileSystem
35+
) throws {
36+
self.fileSystem = fileSystem
37+
current = (path, try fileSystem.getDirectoryContents(path).makeIterator())
38+
}
39+
}

0 commit comments

Comments
 (0)