Skip to content

Commit 083fdaa

Browse files
authored
Merge pull request #73998 from nickolas-pohilets/mpokhylets/fix-32-build
2 parents f4b4db6 + 987b641 commit 083fdaa

File tree

18 files changed

+1006
-983
lines changed

18 files changed

+1006
-983
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(SWIFT_BENCH_MODULES
4040
single-source/ArrayRemoveAll
4141
single-source/ArraySetElement
4242
single-source/ArraySubscript
43+
single-source/AsyncTree
4344
single-source/BinaryFloatingPointConversionFromBinaryInteger
4445
single-source/BinaryFloatingPointProperties
4546
single-source/BitCount
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===--- AsyncTree.swift -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
import Dispatch
15+
16+
public var benchmarks: [BenchmarkInfo] {
17+
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) else {
18+
return []
19+
}
20+
return [
21+
BenchmarkInfo(
22+
name: "AsyncTree.100",
23+
runFunction: run_AsyncTree(treeSize: 100),
24+
tags: [.concurrency]
25+
),
26+
BenchmarkInfo(
27+
name: "AsyncTree.5000",
28+
runFunction: run_AsyncTree(treeSize: 5000),
29+
tags: [.concurrency]
30+
)
31+
]
32+
}
33+
34+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
35+
private actor MyActor {
36+
let g: DispatchGroup
37+
38+
init(_ g: DispatchGroup) {
39+
self.g = g
40+
}
41+
42+
func test(_ n: Int) {
43+
let L = n / 2
44+
let R = n - 1 - L
45+
46+
if L > 0 {
47+
Task {
48+
self.test(L)
49+
}
50+
}
51+
52+
if R > 0 {
53+
Task {
54+
self.test(R)
55+
}
56+
}
57+
58+
g.leave()
59+
}
60+
}
61+
62+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
63+
private func run_AsyncTree(treeSize: Int) -> (Int) -> Void {
64+
return { n in
65+
for _ in 0..<n {
66+
let g = DispatchGroup()
67+
for _ in 0..<treeSize {
68+
g.enter()
69+
}
70+
let actor = MyActor(g)
71+
Task {
72+
await actor.test(treeSize)
73+
}
74+
g.wait()
75+
}
76+
}
77+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ArrayOfRef
2828
import ArrayRemoveAll
2929
import ArraySetElement
3030
import ArraySubscript
31+
import AsyncTree
3132
import BinaryFloatingPointConversionFromBinaryInteger
3233
import BinaryFloatingPointProperties
3334
import BitCount
@@ -223,6 +224,7 @@ register(ArrayOfRef.benchmarks)
223224
register(ArrayRemoveAll.benchmarks)
224225
register(ArraySetElement.benchmarks)
225226
register(ArraySubscript.benchmarks)
227+
register(AsyncTree.benchmarks)
226228
register(BinaryFloatingPointConversionFromBinaryInteger.benchmarks)
227229
register(BinaryFloatingPointProperties.benchmarks)
228230
register(BitCount.benchmarks)

include/swift/ABI/MetadataValues.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,32 @@ inline int descendingPriorityOrder(JobPriority lhs,
25112511
return (lhs == rhs ? 0 : lhs > rhs ? -1 : 1);
25122512
}
25132513

2514+
enum { PriorityBucketCount = 5 };
2515+
2516+
inline int getPriorityBucketIndex(JobPriority priority) {
2517+
// Any unknown priorities will be rounded up to a known one.
2518+
// Priorities higher than UserInteractive are clamped to UserInteractive.
2519+
// Jobs of unknown priorities will end up in the same bucket as jobs of a
2520+
// corresponding known priority. Within the bucket they will be sorted in
2521+
// FIFO order.
2522+
if (priority > JobPriority::UserInitiated) {
2523+
// UserInteractive and higher
2524+
return 0;
2525+
} else if (priority > JobPriority::Default) {
2526+
// UserInitiated
2527+
return 1;
2528+
} else if (priority > JobPriority::Utility) {
2529+
// Default
2530+
return 2;
2531+
} else if (priority > JobPriority::Background) {
2532+
// Utility
2533+
return 3;
2534+
} else {
2535+
// Background and lower
2536+
return 4;
2537+
}
2538+
}
2539+
25142540
inline JobPriority withUserInteractivePriorityDowngrade(JobPriority priority) {
25152541
return (priority == JobPriority::UserInteractive) ? JobPriority::UserInitiated
25162542
: priority;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===--- HeaderFooterLayout.h -----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
14+
#define SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
15+
16+
#include <cstddef>
17+
18+
namespace swift {
19+
20+
template <class T>
21+
class size_without_trailing_padding {
22+
struct ExtraByte { char _size_without_trailing_padding_probe; };
23+
struct Probe: T, ExtraByte {};
24+
public:
25+
enum { value = offsetof(Probe, _size_without_trailing_padding_probe) };
26+
};
27+
28+
namespace detail {
29+
30+
template <ptrdiff_t size>
31+
struct LayoutPadding {
32+
char padding[size];
33+
};
34+
template <>
35+
struct LayoutPadding<0> {};
36+
37+
template <class Header, class Footer, size_t TotalSize>
38+
struct HeaderFooterLayoutPaddingSize {
39+
enum : ptrdiff_t {
40+
maxFooterOffset = TotalSize - (ptrdiff_t)size_without_trailing_padding<Footer>::value,
41+
footerAlignment = (ptrdiff_t)alignof(Footer),
42+
footerOffset = maxFooterOffset - (maxFooterOffset % footerAlignment),
43+
value = footerOffset - (ptrdiff_t)size_without_trailing_padding<Header>::value
44+
};
45+
};
46+
47+
} // namespace detail
48+
49+
template <class Header, class Footer, size_t TotalSize>
50+
struct HeaderFooterLayout
51+
: Header,
52+
detail::LayoutPadding<detail::HeaderFooterLayoutPaddingSize<
53+
Header, Footer, TotalSize>::value>,
54+
Footer {};
55+
56+
} // namespace swift
57+
58+
#endif // SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
59+

0 commit comments

Comments
 (0)