Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce initial Swift support in fdbserver #10156

Merged
merged 342 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
342 commits
Select commit Hold shift + click to select a range
c1b86fa
[fdbserver] workaround the FRT type layout issue to get Swfit getVers…
hyp Oct 11, 2022
74608e1
MasterData.actor.h: fix comment typo
hyp Oct 11, 2022
c73626a
masterserver.swift: some tweaks
hyp Oct 11, 2022
c336f8f
masterserver.swift: remove getVersion function, use the method
hyp Oct 11, 2022
d7dff08
masterserver.swift: print replied version to output for tracing
hyp Oct 11, 2022
7b9e6d6
Merge pull request #1 from FoundationDB/eng/getVersion
ktoso Oct 11, 2022
a4f2150
[swift] add radar links for C++ interop issues found in getVersion br…
hyp Oct 12, 2022
5399767
Merge pull request #3 from FoundationDB/eng/rlinks
hyp Oct 12, 2022
eb548f6
Update fdbserver.actor.cpp
ktoso Oct 14, 2022
70c8078
Migrate MasterData closer to full reference type
hyp Oct 18, 2022
3d6fa2b
[interop] require a new toolchain (>= Oct 19th) to build
hyp Oct 19, 2022
50facac
Merge pull request #6 from FoundationDB/eng/master-data-frt-again
hyp Oct 19, 2022
5ccec62
[Swift] fix computation of toAdd for getVersion Swift implementation
hyp Oct 19, 2022
a85978f
Merge pull request #7 from FoundationDB/eng/toAddfix
hyp Oct 19, 2022
053e01b
add Swift to FDBClient and add async `atLeast` to NotifiedVersion
ktoso Oct 21, 2022
85acaee
fix
ktoso Oct 21, 2022
1951a43
use new atLeast API in master server
ktoso Oct 21, 2022
e92b1eb
=build fixup link dependencies in swift fdbclient
ktoso Oct 24, 2022
e96c9ca
Merge pull request #10 from FoundationDB/wip-async-atLeast
ktoso Oct 24, 2022
48a97ed
clocks
ktoso Oct 24, 2022
e2fca29
+clock implement Clock using Flow's notion of time
ktoso Oct 24, 2022
50bc85c
Merge pull request #11 from ktoso/wip-clocks-2
ktoso Oct 25, 2022
f848de9
[interop] workaround the immortal retain/release issue
hyp Oct 25, 2022
8e991d3
Merge pull request #13 from FoundationDB/fix-retain-release
ktoso Oct 25, 2022
7089deb
[swift] add script to get latest centos toolchain
ktoso Oct 12, 2022
309b755
always install swift hooks; not only in "test" mode
ktoso Oct 13, 2022
b5a9769
simulator - first thing running WIP
ktoso Oct 17, 2022
b6ec08e
cleanups
ktoso Oct 18, 2022
3d82a60
more cleanup
ktoso Oct 18, 2022
63b5b0e
working snapshot
ktoso Oct 19, 2022
2610637
remove sim debug printlns
ktoso Oct 19, 2022
90931da
added convenience for whenAtLeast
ktoso Oct 21, 2022
ad27d47
try Alex's workaround
ktoso Oct 24, 2022
bb92933
annotate nonnull
ktoso Oct 25, 2022
aec4ab3
cleanup clock a little bit
ktoso Oct 25, 2022
d895287
fix missing impls after rebase
ktoso Oct 25, 2022
7842c70
Merge pull request #5 from FoundationDB/wip-sim2-impl
ktoso Oct 25, 2022
1ed7f27
Undo the swift_lookup_Map_UID_CommitProxyVersionReplies workaround
hyp Oct 25, 2022
b0297b4
Merge pull request #15 from FoundationDB/undo-wrk-two
hyp Oct 25, 2022
756ab54
[flow][swift] add Swift version of BUGGIFY
hyp Oct 12, 2022
66675c7
Merge pull request #4 from FoundationDB/eng/swift/buggify
hyp Oct 25, 2022
b34c612
[swiftication] add CounterValue type to provide value semantics for C…
hyp Oct 19, 2022
52bbb48
remove extraneous requestingProxyUID local
hyp Oct 19, 2022
092cef0
masterserver: initial Swift state prototype
hyp Oct 19, 2022
1ac7147
[interop] make the Swiftied getVersion work
hyp Oct 27, 2022
def3bca
masterserver - remove the C++ implementation (it can't be supported a…
hyp Oct 27, 2022
430b7d5
Merge pull request #8 from FoundationDB/eng/swifty-state
ktoso Oct 27, 2022
2640b02
Remove unnecessary SWIFT_CXX_REF_IMMORTAL annotations from Flow types
hyp Oct 27, 2022
5271d31
Remove C++ implementation of CommitProxyVersionReplies - it's in Swif…
hyp Oct 27, 2022
96e5cac
[swift interop] remove more SWIFT_CXX_REF_IMMORTAL
hyp Oct 27, 2022
2d6a2b5
[swift interop] add SWIFT_CXX_IMMORTAL_SINGLETON_TYPE annotation for …
hyp Oct 27, 2022
2b594ba
rename SWIFT_CXX_REF_IMMORTAL -> UNSAFE_SWIFT_CXX_IMMORTAL_REF
hyp Oct 27, 2022
f5fc405
Move master server waitForPrev to swift
sears Oct 27, 2022
c0f3a0e
Merge pull request #17 from FoundationDB/waitForPrev
ktoso Nov 1, 2022
dee7024
=build fix linking swift in all modules
ktoso Nov 2, 2022
a2415a7
=build single link option
ktoso Nov 2, 2022
6480f75
=cmake avoid manual math, just get "last" element from list
ktoso Nov 3, 2022
17bad38
Merge pull request #19 from ktoso/wip-fix-build
ktoso Nov 3, 2022
96a1b39
implement Streams support (#18)
ktoso Nov 3, 2022
37a5d8c
Merge commit '2b594bad1' into HEAD
hyp Nov 3, 2022
8d82080
[interop] update to new toolchain #6
hyp Nov 4, 2022
93d3116
Merge pull request #16 from FoundationDB/eng/immortal-cleanup
hyp Nov 4, 2022
90c4f62
[interop] remove C++ vtable linking workarounds
hyp Nov 4, 2022
d7d31e6
[interop] make MasterData proper reference counted SWIFT_CXX_REF_MAST…
hyp Nov 4, 2022
d39408c
[interop] use Swift array to pass UIDs to registerLastCommitProxyVers…
hyp Nov 4, 2022
bc3cfdd
[interop] expose MasterServer actor to C++ without wrapper struct
hyp Nov 4, 2022
62861db
[interop] we no longer need expose on methods 🥳
hyp Nov 4, 2022
f2e14e5
Merge pull request #20 from FoundationDB/toolchain-cleanups
hyp Nov 4, 2022
ace09fe
[interop] initial prototype of storing CheckedContinuation on the C++…
hyp Nov 5, 2022
6a98eab
Example of invoking a synchronous swift function from a C++ unit test…
sears Nov 5, 2022
5b7f8d2
move all "tests" we have in Swift, and priority support into real mod…
ktoso Nov 8, 2022
c8ba460
Make set continuation functions inline
hyp Nov 10, 2022
b4b1f40
Split flow_swift into flow_swift and flow_swift_future to break circu…
hyp Nov 10, 2022
7803e4c
rename SwiftContinuationCallbackStruct to FlowCallbackForSwiftContinu…
hyp Nov 10, 2022
9cc0821
Future interop: use a method in a class template for continuation set…
hyp Nov 10, 2022
bbf194b
Merge pull request #22 from FoundationDB/cpp-continuation
hyp Nov 10, 2022
c025fe6
Revert "Merge pull request #22 from FoundationDB/cpp-continuation" (#30)
ktoso Nov 14, 2022
809c579
Basic Swift Guide (#29)
ktoso Nov 15, 2022
9682a1f
Revert "Revert "Merge pull request #22 from FoundationDB/cpp-continua…
ktoso Nov 16, 2022
d8dd376
Restore the C++ continuation, but it seems waitValue is broken for CI…
ktoso Nov 16, 2022
9a7c1fb
disable broken tests - waitValue not accessible
ktoso Nov 16, 2022
2af5d3e
Streams can be async iterated over (#27)
ktoso Nov 17, 2022
103b7fb
remove work in progress things (#35)
ktoso Nov 17, 2022
6382ab6
remove some not used (yet) code
ktoso Nov 17, 2022
b550319
remove expose func for CInt, it's a primitive so we always have witne…
ktoso Nov 18, 2022
cd461be
+masterdata implement provideVersions in Swift (#36)
ktoso Nov 18, 2022
eb44de2
serveLiveCommittedVersion in Swift (#38)
ktoso Nov 30, 2022
be393ce
Port updateLiveCommittedVersion to swift (#33)
sears Nov 30, 2022
fc9ff7e
Implement updateRecoveryData in Swift (#39)
ktoso Dec 2, 2022
3357b23
Simplify flow_swift to avoid multiple targets and generate separate C…
hyp Dec 2, 2022
83d75a6
Merge pull request #40 from FoundationDB/eng/clenup_flow_target
hyp Dec 3, 2022
b7b531f
Uncomment test which was blocked on extensions not being picked up (#31)
ktoso Dec 5, 2022
7f41097
[interop] Use a separate target for Swift-to-C++ header generation
hyp Dec 6, 2022
0cf635d
Merge pull request #42 from FoundationDB/eng/reverse-header-separate-…
hyp Dec 6, 2022
8cab429
reduce boilerplate in future and stream support (#41)
ktoso Dec 7, 2022
474783f
[interop] require interop v8 - that will fix linker issue (https://gi…
hyp Dec 9, 2022
324c10a
Merge pull request #43 from FoundationDB/i/v8
hyp Dec 10, 2022
5dd4676
[interop] fix swift_stream_support.h Swift include
hyp Dec 10, 2022
7a76951
Merge pull request #44 from FoundationDB/eng/fix-swift_stream_support.h
hyp Dec 10, 2022
8842596
[interop] bump up requirement to version 9
hyp Dec 12, 2022
021dfb5
Merge pull request #46 from FoundationDB/v9
hyp Dec 12, 2022
74fc087
[interop] Generalize the Flow.Optional -> Swift.Optional conversion u…
hyp Dec 13, 2022
fce7f8c
Merge pull request #48 from FoundationDB/eng/generic-optional
hyp Dec 13, 2022
1992ee9
[WIP] masterServer func in Swift (#45)
ktoso Dec 14, 2022
36ede93
[interop] Try conforms_to with a SWIFT_CONFORMS_TO macro for Optional…
hyp Dec 14, 2022
33a7c74
[interop] include FlowOptionalProtocol source file when generating Fl…
hyp Jan 10, 2023
3adf875
Merge pull request #50 from FoundationDB/eng/fixup-checked-cont
hyp Jan 10, 2023
71662ae
conform Future to FlowFutureOps
ktoso Jan 11, 2023
9fdde8e
some notes
ktoso Jan 12, 2023
52ea6b7
move to value() so we can use discardable result for Flow.Void
ktoso Jan 12, 2023
8103ca1
make calling into Swift async funcs nicer by returning Flow Futures
ktoso Jan 17, 2023
1b85c98
[interop] hide initial use of FlowCheckedContinuation in flow.h to br…
hyp Jan 18, 2023
55e7d0b
Merge pull request #52 from FoundationDB/eng/flow-unchained
hyp Jan 18, 2023
ad01884
[fdbserver] fix an EncryptionOpsUtils.h modularization issue (showed …
hyp Feb 7, 2023
1105b91
Pass GCC toolchain using CMAKE_Swift_COMPILE_EXTERNAL_TOOLCHAIN to Sw…
hyp Mar 2, 2023
04b8f0a
[interop] drop the no longer needed libstdc++ include directories
hyp Mar 2, 2023
d6e395c
[cmake] add a configuration check to ensure Swift can import C++ stan…
hyp Mar 2, 2023
c387ccc
Merge pull request #55 from FoundationDB/modularization-fixes
hyp Mar 2, 2023
faa7d34
[swift] include msgpack from msgpack_DIR
hyp Mar 8, 2023
acb1afe
[interop] make sure the FDB module maps have 'export' directive
hyp Mar 9, 2023
f295dbb
Merge pull request #58 from FoundationDB/eng/export-module
hyp Mar 9, 2023
0d6b669
add import 'flow_swift' to swift_fdbserver_cxx_swift_value_conformanc…
hyp Mar 9, 2023
641db76
Merge pull request #59 from FoundationDB/eng/flow_swift-import
hyp Mar 9, 2023
76fc5d8
make sure the Swift -> C++ manually bridged function signature matche…
hyp Mar 9, 2023
b01b271
[interop][workaround] force back use of @expose attribute before _Con…
hyp Mar 9, 2023
32af490
Merge pull request #60 from FoundationDB/eng/update-to-gen-hdr
hyp Mar 9, 2023
9d4a595
[interop] make getResolutionBalancer return a pointer to allow Swift …
hyp Mar 12, 2023
03169b9
[interop] add a workaround for 'pop' being marked as unsafe in Swift
hyp Mar 12, 2023
6d72329
masterserver.swift: MasterData returns the Swift actor pointer in an …
hyp Mar 12, 2023
e6cd5d0
Add a 'getCopy' method to AsyncVar to make it more Swift friendly
hyp Mar 12, 2023
247f2b1
Merge pull request #61 from FoundationDB/eng/make-fdb-link-again
hyp Mar 13, 2023
76845fa
[interop] bump up the toolchain requirement
hyp Mar 13, 2023
cd80fc9
Revert "[interop][workaround] force back use of @expose attribute bef…
hyp Mar 13, 2023
1594cb6
[interop] add FIXME comments highlighting new issue workarounds
hyp Mar 13, 2023
df55579
[interop] adopt the new C++ interoperability compiler flag
hyp Mar 13, 2023
5d837bf
Merge pull request #62 from FoundationDB/eng/adopt-interop-14
hyp Mar 13, 2023
0a8dc46
[interop] generate swift compile commands
hyp Mar 16, 2023
e95b0c2
Do not deduplicate Swift compilation commands
hyp Mar 16, 2023
33165d1
Merge pull request #63 from FoundationDB/eng/gen-cdb
hyp Mar 16, 2023
4f4b110
[interop] generate swift compile commands
hyp Mar 16, 2023
d59e246
Do not deduplicate Swift compilation commands
hyp Mar 16, 2023
669f63a
flow actorcompiler.h: add a SWIFT_ACTOR empty macro definition
hyp Mar 16, 2023
8741311
[cmake] add missing dependencies
hyp Mar 17, 2023
9a0d030
experimental cross compile
hyp Mar 9, 2023
372130e
[cmake] fix triple in cross-compiled cmake flags
hyp Mar 17, 2023
4ebad9f
[interop] update to interop toolchain version 16
hyp Mar 24, 2023
2eaf07a
Merge pull request #65 from FoundationDB/eng/i16
hyp Mar 24, 2023
df1db52
[x-compile] add flags for cross-compiling boost
hyp Mar 26, 2023
b302266
cleanup x-compile cmake changes
hyp Mar 28, 2023
ee8ff8b
Merge pull request #64 from FoundationDB/eng/x-compile-ide
hyp Mar 28, 2023
aeb0c77
[cmake] fix typo in CMAKE_Swift_COMPILER_EXTERNAL_TOOLCHAIN config va…
hyp Mar 29, 2023
1c9faa0
Merge pull request #66 from FoundationDB/eng/fix_CMAKE_Swift_COMPILER…
hyp Mar 29, 2023
df39590
[interop] pass MasterDataActor from Swift to C++ and back to Swift
hyp Mar 29, 2023
a845a96
Merge pull request #67 from FoundationDB/eng/MasterDataActor-backandf…
hyp Mar 29, 2023
15c7fd8
[fdbserver] Swift->C++ header generation for FDBServer should use sam…
hyp Feb 7, 2023
d694bca
Update swift_get_latest_toolchain.sh to fetch 5.9 toochains
ktoso Mar 30, 2023
fe1d565
set HAVE_FLAG_SEARCH_PATHS_FIRST for cross compilation
hyp Apr 3, 2023
a89ea72
Merge pull request #68 from FoundationDB/eng/set-search-paths-off-link
hyp Apr 3, 2023
9b6032b
partial merge with upstream foundationdb
hyp Apr 5, 2023
6da61df
Merge branch 'main' into fdb/eng/partial-merge-usptream
ktoso Apr 5, 2023
950b898
Resolve conflicts in net2/sim2/actors, can't build yet
ktoso Apr 5, 2023
8d6f156
undo SWIFT_ACTOR changes, not necessary for merge
ktoso Apr 5, 2023
f140576
guard c++ compiler flags with is_cxx_compile
ktoso Apr 5, 2023
0250636
Update flow/actorcompiler/ActorParser.cs
ktoso Apr 5, 2023
8acb0fd
update the boost dependency
hyp Apr 4, 2023
48bed72
Include boost directory from the container for Swift
hyp Apr 4, 2023
c3115e7
conform flow's Optional to FlowOptionalProtocol again
hyp Apr 5, 2023
b5003b5
Guard entire RocksDBLogForwarder.h with SSD_ROCKSDB_EXPERIMENTAL to a…
hyp Apr 5, 2023
2a66771
remove extraneous merge marker
hyp Apr 5, 2023
c0b6cd7
[swift] update swift_test_streams.swifto to use vars in more places
hyp Apr 5, 2023
593e1a1
Add header guard to flow/include/flow/ThreadSafeQueue.h to fix modura…
hyp Apr 5, 2023
124c627
Update net and sim impls
ktoso Apr 6, 2023
d31c36b
[cmake] use prebuilt libc++ boost only when we're actually using libc++
hyp Apr 11, 2023
24504bc
[fdbserver] Swift->C++ header generation for FDBServer should use sam…
hyp Feb 7, 2023
35d5e0e
Merge branch 'upstream-main' into wip-staged-merged-main-1
ktoso Apr 20, 2023
af024b7
fixups after merge
ktoso Apr 20, 2023
76709d5
remove CustomStringConvertible conformance that would not be used
ktoso Apr 20, 2023
e3abfb8
remove self-caused deprecation warnings in future_support
ktoso Apr 20, 2023
7deeca7
handle newly added task priority
ktoso Apr 20, 2023
2ca0595
reformatting
ktoso Apr 20, 2023
6f36bdd
future: make value() not mutating
ktoso Apr 20, 2023
9aba9b2
remove FIXME, not needed anymore
ktoso Apr 21, 2023
ccb43a6
future: clarify why as functions
ktoso Apr 21, 2023
f3a4dd9
Merge branch 'main' into wip-staged-merged-main-1
ktoso Apr 26, 2023
c344c41
Support TraceEvent in Swift
ktoso Apr 28, 2023
5ce8a12
Enable TraceEvent using a class wrapper in Swift
ktoso May 1, 2023
14a6779
prearing WITH_SWIFT flag
ktoso May 1, 2023
6d90267
wip disabled failing Go stuff
ktoso May 1, 2023
6b90db9
cleanup WITH_SWIFT_FLAG and reenable Go
ktoso May 1, 2023
8ede4f7
wip disabled failing Go stuff
ktoso May 1, 2023
bb3aa51
move setting flag before printing it
ktoso May 2, 2023
4a214d5
Add SWIFT_IDE_SETUP and cleanup guides and build a bit
ktoso May 2, 2023
ebbc238
Merge remote-tracking branch 'upstream/main' into wip-staged-merged-m…
ktoso May 2, 2023
5ad8dce
Revert "Wipe packet buffers that held serialized WipedString (#10018)"
ktoso May 2, 2023
7d29c31
[Swift] Compile workaround in KeyBackedRangeMap; default init is inco…
ktoso May 2, 2023
b93e57c
[interop] do not add FlowFutureOps conformance when building flow cla…
hyp May 2, 2023
8ed9cd4
make sure to show -DUSE_LIBCXX=OFF in readme
ktoso May 3, 2023
f2a0706
readme updates
ktoso May 4, 2023
e756706
do not print to stderr
ktoso May 11, 2023
7ca087e
Update Swift and C++ code to build with latest Swift 5.9 toolchain no…
hyp May 20, 2023
ce9b242
Fix SERVER_KNOBS and enable use them for masterserver
vishesh May 21, 2023
d33ad47
Bump to C++20, Swift is now able to handle it as well
ktoso May 22, 2023
b3de697
Put waitForPrev behind FLOW_WITH_SWIFT knob
vishesh May 22, 2023
88be3e1
Forward declare updateLiveCommittedVersion
vishesh May 23, 2023
c5a082f
Remove unused code
vishesh May 23, 2023
9df7574
fix wrong condition set for updateLiveCommittedVersion
vishesh May 23, 2023
ce9f295
Merge pull request #2 from vishesh/ktoso-wip-staged-merged-main-2
vishesh May 24, 2023
c1dbfe1
Revert "Revert "Wipe packet buffers that held serialized WipedString …
ktoso May 22, 2023
349f681
Enable go-bindings in cmake
vishesh May 25, 2023
789ca66
Revert "Revert "Wipe packet buffers that held serialized WipedString …
vishesh May 25, 2023
be525a4
Merge pull request #3 from vishesh/ktoso-wip-staged-merged-main-2
ktoso May 25, 2023
59b820e
Merge pull request #4 from vishesh/ktoso-wip-staged-merged-main-2
ktoso May 25, 2023
6ed27ab
USE_SWIFT flag so we "build without swift" until ready to by default
ktoso May 26, 2023
9c0e8a0
uncomment a few tests which were disabled during USE_SWIFT enablement
ktoso May 26, 2023
3fb953f
the option is WITH_SWIFT, not USE
ktoso May 26, 2023
1bf66d2
formatting
ktoso May 26, 2023
a9fbc74
Merge remote-tracking branch 'ktoso/wip-use-swift-build-time-flag' in…
vishesh May 30, 2023
ad4d807
Fix masterserver compile error
vishesh May 30, 2023
e0cbfff
Merge remote-tracking branch 'apple/main' into ktoso-wip-staged-merge…
vishesh May 30, 2023
8e74788
Fix some build errors.
vishesh May 25, 2023
1719fff
remove initializer list from constructor
vishesh May 26, 2023
e2d091e
Merge pull request #6 from ktoso/wip-use-swift-build-time-flag
vishesh May 30, 2023
0abcf41
Expect Swift toolchain only if WITH_SWIFT is enabled
vishesh May 30, 2023
d262143
Merge remote-tracking branch 'ktoso/wip-staged-merged-main-2' into kt…
vishesh May 30, 2023
00b736e
Don't require Flow_CheckedContinuation when Swift is disabled
vishesh May 30, 2023
c8f49ad
Don't compile FlowCheckedContinuation when WITH_SWIFT=OFF
vishesh May 30, 2023
26a5b33
No-op Swift macros
vishesh May 30, 2023
46cb4c9
More compile guards
vishesh May 30, 2023
a27792b
fix typo
vishesh May 30, 2023
177d24c
Run clang-format
vishesh May 30, 2023
fda513d
Merge pull request #5 from vishesh/ktoso-wip-staged-merged-main-2
vishesh May 31, 2023
7e351fd
Merge branch 'main' into wip-staged-merged-main-2
vishesh May 31, 2023
d3d3539
Guard swift/bridging include in fdbrpc
vishesh May 31, 2023
7862801
Merge pull request #7 from vishesh/ktoso-wip-staged-merged-main-2
vishesh May 31, 2023
4df4a7e
Remove printf to pass the test
vishesh May 31, 2023
9ae23c0
Remove some more printf to avoid potential issues
vishesh May 31, 2023
1d3a0c0
Remove __has_feature(nullability) as its only used in Swift
vishesh May 31, 2023
52e4b9e
Merge remote-tracking branch 'apple/main' into ktoso-wip-staged-merge…
vishesh May 31, 2023
9a05908
Don't use __FILENAME__
vishesh May 31, 2023
54203a8
Don't call generate_module_map outside WITH_SWIFT
vishesh May 31, 2023
d7eeb07
Add some more cmake stuff under WITH_SWIFT guard
vishesh May 31, 2023
8c76d45
Some more guards
vishesh Jun 1, 2023
d591992
Bring back TLSTest.cpp
vishesh Jun 1, 2023
24117f3
clang-format
vishesh Jun 1, 2023
0020844
fix comment formatting
vishesh Jun 2, 2023
e905e61
Merge remote-tracking branch 'apple/main' into wip-staged-merged-main-2
vishesh Jun 2, 2023
08f81c9
Remove unused command line arg
vishesh Jun 2, 2023
5272b94
fix cmake formatting in some files
vishesh Jun 2, 2023
c82c98c
Address some review comments
vishesh Jun 2, 2023
b3e9a72
fix clang-format error
vishesh Jun 2, 2023
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: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ project(foundationdb
VERSION 7.3.0
DESCRIPTION "FoundationDB is a scalable, fault-tolerant, ordered key-value store with full ACID transactions."
HOMEPAGE_URL "http://www.foundationdb.org/"
LANGUAGES C CXX ASM)
LANGUAGES C CXX ASM Swift)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

Expand Down Expand Up @@ -187,16 +187,22 @@ add_subdirectory(fdbclient)
add_subdirectory(fdbserver)
add_subdirectory(fdbcli)
if(NOT WIN32)
add_subdirectory(fdbmonitor)
if (NOT FOUNDATIONDB_CROSS_COMPILING) # FIXME(swift): make this work when x-compiling.
add_subdirectory(fdbmonitor)
endif()
else()
add_subdirectory(fdbservice)
endif()
add_subdirectory(fdbbackup)
add_subdirectory(metacluster)
add_subdirectory(tests)
add_subdirectory(flowbench EXCLUDE_FROM_ALL)
if (NOT FOUNDATIONDB_CROSS_COMPILING) # FIXME(swift): make this work when x-compiling.
add_subdirectory(flowbench EXCLUDE_FROM_ALL)
endif()
if(WITH_PYTHON AND WITH_C_BINDING)
add_subdirectory(bindings)
if (NOT FOUNDATIONDB_CROSS_COMPILING) # FIXME(swift): make this work when x-compiling.
add_subdirectory(bindings)
endif()
endif()
if(WITH_DOCUMENTATION)
add_subdirectory(documentation)
Expand All @@ -219,11 +225,14 @@ if (CMAKE_EXPORT_COMPILE_COMMANDS AND WITH_PYTHON)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
COMMAND $<TARGET_FILE:Python3::Interpreter> ${CMAKE_CURRENT_SOURCE_DIR}/contrib/gen_compile_db.py
ARGS -b ${CMAKE_CURRENT_BINARY_DIR} -s ${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
ARGS -b ${CMAKE_CURRENT_BINARY_DIR} -s ${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json -ninjatool ${CMAKE_MAKE_PROGRAM} ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/gen_compile_db.py ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
COMMENT "Build compile commands for IDE"
)
add_custom_target(processed_compile_commands ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json)

# A prebuild target ensures that all actors, Swift-generated headers, and Swift modules are built.
add_custom_target(prebuild_for_ide ALL DEPENDS fdbserver_swift processed_compile_commands)
endif()

################################################################################
Expand Down
310 changes: 310 additions & 0 deletions SWIFT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
# Swift in FoundationDB

The optional Swift support allows piecewise adoption of Swift in implementing FoundationDB.

Swift offers a unique modern type-safe low-ceremony approach taking the best of both worlds that scales from mobile
apps to high-performance systems where previously memory-unsafe languages would be used. It also interoperates
seamlessly with C and C++.

Since FoundationDB is largely implemented in C++ and Flow, large pieces of

## Building with Swift

Swift is built using the same CMake build as the rest of the project.

To configure the build such that `clang` and `swiftc` are used, use the following:

```swift
cd build

cmake -G 'Ninja' \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_Swift_COMPILER=swiftc \
-DWITH_SWIFT=ON \
-DUSE_LIBCXX=OFF \
-DCMAKE_Swift_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/devtoolset-11/root/usr \
../src/foundationdb/
```

Then, build using `ninja` as usual.

## IDE Integration

A full guide on setting up IDEs with FoundationDB, including cross language autocomplete support and code navigation
is available here: [SWIFT_IDE_SETUP.md](SWIFT_IDE_SETUP.md)

## How Swift interoperates with C++

The CMake build has been prepared with Swift interop in the following modules:

- flow
- fdbrpc
- fdbclient
- fdbserver

The integration works "both ways", i.e. Swift can call into Flow/C++ code, as well as Flow/C++ can call into Swift.

Swift generates clang modules which can be consumed in C++. For example, the module `fdbserver_swift` contains all swift code in `fdbserver/`.

> Note: you can check, and add new files to the `_swift` targets by locating the command, e.g. `add_library(fdbserver_swft` in [fdbserver/CMakeLists.txt](fdbserver/CMakeLists.txt).

Then, you can then include the generated module in C++:

```cpp
// ...
#include "SwiftModules/FDBServer"

#include "flow/actorcompiler.h" // This must be the last #include.
```

## Swift Basics

When in doubt about Swift syntax, refer to https://docs.swift.org/swift-book/ or reach out to the team, we're here to help.

## Swift → C++

Swift can import clang modules, and does so using the `import` statement, like so:

```swift
import Flow
import flow_swift
import FDBServer
import FDBClient
import fdbclient_swift
import FlowFutureSupport
import flow_swift_future
// ...
```

The module has to have dependencies set up properly in `CMake` as well, check `CMakeLists.txt` for examples.

### Futures and other templates

Swift's C++ interop cannot currently instantiate class templates in Swift, but can use specialized templates if they are declared so in C++. For example, in order to use Flow futures and promises in Swift, we currently need to type alias them on the C++ side, and then use the type alias name in Swift, like so:

```swift
// flow/include/flow/swift_future_support.h
using PromiseCInt = Promise<int>;
using FutureCInt = Future<int>;

using PromiseVoid = Promise<Void>;
using FutureVoid = Future<Void>;
```

To use them in Swift make sure to use the type-aliases:

```swift
public func getVersion(cxxState: MasterData, req: GetCommitVersionRequest, result promise: PromiseVoid) {
// ...
}
```

### Sendable

Sendable is Swift's mechanism to ensure compile time thread-safety. It does so by marking types known to be safe to send across task/actor/thread boundaries with `Sendable` (i.e. `struct Something: Sendable {}` and checks related to it).

In order to declare a C++ type as Sendable you can use the @Sendable attribute:

```cpp
#define SWIFT_SENDABLE \
__attribute__((swift_attr("@Sendable")))
```

which is used like this:

```cpp
template <class T>
class SWIFT_SENDABLE Future {
// ...
};
```



### Importing types

Swift can import copyable C++ structs and classes as Swift value types. Non-copyable types with value semantics require special wrappers to make them available in Swift (see the "Non-copyable types" section).

Swift can also import some C++ types as reference types, if they're appropriately annotated. The sections "Bridging Singleton-like values with immortal reference types" and "Bridging reference types" describes how that can be done.

Swift will avoid importing "unsafe projections", which means a type which contains pointers to something "outside" the type, as they may end up pointing at unsafe memory.

#### Non-copyable types

Swift's C++ interop currently cannot import non-copyable C++ types. If you have a type that's non-copyable that you want to use as a value type in Swift (i.e. it's typically used as its own type in C++, not through a pointer type), you most likely want to wrap it in a copyable type which is then made available to Swift. For types that have reference semantics (i.e. you always pass it around using a raw pointer or a custom smart pointer type in C++), see the "Bridging reference types" section.

For example, Flow's `Counter` type is non-copyable. We can make it available to
Swift so that it can be used as a stored property in a Swift actor by creating a value
type wrapper for it in C++, that stores the counter in a shared pointer value:

```cpp
// A type with Swift value semantics for working with `Counter` types.
class CounterValue {
public:
using Value = Counter::Value;

CounterValue(std::string const& name, CounterCollection& collection);

void operator+=(Value delta);
void operator++();
void clear();
private:
std::shared_ptr<Counter> value;
};
```

We want to implement the required interface for this type that's needed from Swift.

#### Bridging Singleton-like values with immortal reference types

Certain C++ types act as singletons which have one value referenced throughout codebase. That value is expected to be alive throughout the lifetime of the program. Such types can be bridged to Swift using the `SWIFT_CXX_IMMORTAL_SINGLETON_TYPE` annotation. This annotation will instruct Swift to import such type as reference type that doesn't need any reference counting, i.e. it's assumed to be immortal.

For instance, the `INetwork` interface type:

```cpp
class SWIFT_CXX_IMMORTAL_SINGLETON_TYPE ServerKnobs : public KnobsImpl<ServerKnobs> {
public:
```

Gets bridged over to an immortal reference type in Swift:

```Swift
let knobs = getServerKnobs() // knobs type is `ServerKnobs` in Swift, identical to `ServerKnobs *` C++ type.
knobs.MAX_VERSION_RATE_MODIFIER
```

#### Bridging reference types

Some C++ types have reference counting and referencial semantics, i.e. they're passed around using raw or smart pointers that point to an instance. That instance typically has its own reference count, that keeps track of when the instance should be released. Such types can be bridged over to Swift reference types, and Swift's automatic reference counting (ARC) will automatically retain and release them using their C++ reference counting implementation.

You can use the `SWIFT_CXX_REF` annotation for that. Right now `SWIFT_CXX_REF` does not work (due to https://github.com/apple/swift/issues/61620), so you have to make a custom annotation for each class you want to bridge with reference semantics to Swift. For example, the `MasterData` class receives the following annotation:

```cpp
#define SWIFT_CXX_REF_MASTERDATA \
__attribute__((swift_attr("import_as_ref"))) \
__attribute__((swift_attr("retain:addrefMasterData"))) \
__attribute__((swift_attr("release:delrefMasterData")))

struct SWIFT_CXX_REF_MASTERDATA MasterData : NonCopyable, ReferenceCounted<MasterData> {
```

This annotation then makes Swift's' `MasterData` type behave like C++/Flow's `Reference<MasterData>` type, i.e. it is automatically reference counted in Swift.

### Awaiting Flow concurrency types

Flow **Futures** can be awaited on in Swift, like this:

```swift
var f: FutureCInt = ...
await f.value()
```

to avoid name clashes with `value` it's currently called `waitValue` though we should probably rename this.

You can also await a next value of a stream:

```swift
var ps = PromiseStream<CInt>()
var fs: FutureStream<CInt> = ps.getFuture()

// ...

let element = try? await fs.waitNext // suspends until value is sent into `ps`
```

It is also possible to use the `async for-loop` syntax on `FutureStream`s:

```swift
for try await num in fs {
// ...
}
```

This future will loop until an "end" is sent to the stream.

Sending an "end" element is currently done the same way as in Flow itself:

```swift
var i: CInt = 10
ps.send(&i)
ps.sendError(end_of_stream())
```

## C++ → Swift

Calling Swift from C++ is relatively simple, you can write new Swift code and `@_expose(Cxx)` them, like this free function in Swift:

```swift
@_expose(Cxx)
public func swiftyTestRunner(p: PromiseVoid) { }
```

This can be called from C++ as expected:

```swift
fdbserver_swift::swiftyTestRunner(p);
```

### Exposing actors and async functions

Actors in Swift have strong isolation properties and cannot be accessed synchronously, as such, every method declared on an actor is implicitly `async` if called from the outside. For example:

```swift
@_expose(Cxx)
actor Example {
func hi() -> String { "hi!" }
}
```

this `hi()` method is not imported into C++, so you'd get an error when trying to call it on an instance of `Example` from C++:

```
<<error not imported>>
```

This is because, calls "into" an actor are implicitly async, so the method is effectively async:

```swift
@_expose(Cxx)
actor Example {
func hi() async -> CInt { 42 }
}
```

Since C++ does not understand Swift's async calling convention, we don't import such methods today. This is why today we implement a `nonisolated` wrapper method in order to bridge Flow/C++ and the Swift actor method, like this:

```swift
@_expose(Cxx)
actor Example {
func hi() async -> CInt { 42 }

nonisolated func hi(/*other params*/ result: PromiseCInt) {
Task { // schedule a new Task
var i = await self.hi() // inside that task, await the hi() method
result.send(&i)
}
}
}
```

And since the `Example` was `_expose`-d the `nonisolated func hi(result:)` is as well, and that can be called from C++:

```swift
// C++
auto promise = Promise<int>();
actor.hi(promise);
wait(p.getFuture());
```

> Note: We hope to simplify this, so you could just `wait(actor.hi())`. And the nonisolated wrapper can also be implemented using a Swift macro once they land (Swift macros are work in progress, and operate on AST, so we're not too worried about using them -- i.e. they are not just textual macros).

## Swift tests

We have prepared a ver simple test suite runner since we cannot use the usual Swift's XCTest framework (maybe we could, didn't investigate yet). To run `swift` tests inside `fdbserver` run like this:

```bash
FDBSWIFTTEST=1 bin/fdbserver -p AUTO
```

you can also `--filter-test future` etc.
Loading