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-11601] Assert in relabelParams when tuple is returned by generic function #54006

Closed
swift-ci opened this issue Oct 10, 2019 · 3 comments
Closed
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 good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11601
Radar None
Original Reporter owenvoorhees (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

master @ b32e82c

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, StarterBug, TypeChecker
Assignee owenvoorhees (JIRA)
Priority Medium

md5: 355829bd1c225783feb99cb5920b2d0d

Issue Description:

The following code is clearly incorrect:

func test2<T>(_ any: T) -> T { return any }
func test(x: Int, y: Int) {
  print(x,y)
}


let tuple = (3, 4)
test(test2((3,4)))

But, it hits an assert in the compiler on master instead of reporting an error (I tested on 5.1 and didn't see a crash):

Assertion failed: (params.size() == labels.size()), function relabelParams, file /Users/owenvoorhees/Documents/Development/swift-source/swift/lib/AST/ASTContext.cpp, line 2977.Assertion failed: (params.size() == labels.size()), function relabelParams, file /Users/owenvoorhees/Documents/Development/swift-source/swift/lib/AST/ASTContext.cpp, line 2977.Stack dump:0. Program arguments: /Users/owenvoorhees/Documents/Development/swift-source/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret /Users/owenvoorhees/Desktop/hello.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name hello1. Swift version 5.1.1-dev (LLVM d1510a2b47, Swift b32e82c720)2. While type-checking statement at [/Users/owenvoorhees/Desktop/hello.swift:9:1 - line:9:12] RangeText="test(*tuple"3. While type-checking expression at [/Users/owenvoorhees/Desktop/hello.swift:9:1 - line:9:12] RangeText="test(*tuple"0  swift                    0x0000000106331865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 371  swift                    0x0000000106330868 llvm::sys::RunSignalHandlers() + 2482  swift                    0x0000000106331e58 SignalHandler(int) + 2643  libsystem_platform.dylib 0x00007fff70420b1d _sigtramp + 294  libsystem_platform.dylib 0x00000001116a8268 _sigtramp + 27037837845  libsystem_c.dylib        0x00007fff702f6a08 abort + 1206  libsystem_c.dylib        0x00007fff702f5cc2 err + 07  swift                    0x0000000106706563 swift::AnyFunctionType::relabelParams(llvm::MutableArrayRef<swift::AnyFunctionType::Param>, llvm::ArrayRef<swift::Identifier>) (.cold.4) + 358  swift                    0x0000000103113f34 swift::AnyFunctionType::relabelParams(llvm::MutableArrayRef<swift::AnyFunctionType::Param>, llvm::ArrayRef<swift::Identifier>) + 2449  swift                    0x0000000102cc831f (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 787110 swift                    0x0000000102cb4586 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 8611 swift                    0x0000000102d74898 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 170412 swift                    0x0000000102d0dc4c swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 50813 swift                    0x0000000102de4aa3 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 99514 swift                    0x0000000102de46af swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 6315 swift                    0x0000000102e84309 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 56916 swift                    0x0000000102e82c88 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 13617 swift                    0x0000000102e82d85 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 18118 swift                    0x0000000102eafa32 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 168219 swift                    0x00000001026070c9 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 48920 swift                    0x0000000102605d57 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 51921 swift                    0x000000010260555d swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 62122 swift                    0x00000001023ebec2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 165023 swift                    0x00000001023ea8e6 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 304624 swift                    0x000000010238fe89 main + 72925 libdyld.dylib            0x00007fff7021f405 start + 126 libdyld.dylib            0x000000000000000a start + 2413693958Abort trap: 6

And if I run with `-debug-constraints`, I see:

---Constraint solving for the expression at [/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12]---
  (overload set choice binding $T0 := ($T1) -> $T1)
  (overload set choice binding $T2 := (Int, Int))
---Initial constraints for the given expression---
(paren_expr type='($T1)' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12]
  (prefix_unary_expr type='$T1' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:6 - line:9:7]
    (declref_expr type='($T1) -> $T1' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:6 - line:9:6] decl=hello.(file).*@/Users/owenvoorhees/Desktop/hello.swift:2:13 function_ref=unapplied)
    (paren_expr implicit type='((Int, Int))' location=/Users/owenvoorhees/Desktop/hello.swift:9:7 range=[/Users/owenvoorhees/Desktop/hello.swift:9:7 - line:9:7]
      (declref_expr type='(Int, Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:7 range=[/Users/owenvoorhees/Desktop/hello.swift:9:7 - line:9:7] decl=hello.(file).tuple@/Users/owenvoorhees/Desktop/hello.swift:8:5 function_ref=unapplied))))
Score: 0 0 0 0 0 0 0 0 0 0 0 0
Contextual Type: (x: Int, y: Int)
Type Variables:
  $T0 [lvalue allowed] [noescape allowed] as ($T1) -> $T1 @ locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6]
  $T1 potentially_incomplete bindings={(supertypes of) (Int, Int); (subtypes of) (x: Int, y: Int)} @ locator@0x119122c50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> generic parameter 'T']
  $T2 [lvalue allowed] [noescape allowed] as (Int, Int) @ locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7]
  $T3 [noescape allowed] equivalent to $T1 @ locator@0x119122e08 [PrefixUnary@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> function result]


Active Constraints:
  (Int, Int) operator arg conv $T1 [[locator@0x119122ed8 [PrefixUnary@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> apply argument -> comparing call argument #&#8203;0 to parameter #&#8203;0]]];


Inactive Constraints:
  $T1 arg conv (x: Int, y: Int) [[locator@0x119122f80 [Paren@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> contextual type]]];
Resolved overloads:
  selected overload set choice tuple: $T2 == (Int, Int)
  selected overload set choice *: $T0 == ($T1) -> $T1




Opened types:
  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] opens τ_0_0 -> $T1
  ($T1 potentially_incomplete bindings={(supertypes of) (Int, Int); (subtypes of) (x: Int, y: Int)})
  Initial bindings: $T1 := (Int, Int), $T1 := (x: Int, y: Int)
  (attempting type variable $T1 := (Int, Int)
    (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
  )
  (attempting type variable $T1 := (x: Int, y: Int)
    (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
  )
---Solver statistics---
Total number of scopes explored: 3
Maximum depth reached while exploring solutions: 2
Time: 1.846400e+01ms
Comparing 2 viable solutions
--- Solution #&#8203;0 ---
Fixed score: 0 0 0 0 0 0 0 0 0 0 0 0
Type variables:
  $T2 as (Int, Int) @ locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7]
  $T1 as (Int, Int) @ locator@0x119122c50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> generic parameter 'T']
  $T0 as ((Int, Int)) -> (Int, Int) @ locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6]
  $T3 as (Int, Int) @ locator@0x119122e08 [PrefixUnary@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> function result]


Overload choices:
  locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7] with hello.(file).tuple@/Users/owenvoorhees/Desktop/hello.swift:8:5 as tuple: (Int, Int)


  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] with hello.(file).*@/Users/owenvoorhees/Desktop/hello.swift:2:13 as *: ($T1) -> $T1




Constraint restrictions:


Disjunction choices:


Opened types:
  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] opens τ_0_0 -> $T1
--- Solution #&#8203;1 ---
Fixed score: 0 0 0 0 0 0 0 0 0 0 0 0
Type variables:
  $T2 as (Int, Int) @ locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7]
  $T1 as (x: Int, y: Int) @ locator@0x119122c50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> generic parameter 'T']
  $T0 as ((x: Int, y: Int)) -> (x: Int, y: Int) @ locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6]
  $T3 as (x: Int, y: Int) @ locator@0x119122e08 [PrefixUnary@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> function result]


Overload choices:
  locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7] with hello.(file).tuple@/Users/owenvoorhees/Desktop/hello.swift:8:5 as tuple: (Int, Int)


  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] with hello.(file).*@/Users/owenvoorhees/Desktop/hello.swift:2:13 as *: ($T1) -> $T1




Constraint restrictions:


Disjunction choices:


Opened types:
  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] opens τ_0_0 -> $T1
comparing solutions 1 and 0
  (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
  (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
comparing solutions 0 and 1
  (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
  (found solution 0 0 0 0 0 0 0 0 0 0 0 0)
---Solution---
Fixed score: 0 0 0 0 0 0 0 0 0 0 0 0
Type variables:
  $T2 as (Int, Int) @ locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7]
  $T1 as (Int, Int) @ locator@0x119122c50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> generic parameter 'T']
  $T0 as ((Int, Int)) -> (Int, Int) @ locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6]
  $T3 as (Int, Int) @ locator@0x119122e08 [PrefixUnary@/Users/owenvoorhees/Desktop/hello.swift:9:6 -> function result]


Overload choices:
  locator@0x119122d50 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:7] with hello.(file).tuple@/Users/owenvoorhees/Desktop/hello.swift:8:5 as tuple: (Int, Int)


  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] with hello.(file).*@/Users/owenvoorhees/Desktop/hello.swift:2:13 as *: ($T1) -> $T1




Constraint restrictions:


Disjunction choices:


Opened types:
  locator@0x119122c00 [DeclRef@/Users/owenvoorhees/Desktop/hello.swift:9:6] opens τ_0_0 -> $T1
---Type-checked expression---
(destructure_tuple_expr implicit type='(x: Int, y: Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] destructured=(
    (opaque_value_expr implicit type='Int' location=/Users/owenvoorhees/Desktop/hello.swift:9:5 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] @ 0x11b207e90)
    (opaque_value_expr implicit type='Int' location=/Users/owenvoorhees/Desktop/hello.swift:9:5 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] @ 0x11b207eb8))
  (paren_expr type='((Int, Int))' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12]
    (prefix_unary_expr type='(Int, Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:6 - line:9:7]
      (declref_expr type='((Int, Int)) -> (Int, Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:6 range=[/Users/owenvoorhees/Desktop/hello.swift:9:6 - line:9:6] decl=hello.(file).*@/Users/owenvoorhees/Desktop/hello.swift:2:13 [with (substitution_map generic_signature=<T> (substitution T -> (Int, Int)))] function_ref=unapplied)
      (paren_expr implicit type='((Int, Int))' location=/Users/owenvoorhees/Desktop/hello.swift:9:7 range=[/Users/owenvoorhees/Desktop/hello.swift:9:7 - line:9:7]
        (declref_expr type='(Int, Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:7 range=[/Users/owenvoorhees/Desktop/hello.swift:9:7 - line:9:7] decl=hello.(file).tuple@/Users/owenvoorhees/Desktop/hello.swift:8:5 function_ref=unapplied))))
  (tuple_expr implicit type='(x: Int, y: Int)' location=/Users/owenvoorhees/Desktop/hello.swift:9:5 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] names=x,y
    (opaque_value_expr implicit type='Int' location=/Users/owenvoorhees/Desktop/hello.swift:9:5 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] @ 0x11b207e90)
    (opaque_value_expr implicit type='Int' location=/Users/owenvoorhees/Desktop/hello.swift:9:5 range=[/Users/owenvoorhees/Desktop/hello.swift:9:5 - line:9:12] @ 0x11b207eb8)))
Assertion failed: (params.size() == labels.size()), function relabelParams, file /Users/owenvoorhees/Documents/Development/swift-source/swift/lib/AST/ASTContext.cpp, line 2977.
@theblixguy
Copy link
Collaborator

cc @xedin

@xedin
Copy link
Member

xedin commented Oct 11, 2019

Ah interesting, this is a reverse tuple splat 🙂 It's going to be fixed once I get my extraneous arguments PR ready, hopefully very soon...

@xedin
Copy link
Member

xedin commented Feb 19, 2020

Looks like this has been fixed on master. Produces following diagnostic:

error: missing argument for parameter 'y' in call
test(test2((3,4)))
                 ^
                 , y: <#Int#>
<REPL Input>:1:6: note: 'test(x:y:)' declared here
func test(x: Int, y: Int) {
     ^

@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 good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants