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

[SR-10753] DefaultStringInterpolation cannot be used as an argument for DynamicCallable #53143

Closed
CaptainYukinoshitaHachiman mannequin opened this issue May 22, 2019 · 6 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software interpolated strings Feature → expressions → literals → string literals: interpolated strings type checker Area → compiler: Semantic analysis

Comments

@CaptainYukinoshitaHachiman
Copy link
Mannequin

Previous ID SR-10753
Radar None
Original Reporter @CaptainYukinoshitaHachiman
Type Bug
Status Resolved
Resolution Done
Environment

Using Xcode 10.2.1 (10E1001)

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, CompilerCrash, StringInterpolation, TypeChecker
Assignee @Azoy
Priority Medium

md5: 343644f230c23c4ddba5b778b5be0eeb

relates to:

  • SR-11594 Using StringInterpolation in PropertyWrapper closure fails (inout to non-inout error)

Issue Description:

Introduction

A compile-time error rises when using a string interpolation as an argument for dynamically callable func:

public func dynamicallyCall(withArguments arguments: [String])

Reproduction

@dynamicCallable
struct A {
    public func dynamicallyCall(withArguments arguments: [String]) {
        print(arguments)
    }
}

A()("hello")
// Output:
// ["hello"]

A()("\(1)")
// Output:
// error: 'inout DefaultStringInterpolation' is not convertible to 'DefaultStringInterpolation'
// error: 'inout DefaultStringInterpolation' is not convertible to 'DefaultStringInterpolation'
// error: 'inout DefaultStringInterpolation' is not convertible to 'DefaultStringInterpolation'
@ApolloZhu
Copy link
Collaborator

Compiler error with swift-DEVELOPMENT-SNAPSHOT-2019-05-20-a-osx toolchain:

Assertion failed: (!t || !t->is<InOutType>() && "set flags instead"), function Param, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/include/swift/AST/Types.h, line 2688.

Stack dump:

0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-05-20-a.xctoolchain/usr/bin/swift -frontend -interpret a.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name a 
1.  Apple Swift version 5.1-dev (LLVM 082dec2e22, Swift 0fce7059a2)
2.  While type-checking statement at [a.swift:8:1 - line:8:11] RangeText="A()("\(1)""
3.  While type-checking expression at [a.swift:8:1 - line:8:11] RangeText="A()("\(1)""
4.  While type-checking statement at [a.swift:8:5 - line:8:11] RangeText=""\(1)""
5.  While type-checking expression at [a.swift:8:5 - line:8:5] RangeText=""
0  swift                    0x00000001070b6f45 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001070b6205 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001070b7528 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff5ef86b5d _sigtramp + 29
4  libsystem_platform.dylib 0x000000010d041938 _sigtramp + 2920001016
5  libsystem_c.dylib        0x00007fff5ee406a6 abort + 127
6  libsystem_c.dylib        0x00007fff5ee0920d basename_r + 0
7  swift                    0x0000000103fd365f swift::constraints::ConstraintSystem::getTypeOfMemberReference(swift::Type, swift::ValueDecl*, swift::DeclContext*, bool, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclRefExpr const*, llvm::DenseMap<swift::GenericTypeParamType*, swift::TypeVariableType*, llvm::DenseMapInfo<swift::GenericTypeParamType*>, llvm::detail::DenseMapPair<swift::GenericTypeParamType*, swift::TypeVariableType*> >*) + 4111
8  swift                    0x0000000103fd4472 swift::constraints::ConstraintSystem::resolveOverload(swift::constraints::ConstraintLocator*, swift::Type, swift::constraints::OverloadChoice, swift::DeclContext*) + 514
9  swift                    0x0000000103f50821 swift::ASTVisitor<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void>::visit(swift::Expr*) + 22593
10 swift                    0x0000000103f4ad05 (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 389
11 swift                    0x00000001043598bb (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 123
12 swift                    0x00000001043568d4 swift::Expr::walk(swift::ASTWalker&) + 84
13 swift                    0x0000000103f46662 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 418
14 swift                    0x0000000103f8120b swift::constraints::ConstraintSystem::solveImpl(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 475
15 swift                    0x0000000103f80d76 swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 486
16 swift                    0x0000000104042cef swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 927
17 swift                    0x000000010404293f swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
18 swift                    0x00000001040e3de6 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 614
19 swift                    0x00000001040e2d68 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
20 swift                    0x00000001040e2c93 swift::TypeChecker::typeCheckTapBody(swift::TapExpr*, swift::DeclContext*) + 179
21 swift                    0x0000000103efd50f swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 687
22 swift                    0x0000000104042d7a swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1066
23 swift                    0x000000010404293f swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
24 swift                    0x00000001040e3de6 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 614
25 swift                    0x00000001040e2d68 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
26 swift                    0x00000001040e2e7e swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 174
27 swift                    0x0000000104105212 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 930
28 swift                    0x000000010384a1d6 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 502
29 swift                    0x0000000103848e56 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 342
30 swift                    0x0000000103848647 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 615
31 swift                    0x00000001036124cf performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1615
32 swift                    0x0000000103610e22 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
33 swift                    0x00000001035b7199 main + 729
34 libdyld.dylib            0x00007fff5ed9b3d5 start + 1
Abort trap: 6

@belkadan
Copy link
Contributor

brentdax (JIRA User), dan-zheng (JIRA User), any ideas?

@dan-zheng
Copy link
Collaborator

Unfortunately, I don't have time to look into this for a while. This bug was fixed in #22366 on the tensorflow branch, but the changes were never upstreamed to master. (cc pschuh (JIRA User) who wrote the patch)

If someone has time, upstreaming the changes to finishApplyDynamicCallable from the tensorflow branch should fix this issue.


Previously, finishApplyDynamicCallable constructed a new untyped ApplyExpr, then ran TypeChecker::typeCheckExpression on it to type it. The call to typeCheckExpression is not only expensive but also produces bugs, like this one.

With the patch, finishApplyDynamicCallable sets subexpression types while building the new ApplyExpr.

@belkadan
Copy link
Contributor

belkadan commented Jul 8, 2019

@Azoy, think we should we cherry-pick this for 5.1? Or is it too risky?

@Azoy
Copy link
Member

Azoy commented Jul 8, 2019

I don't know exactly what would be considered too risky, but it might be nice to get this in because of a number of bug reports for this feature.

@Azoy
Copy link
Member

Azoy commented Jul 8, 2019

I went ahead and made a cherry pick for 5.1 just in case here: #26004

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software interpolated strings Feature → expressions → literals → string literals: interpolated strings type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants