Skip to content

Commit 911b7c9

Browse files
authored
Add SwiftCorelibsCoreFoundation, Utilities targets and UtilitiesTests (#203)
1 parent af45d6a commit 911b7c9

37 files changed

Lines changed: 4663 additions & 94 deletions

‎CREDITS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project uses third-party libraries and code. Their licenses and acknowledge
77
## Compute
88

99
OpenAttributeGraphCxx's Data, Graph, Vector and more is modified based on [Compute](https://github.com/jcmosc/Compute)'s implementations.
10+
Platform, SwiftCorelibsCoreFoundation and Utilities are also modified based on Compute's implementations.
1011

1112
Compute is licensed as follows:
1213

‎Package.resolved‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,17 @@ let attributeGraphCondition = envBoolValue("ATTRIBUTEGRAPH", default: buildForDa
163163
var sharedCSettings: [CSetting] = [
164164
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
165165
.define("NDEBUG", .when(configuration: .release)),
166+
// Rewrite malloc() to malloc_type_malloc() for type-isolated allocation buckets (xzone malloc).
167+
.unsafeFlags(["-ftyped-memory-operations"], .when(platforms: .darwinPlatforms)),
166168
]
167169

168170
var sharedCxxSettings: [CXXSetting] = [
169171
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
170172
.define("NDEBUG", .when(configuration: .release)),
173+
// Rewrite malloc() to malloc_type_malloc() for type-isolated allocation buckets (xzone malloc).
174+
.unsafeFlags(["-ftyped-memory-operations"], .when(platforms: .darwinPlatforms)),
175+
// Rewrite operator new/delete to typed variants (operator new(size_t, std::__type_descriptor_t)).
176+
.unsafeFlags(["-ftyped-cxx-new-delete"], .when(platforms: .darwinPlatforms)),
171177
]
172178

173179
var sharedSwiftSettings: [SwiftSetting] = [
@@ -226,6 +232,9 @@ extension Target {
226232
}
227233

228234
extension [Platform] {
235+
static var darwinPlatforms: [Platform] {
236+
[.macOS, .iOS, .tvOS, .watchOS, .visionOS, .macCatalyst]
237+
}
229238
static var nonDarwinPlatforms: [Platform] {
230239
[.linux, .android, .wasi, .openbsd, .windows]
231240
}
@@ -242,16 +251,30 @@ let swiftClonePlugin = Target.plugin(
242251

243252
let platformTarget = Target.target(
244253
name: "Platform",
245-
cSettings: [
254+
cSettings: sharedCSettings + [
246255
.define("_GNU_SOURCE", .when(platforms: [.linux])),
247256
]
248257
)
258+
let swiftCorelibsCoreFoundationTarget = Target.target(
259+
name: "SwiftCorelibsCoreFoundation"
260+
)
261+
let utilitiesTarget = Target.target(
262+
name: "Utilities",
263+
dependencies: [
264+
.target(name: platformTarget.name),
265+
.target(name: swiftCorelibsCoreFoundationTarget.name, condition: .when(platforms: .nonDarwinPlatforms)),
266+
],
267+
cxxSettings: sharedCxxSettings
268+
)
249269
// FIXME: Merge into one target
250270
// OpenAttributeGraph is a C++ & Swift mix target.
251271
// The SwiftPM support for such usage is still in progress.
252272
let openAttributeGraphCxxTarget = Target.target(
253273
name: "OpenAttributeGraphCxx",
254-
dependencies: [.target(name: platformTarget.name)],
274+
dependencies: [
275+
.target(name: platformTarget.name),
276+
.target(name: utilitiesTarget.name),
277+
],
255278
cSettings: sharedCSettings + [
256279
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
257280
],
@@ -279,6 +302,14 @@ let openAttributeGraphShimsTarget = Target.target(
279302

280303
// MARK: - Test Targets
281304

305+
let utilitiesTestsTarget = Target.testTarget(
306+
name: "UtilitiesTests",
307+
dependencies: [
308+
.target(name: utilitiesTarget.name),
309+
],
310+
cxxSettings: [.define("SWIFT_TESTING")],
311+
swiftSettings: [.interoperabilityMode(.Cxx)]
312+
)
282313
let openAttributeGraphCxxTestsTarget = Target.testTarget(
283314
name: "OpenAttributeGraphCxxTests",
284315
dependencies: [
@@ -324,6 +355,8 @@ let package = Package(
324355
targets: [
325356
swiftClonePlugin,
326357
platformTarget,
358+
swiftCorelibsCoreFoundationTarget,
359+
utilitiesTarget,
327360
openAttributeGraphTarget,
328361
openAttributeGraphCxxTarget,
329362
openAttributeGraphShimsTarget,
@@ -335,6 +368,7 @@ if compatibilityTestCondition {
335368
openAttributeGraphCompatibilityTestsTarget.addAGSettings()
336369
} else {
337370
package.targets += [
371+
utilitiesTestsTarget,
338372
openAttributeGraphCxxTestsTarget,
339373
openAttributeGraphShimsTestsTarget,
340374
]

‎Sources/OpenAttributeGraphCxx/Data/table.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//
55
// Audited for 6.5.1
66
// Status: WIP
7-
// Modified based Compute code
87

98
#include <OpenAttributeGraphCxx/Data/table.hpp>
109
#include <OpenAttributeGraphCxx/Data/page.hpp>

‎Sources/OpenAttributeGraphCxx/Runtime/OAGTupleType.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,7 @@ void OAGTupleWithBuffer(OAGTupleType tuple_type, size_t count, const void (* fun
208208
// So we need to call function in this scope.
209209
function(tuple, context);
210210
} else {
211-
#if OAG_TARGET_OS_DARWIN
212-
void *buffer = malloc_type_malloc(buffer_size, 0x100004077774924);
213-
#else
214-
// FIXME
215211
void *buffer = malloc(buffer_size);
216-
#endif
217212
if (buffer == nullptr) {
218213
OAG::precondition_failure("memory allocation failure");
219214
}

‎Sources/OpenAttributeGraphCxx/include/OpenAttributeGraphCxx/Data/ptr.hpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// OpenAttributeGraphCxx
44
//
55
// Status: Complete
6-
// Modified based Compute code
76

87
#ifndef ptr_hpp
98
#define ptr_hpp

‎Sources/OpenAttributeGraphCxx/include/module.private.modulemap‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ module OpenAttributeGraphCxx_Private.Runtime {
4444
export *
4545
}
4646

47-
module OpenAttributeGraphCxx_Private.Util {
48-
requires cplusplus
49-
umbrella "OpenAttributeGraphCxx/Util"
50-
export *
51-
module * { export * }
52-
}
53-
5447
module OpenAttributeGraphCxx_Private.Vector {
5548
requires cplusplus
5649
umbrella "OpenAttributeGraphCxx/Vector"

‎Sources/Platform/LICENSE‎

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#if __APPLE__
4+
#include <malloc/malloc.h>
5+
#else
6+
7+
#include <malloc.h>
8+
9+
typedef int malloc_zone_t;
10+
11+
#define malloc_zone_malloc(zone,size) malloc(size)
12+
#define malloc_zone_memalign(zone,align,size) malloc(size)
13+
#define malloc_zone_calloc(zone,count,size) calloc(count,size)
14+
#define malloc_zone_realloc(zone,ptr,size) realloc(ptr,size)
15+
#define malloc_zone_free(zone,ptr) free(ptr)
16+
17+
#define malloc_size(ptr) malloc_usable_size(ptr)
18+
#define malloc_good_size(size) (size)
19+
20+
#define malloc_create_zone(a,b) ((malloc_zone_t *)NULL)
21+
#define malloc_destroy_zone(zone)
22+
#define malloc_set_zone_name(zone,name)
23+
24+
#endif

‎Sources/Platform/include/platform/platform.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
#include <platform/base.h>
44
#include <platform/log.h>
5+
#include <platform/malloc.h>

0 commit comments

Comments
 (0)