Skip to content
Merged
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
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"features": {
"ghcr.io/devcontainers-extra/features/apt-get-packages:1": {
"version": "1.0.8",
"resolved": "ghcr.io/devcontainers-extra/features/apt-get-packages@sha256:776fa11c30c50fa91d5e1bf050444b0f130827457109c349db92e8e126b750ec",
"integrity": "sha256:776fa11c30c50fa91d5e1bf050444b0f130827457109c349db92e8e126b750ec"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"version": "2.5.9",
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a",
"integrity": "sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "1.3.5",
"resolved": "ghcr.io/devcontainers/features/git@sha256:27905dc196c01f77d6ba8709cb82eeaf330b3b108772e2f02d1cd0d826de1251",
"integrity": "sha256:27905dc196c01f77d6ba8709cb82eeaf330b3b108772e2f02d1cd0d826de1251"
}
}
}
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Swift",
"image": "swift:6.3",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
"username": "vscode",
"upgradePackages": "false"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "os-provided",
"ppa": "false"
},
"ghcr.io/devcontainers-extra/features/apt-get-packages:1": {
"packages": "libssl-dev"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"swift.path": "/usr/bin",
"lldb.library": "/usr/lib/liblldb.so"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"swiftlang.swift-vscode"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
2 changes: 2 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ jobs:
submodules: true
- name: Build
run: swift build
- name: Test
run: swift test
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ let package = Package(
// When -enable-library-evolution is specified verify-emitted-module-interface command fails
"-no-verify-emitted-module-interface",
]),
],
linkerSettings: [
.linkedLibrary("crypto", .when(platforms: [.linux]))
]
),
.testTarget(
Expand Down
38 changes: 38 additions & 0 deletions Sources/ComputeCxx/Graph/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2081,4 +2081,42 @@ const char *Graph::key_name(uint32_t key_id) const {
IAG::precondition_failure("invalid string key id: %u", key_id);
}

#pragma mark - Printing

#if !TARGET_OS_MAC
namespace {

int cycle_verbosity() {
const char *print_cycles = getenv("IAG_PRINT_CYCLES");
if (print_cycles) {
return atoi(print_cycles);
}
return 1;
}

int trap_cycles() {
const char *trap_cycles = getenv("IAG_TRAP_CYCLES");
if (trap_cycles) {
return atoi(trap_cycles) != 0;
}
return false;
}

} // namespace

void Graph::print_cycle(data::ptr<Node> node) {
foreach_trace([&node](Trace &trace) { trace.log_message("cycle detected through attribute: %u", node); });

static int verbosity = cycle_verbosity();
if (verbosity >= 1) {
fprintf(stdout, "=== AttributeGraph: cycle detected through attribute %u ===\n", node.offset());
}

static bool traps = trap_cycles();
if (traps) {
precondition_failure("cyclic graph: %u", node);
}
}
#endif

} // namespace IAG
2 changes: 1 addition & 1 deletion Sources/ComputeCxx/Swift/ContextDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ uint64_t class_type_descriptor::immediate_members_offset() const {
uint64_t class_type_descriptor::field_offset_vector_offset() const {
// FieldOffsetVectorOffset is a private field,
// but we know comes directly after Numfields which is a uint32_t
uint32_t offset = *(&_base.NumFields + sizeof(uint32_t));
uint32_t offset = *(reinterpret_cast<const char *>(&_base.NumFields) + sizeof(uint32_t));

if (base()->hasResilientSuperclass()) {
return immediate_members_offset() + offset;
Expand Down
27 changes: 9 additions & 18 deletions Sources/ComputeCxx/Swift/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,15 @@ bool metadata::visit_heap_class(metadata_visitor &visitor) const {
}

if ((class_type->Flags & ::swift::ClassFlags::UsesSwiftRefcounting) == 0) {
size_t *ivar_offsets = nullptr; // TODO: use new
ptrdiff_t *ivar_offsets = nullptr;

#if SWIFT_OBJC_INTEROP
unsigned int ivar_count;
Ivar *ivar_list = class_copyIvarList(reinterpret_cast<const Class>((void *)this), &ivar_count);
if (ivar_list) {
if (ivar_count == fields->NumFields) {
ivar_offsets = (size_t *)calloc(ivar_count, sizeof(size_t)); // or bzero?
ivar_offsets = (ptrdiff_t *)alloca(sizeof(ptrdiff_t) * ivar_count);
memset(ivar_offsets, 0, sizeof(ptrdiff_t) * ivar_count);
for (unsigned int ivar_index = 0; ivar_index < ivar_count; ++ivar_index) {
ivar_offsets[ivar_index] = ivar_getOffset(ivar_list[ivar_index]);
}
Expand All @@ -689,37 +690,27 @@ bool metadata::visit_heap_class(metadata_visitor &visitor) const {
if (ivar_offsets && *ivar_offsets != 0) {
unsigned index = 0;
for (auto &field : fields->getFields()) {
size_t offset = ivar_offsets[index];
size_t end_offset = index + 1 < fields->NumFields ? ivar_offsets[index + 1] : -1;
ptrdiff_t offset = ivar_offsets[index];
ptrdiff_t end_offset = index + 1 < fields->NumFields ? ivar_offsets[index + 1] : vw_size();
size_t field_size = offset <= end_offset ? end_offset - offset : -1;
if (!visitor.visit_field(*this, field, offset, field_size)) {
if (ivar_offsets) {
free(ivar_offsets);
}
return false;
}
index += 1;
}
if (ivar_offsets) {
free(ivar_offsets);
}
return true;
}

if (ivar_offsets) {
free(ivar_offsets);
}
return visitor.unknown_result();
} else {
if (class_context->hasFieldOffsetVector()) {
auto offset = reinterpret_cast<const class_type_descriptor *>(class_context)->field_offset_vector_offset();
auto asWords = *reinterpret_cast<const size_t *const *>(this);
const size_t *field_offsets = reinterpret_cast<const size_t *>(asWords + offset);
auto asWords = reinterpret_cast<const void *const *>(this);
const ptrdiff_t *field_offsets = reinterpret_cast<const ptrdiff_t *>(asWords + offset);

unsigned index = 0;
for (auto &field : class_context->Fields->getFields()) {
size_t field_offset = field_offsets[index];
size_t end_offset = index + 1 < class_context->NumFields ? field_offsets[index + 1] : vw_size();
ptrdiff_t field_offset = field_offsets[index];
ptrdiff_t end_offset = index + 1 < class_context->NumFields ? field_offsets[index + 1] : vw_size();
size_t field_size = field_offset <= end_offset ? end_offset - field_offset : -1;
if (!visitor.visit_field(*this, field, field_offset, field_size)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import Testing

/// A type that can be equal without being bitwise identical.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Foundation
import Testing

// This suite relies heavily on process isolation, which does not complete on Linux.
#if !os(Linux)

public struct ValueLayout: CustomStringConvertible, Equatable {

let storage: UnsafePointer<CUnsignedChar>
Expand Down Expand Up @@ -1946,3 +1950,5 @@ struct PrefetchCompareValuesTests {
}

}

#endif
18 changes: 18 additions & 0 deletions Tests/ComputeSwiftTests/Shared/ArrayBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@resultBuilder
struct ArrayBuilder<Element> {
static func buildPartialBlock(first: Element) -> [Element] {
[first]
}

static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] {
var result = accumulated
result.append(next)
return result
}
}

extension Array {
init(@ArrayBuilder<Element> build: () -> [Element]) {
self = build()
}
}
Loading