I have been exploring Macros and was attempting to create one which solely returns a lazy var, utilizing the next code:
public struct SubjectPublisherMacro: PeerMacro {
public static func enlargement(of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext) throws -> [SwiftSyntax.DeclSyntax] {
return [
"lazy var state: AnyPublisher<String, Never> = { subject.eraseToAnyPublisher() }()"
]
}
}
When utilized to a Topic, like the next:
@SubjectPublisher
non-public var topic = PassthroughSubject<String, By no means>()
If we broaden the macro, the code generated is successfully:
lazy var state: AnyPublisher<String, By no means> = {
topic.eraseToAnyPublisher()
}()
Nonetheless, once we compile, it provides an error, and we now have the next Stack dump:
0. Program arguments: /Purposes/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Customers/xpto/macros/FFMacros/Sources/FFMacrosClient/fundamental.swift -emit-dependencies-path /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.d -emit-const-values-path /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.swiftconstvalues -emit-reference-dependencies-path /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.swiftdeps -serialize-diagnostics-path /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.dia -target arm64-apple-macos10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Merchandise/Debug -I /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Merchandise/Debug/PackageFrameworks -F /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Merchandise/Debug -F /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Customers/xpto/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -load-plugin-executable /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Merchandise/Debug/FFMacrosMacros#FFMacrosMacros -package-name ffmacros -const-gather-protocols-file /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/FFMacrosClient_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Customers/xpto/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Customers/xpto/macros/FFMacros -resource-dir /Purposes/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -ivfsstatcache -Xcc /Customers/xpto/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx14.2-23C53-ddea79c7890ab41bba4a63928c655a96.sdkstatcache -Xcc -I/Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Merchandise/Debug/embody -Xcc -I/Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/DerivedSources-normal/arm64 -Xcc -I/Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/DerivedSources/arm64 -Xcc -I/Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name FFMacrosClient -frontend-parseable-output -disable-clang-spi -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift/host/plugins#/Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/native/lib/swift/host/plugins#/Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/native/lib/swift/host/plugins#/Purposes/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Purposes/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/native/lib/swift/host/plugins -o /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Construct/Intermediates.noindex/FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.o -index-unit-output-path /FFMacros.construct/Debug/FFMacrosClient.construct/Objects-normal/arm64/fundamental.o -index-store-path /Customers/xpto/Library/Developer/Xcode/DerivedData/FFMacros-byrxxptdunfedzeunapzrisyulor/Index.noindex/DataStore -index-system-modules
1. Apple Swift model 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
2. Compiling with the present language model
3. Whereas evaluating request IRGenRequest(IR Era for file "/Customers/macros/FFMacros/Sources/FFMacrosClient/fundamental.swift")
4. Whereas emitting IR SIL operate "@$s14FFMacrosClient4TestC5state7Combine12AnyPublisherVySSs5NeverOGvg".
for getter for state (at @__swiftmacro_14FFMacrosClient4TestC7subject33_32E41C858868D91DD4497E3BF955E2AFLL16SubjectPublisherfMp_.swift:1:10)
Stack dump with out image names (guarantee you have got llvm-symbolizer in your PATH or set the atmosphere var `LLVM_SYMBOLIZER_PATH` to level to it):
0 swift-frontend 0x000000010728dabc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000109ef3cb0 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000109c5d054 SignalHandler(int) + 352
3 libsystem_platform.dylib 0x0000000186829a24 _sigtramp + 56
4 swift-frontend 0x00000001098a52a4 swift::irgen::projectPhysicalClassMemberAddress(swift::irgen::IRGenFunction&, llvm::Worth*, swift::SILType, swift::SILType, swift::VarDecl*, swift::GenericSignature) + 1036
5 swift-frontend 0x00000001098a52a4 swift::irgen::projectPhysicalClassMemberAddress(swift::irgen::IRGenFunction&, llvm::Worth*, swift::SILType, swift::SILType, swift::VarDecl*, swift::GenericSignature) + 1036
6 swift-frontend 0x0000000106e90ee4 (nameless namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 79544
7 swift-frontend 0x0000000109611fdc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 11680
8 swift-frontend 0x00000001072109c8 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>,
std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 2516
9 swift-frontend 0x00000001058b59d0 swift::IRGenRequest::consider(swift::Evaluator&, swift::IRGenDescriptor) const + 6532
10 swift-frontend 0x0000000105188adc swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
11 swift-frontend 0x0000000106b59f64 llvm::Anticipated<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 1480
12 swift-frontend 0x0000000108e00fb8 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 264
13 swift-frontend 0x00000001097cd99c generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
14 swift-frontend 0x00000001097d56d4 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1596
15 swift-frontend 0x00000001097d0a08 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1748
16 swift-frontend 0x00000001097d4854 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
17 swift-frontend 0x000000010983bd44 swift::mainEntry(int, char const**) + 4408
18 dyld 0x00000001864790e0 begin + 2360
LLVM Profile Error: Failed to write down file "default.profraw": Operation not permitted
If we modify our macro to return a computed var as an alternative of a lazy var, we are able to compile efficiently. Nonetheless, our objective was to return the lazy var. Does anybody have an concept of what the problem may be?
Thanks in your assist!