Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/ComputeCxx/Vector/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class vector {
using size_type = _size_type;

private:
T _inline_buffer[_inline_capacity];
// Elements are constructed and destroyed explicitly. After relocation to
// the heap, the inline storage must not destroy the old element copies.
union {
T _inline_buffer[_inline_capacity];
};
T *_Nullable _buffer = nullptr;
size_type _size = 0;
size_type _capacity = _inline_capacity;
Expand Down
43 changes: 43 additions & 0 deletions Tests/ComputeTests/Shared/Subgraph/SubgraphUpdateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@ import Testing

@Suite
struct SubgraphUpdateTests {
@Test
func updatePreservesChildrenBeyondInlineCapacity() async {
await #expect(processExitsWith: .success) {
struct CountingRule: StatefulRule {
typealias Value = Int
var count = 0

mutating func updateValue() {
count += 1
value = count
}
}

withGraph {
let parent = Subgraph.current!
let flags = Subgraph.Flags(rawValue: 1)
let children = (0..<64).map { _ in Subgraph(graph: parent.graph) }
let attributes = children.map { child in
parent.addChild(child)
return child.apply {
let attribute = Attribute(CountingRule())
attribute.flags = flags
return attribute
}
}

for expectedValue in 1...3 {
for attribute in attributes {
attribute.invalidateValue()
}
parent.update(flags: flags)
for child in children {
precondition(child.isValid)
}
for attribute in attributes {
precondition(attribute.value == expectedValue)
}
}
withExtendedLifetime(children) {}
}
}
}

@Test
func updateIterativelyEvaluatesDirtiedAttributesDuringTheSamePass() {
class Counter {
Expand Down
Loading