I'd like to know more about @effects attribute.
Apart from the document linked to above, I haven't been able to find anything.
As it's available in Xcode 9.4 and doesn't have an underscore I assume that it's supposed to be usable not only in the implementation of the standard library?
Where should I go to find more info, implementation status etc?
I noticed that while the following (command line prg) compiles with Xcode 9.4 (default toolchain), it always prints 0 instead of the expected 123:
@effects(readnone)
func f<T>(_ a: T) -> T { return a }
let x = f(123)
print(x) // Prints 0, not 123
(Note that I'm only talking about release builds / -O, with a debug build it will print 123.)
And, if I stick the top level statements in a func, it prints "random" values:
@effects(readnone)
func f<T>(_ a: T) -> T { return a }
func test() {
let x = f(123)
print(x) // Prints "random" (uninitialized?) values.
}
test()
Also, if I use a recent dev snapshot (2018-06-03), the first example will work the same (printing 0), but the second example will crash the compiler.
(I'm still talking only about release builds, as I guess the attribute has no effect in debug builds? (It won't crash the compiler when doing a debug build)).
Here's what the compiler crash looks like
› /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-06-03-a.xctoolchain/usr/bin/swiftc --version
Apple Swift version 4.2-dev (LLVM 58850e66ae, Clang b58a7ad218, Swift feb385736b)
Target: x86_64-apple-darwin17.5.0
› /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-06-03-a.xctoolchain/usr/bin/swiftc -O test.swift
Assertion failed: (ASI->getElementType().isVoid() && "Expected initialization of non-void type!"), function removeSingleBlockAllocation, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILOptimizer/Transforms/SILMem2Reg.cpp, line 470.
0 swift 0x000000010f193b08 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000010f192d77 llvm::sys::RunSignalHandlers() + 39
2 swift 0x000000010f194182 SignalHandler(int) + 258
3 libsystem_platform.dylib 0x00007fff79195f5a _sigtramp + 26
4 libsystem_platform.dylib 0x00007fb4340f3d40 _sigtramp + 3136675328
5 libsystem_c.dylib 0x00007fff78f331ae abort + 127
6 libsystem_c.dylib 0x00007fff78efb1ac basename_r + 0
7 swift 0x000000010c44db74 (anonymous namespace)::MemoryToRegisters::promoteSingleAllocation(swift::AllocStackInst*, llvm::DenseMap<llvm::DomTreeNodeBase<swift::SILBasicBlock>*, unsigned int, llvm::DenseMapInfo<llvm::DomTreeNodeBase<swift::SILBasicBlock>*>, llvm::detail::DenseMapPair<llvm::DomTreeNodeBase<swift::SILBasicBlock>*, unsigned int> >&) + 9844
8 swift 0x000000010c44b393 (anonymous namespace)::SILMem2Reg::run() + 1011
9 swift 0x000000010c336673 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1475
10 swift 0x000000010c3375c3 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1315
11 swift 0x000000010c338284 swift::SILPassManager::execute() + 660
12 swift 0x000000010bb4e88b swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
13 swift 0x000000010c340085 swift::runSILOptimizationPasses(swift::SILModule&) + 117
14 swift 0x000000010b9e9680 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13520
15 swift 0x000000010b9e5161 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3297
16 swift 0x000000010b9a111c main + 2300
17 libdyld.dylib 0x00007fff78e87015 start + 1
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-06-03-a.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-darwin17.5.0 -enable-objc-interop -O -color-diagnostics -module-name test -o /var/folders/50/br4kxvjd0t551h0fmtrzkwdw0000gn/T/test-847ef0.o
1. While running pass #565 SILFunctionTransform "Mem2Reg" on SILFunction "@$S4testAAyyF".
for 'test()' at test.swift:4:1
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)