Skip to content

Commit b8f3009

Browse files
committed
Add some comments explaining how the world works.
1 parent fb22777 commit b8f3009

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

ci/LDKSwift/Tests/LDKSwiftTests/HumanObjectPeerTestInstance.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public class HumanObjectPeerTestInstance {
303303

304304
let graph = NetworkGraph(network: .Regtest, logger: self.logger)
305305
var scorerGraph = graph
306-
if(master.configuration.ephemeralNetworkGraphForScorer) {
306+
if master.configuration.ephemeralNetworkGraphForScorer {
307307
scorerGraph = NetworkGraph(network: .Regtest, logger: self.logger)
308308
}
309309

ci/LDKSwift/Tests/LDKSwiftTests/LDKSwiftTests.swift

+4-20
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ class LDKSwiftTests: XCTestCase {
456456
print("Running test with flags \(i)");
457457

458458
let config = HumanObjectPeerTestInstance.Configuration()
459+
460+
// We have a set of configuration properties. We run through all possible
461+
// combinations, and set each individual property depending on whether
462+
// its bit is set.
459463

460464
config.shouldRecipientRejectPayment = (i & (1 << 0)) != 0
461465
print("shouldRecipientRejectPayment: \(config.shouldRecipientRejectPayment)")
@@ -469,26 +473,6 @@ class LDKSwiftTests: XCTestCase {
469473
config.ephemeralNetworkGraphForScorer = (i & (1 << 3)) != 0
470474
print("ephemeralNetworkGraphForScorer: \(config.ephemeralNetworkGraphForScorer)")
471475

472-
/*
473-
config.nice_close = (i & (1 << 0)) != 0;
474-
config.use_km_wrapper = (i & (1 << 1)) != 0;
475-
config.use_manual_watch = (i & (1 << 2)) != 0;
476-
config.reload_peers = (i & (1 << 3)) != 0;
477-
config.break_cross_peer_refs = (i & (1 << 4)) != 0;
478-
config.use_nio_peer_handler = true // (i & (1 << 5)) != 0;
479-
config.useChannelManagerConstructor = true // (i & (1 << 6)) != 0;
480-
481-
if (config.break_cross_peer_refs && !config.reload_peers) {
482-
// There are no cross refs to break without reloading peers.
483-
continue;
484-
}
485-
486-
if (config.useChannelManagerConstructor && (config.use_manual_watch || !config.use_nio_peer_handler)) {
487-
// ChannelManagerConstructor requires a ChainMonitor as the Watch and creates a NioPeerHandler for us.
488-
continue;
489-
}
490-
*/
491-
492476
let instance = HumanObjectPeerTestInstance(configuration: config)
493477
await instance.testMessageHandling()
494478
}

src/generation/base_type_generator.mts

+21-1
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ export abstract class BaseTypeGenerator<Type extends RustType> {
815815
}
816816
`;
817817

818+
/**
819+
* When an argument is an asterisk-based pointer, we usually simply create the
820+
* pointer-related handling like we do above, and nothing beyond that. However,
821+
* when the method taking that pointer is a constructor, it is likely that the
822+
* pointed-to argument will need to live well beyond the conclusion of the method
823+
* call. Specifically, it is likely a requirement of the instantiated object
824+
* that the argument is kept around for as long as necessary. We do that by
825+
* tethering the argument to the returned object. It's nothing but a reference
826+
* that will have Swift delay deallocation.
827+
*
828+
* If the reference is an elided type, such as an array, a nullable, or a tuple,
829+
* we, for the time being, just pretend that no anchoring is necessary. In reality,
830+
* we simply haven't encountered such a case yet, and until we do, it's a bit too
831+
* complicated to handle, because doing it blindly will probably only lead us to
832+
* introduce some new memory bugs.
833+
*/
818834
if(memoryContext && memoryContext.isConstructor && (argument.type instanceof RustStruct || argument.type instanceof RustTaggedValueEnum || argument.type instanceof RustResult)){
819835
preparedArgument.requiresAnchoring = true;
820836
}
@@ -1298,7 +1314,11 @@ export interface PreparedArgument {
12981314
deferredCleanup: string
12991315

13001316
/**
1301-
* If true (only applicable in constructors), add a `self.addAnchor` call after super.init()
1317+
* If true (only applicable in constructors), add a `self.addAnchor` call after super.init().
1318+
* For anchoring that doesn't immediately succeed object instantiation, or that can happen
1319+
* outside the initializer method, we have other mechanisms. This particular mechanism is,
1320+
* strictly speaking, somewhat of a workaround, but one that is necessary due to Swift's
1321+
* constraints surrounding when calls to `self` can be made.
13021322
*/
13031323
requiresAnchoring: boolean
13041324
}

0 commit comments

Comments
 (0)