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
[SR-9991] It is possible to forward @autoclosure in a tuple #52395
Comments
Hm, I can't reproduce it in my local build of Swift 5, which admittedly isn't as new as the snapshot you tried. @xedin, did something just change here? |
Comment by Bartosz Polaczyk (JIRA) I downloaded func copyType<I,O> (_ function: (I) -> (O)) -> (I) -> (O) {
fatalError("Never called")
}
class Class {
lazy var storage = copyType(takeFunction) // storage is "autoclosured"
func takeFunction(_ autoString: @autoclosure () -> String, other: String) {
}
} /Library/Developer/Toolchains/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-24-a.xctoolchain/usr/bin/swiftc autoclosure.swift -v
Apple Swift version 5.0-dev (LLVM 3207a50965, Clang 72dde1b133, Swift a8126fb484)
Target: x86_64-apple-darwin18.5.0
/Library/Developer/Toolchains/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-24-a.xctoolchain/usr/bin/swift -frontend -c -primary-file autoclosure.swift -target x86_64-apple-darwin18.5.0 -enable-objc-interop -color-diagnostics -module-name autoclosure -o /var/folders/3v/2ymlw0cd53q9k8qsr1vg45gh0000gn/T/autoclosure-58c714.o
Assertion failed: (flags.isNone()), function appendTypeList, file /Users/buildnode/jenkins/workspace/oss-swift-5.0-package-osx/swift/lib/AST/ASTMangler.cpp, line 1829.
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-24-a.xctoolchain/usr/bin/swift -frontend -c -primary-file autoclosure.swift -target x86_64-apple-darwin18.5.0 -enable-objc-interop -color-diagnostics -module-name autoclosure -o /var/folders/3v/2ymlw0cd53q9k8qsr1vg45gh0000gn/T/autoclosure-58c714.o
0 swift 0x000000010afa1c45 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x000000010afa0ee5 llvm::sys::RunSignalHandlers() + 85
2 swift 0x000000010afa2232 SignalHandler(int) + 258
3 libsystem_platform.dylib 0x00007fff7f1e5b5d _sigtramp + 29
4 libsystem_platform.dylib 0x00007f9e930a1b48 _sigtramp + 334217224
5 libsystem_c.dylib 0x00007fff7f0a56a6 abort + 127
6 libsystem_c.dylib 0x00007fff7f06e20d basename_r + 0
7 swift 0x000000010865117b swift::Mangle::ASTMangler::appendTypeList(swift::Type) + 523
8 swift 0x000000010864d18f swift::Mangle::ASTMangler::appendType(swift::Type) + 1055
9 swift 0x00000001086536fc swift::Mangle::ASTMangler::appendTypeListElement(swift::Identifier, swift::Type, swift::ParameterTypeFlags) + 140
10 swift 0x0000000108653542 swift::Mangle::ASTMangler::appendFunctionInputType(llvm::ArrayRef<swift::AnyFunctionType::Param>) + 146
11 swift 0x00000001086533aa swift::Mangle::ASTMangler::appendFunctionSignature(swift::AnyFunctionType*) + 58
12 swift 0x00000001086518b2 swift::Mangle::ASTMangler::appendFunctionType(swift::AnyFunctionType*, bool) + 50
13 swift 0x000000010864e638 swift::Mangle::ASTMangler::appendType(swift::Type) + 6344
14 swift 0x000000010864f67d swift::Mangle::ASTMangler::appendDeclType(swift::ValueDecl const*, bool) + 205
15 swift 0x000000010864b04a swift::Mangle::ASTMangler::appendEntity(swift::ValueDecl const*, llvm::StringRef, bool) + 58
16 swift 0x000000010864b292 swift::Mangle::ASTMangler::mangleInitializerEntity(swift::VarDecl const*, swift::Mangle::ASTMangler::SymbolKind) + 66
17 swift 0x000000010818cfb6 swift::SILDeclRef::mangle(swift::SILDeclRef::ManglingKind) const + 1446
18 swift 0x00000001081dc527 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 55
19 swift 0x0000000107c45eac swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 348
20 swift 0x0000000107c49683 swift::Lowering::SILGenModule::emitStoredPropertyInitialization(swift::PatternBindingDecl*, unsigned int) + 867
21 swift 0x0000000107d2e76d (anonymous namespace)::SILGenType::emitType() + 429
22 swift 0x0000000107d2e5b9 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
23 swift 0x0000000107c4bd26 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 822
24 swift 0x0000000107c4cc35 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 293
25 swift 0x0000000107c4d1b9 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&) + 41
26 swift 0x00000001073d5a9c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 8012
27 swift 0x00000001073d2de8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3000
28 swift 0x0000000107384c62 main + 690
29 libdyld.dylib 0x00007fff7f0003ed start + 1
30 libdyld.dylib 0x000000000000000d start + 2164259873
<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) |
@slavapestov Looks like `flag.isNone()` assert added by d31d35a, might be too strict for this case since we allow `@autoclosure` marked parameters inside of optional container like in the example code. Type of the `storage` declaration is a follows:
WDYT? |
Or maybe if we should just disallow assigning tuples with @autoclosure flag to generic parameters in the solver, jut like we do for @escaping I think... |
Hm, I though that we disallowed @escaping in situations like this, but then I tried this example with @escaping instead of @autoclosure `Class` declaration and it compiled just fine... |
I think the call `copyType(takeFunction)` should be rejected. We should not do the 'tuple splat' when the argument list contains an autoclosure. |
We also allow splatting tuples containing noescape function types, which isn't sound either:
|
Environment
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.5.0
Additional Detail from JIRA
md5: 2d9abebffa6f6c5993f5446f37e30268
Issue Description:
SR-9494 mentions that
@autoclosure
shouldn't forward, however it is still possible to do that by wrapping it in a tuple and use type interference:Output from 5.0 snapshot
Practical problem
If the @autoclosure behaviour is forwarded without error, it leads to a crash when I try to record the argument:
The text was updated successfully, but these errors were encountered: