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-9239] Crash with default argument in initializer for @dynamicCallable struct #51727

Closed
harlanhaskins opened this issue Nov 14, 2018 · 5 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

Comments

@harlanhaskins
Copy link
Collaborator

Previous ID SR-9239
Radar None
Original Reporter @harlanhaskins
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @Azoy
Priority Medium

md5: 1af6665a70d50a07649e5533d9613bc5

Issue Description:

@dynamicCallable
struct A {
  init(_ x: Int = 0) {}
  func dynamicallyCall(withArguments args: [Int]) {}
}

A()()

The above code trips this assertion while constraint solving:

/tmp/init.swift:7:1: error: type of expression is ambiguous without more context
A()()
^~~
Assertion failed: (hasType(E) && "Expected type to have been set!"), function getType, file /Users/harlan/Swift/swift/lib/Sema/ConstraintSystem.h, line 1683.
Stack dump:
0.  Program arguments: /Users/harlan/Swift/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -emit-sil -primary-file /tmp/init.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -color-diagnostics -module-name init -o - 
1.  While type-checking statement at [/tmp/init.swift:7:1 - line:7:5] RangeText="A()("
2.  While type-checking expression at [/tmp/init.swift:7:1 - line:7:5] RangeText="A()("
0  swift                    0x00000001043dd425 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001043dc408 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x00000001043dda32 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff681c7b3d _sigtramp + 29
4  swift                    0x00000001056d8be5 cmark_strbuf__initbuf + 133936
5  libsystem_c.dylib        0x00007fff680851c9 abort + 127
6  libsystem_c.dylib        0x00007fff6804d868 basename_r + 0
7  swift                    0x000000010154af94 swift::constraints::ConstraintSystem::getType(swift::Expr const*) const + 356
8  swift                    0x0000000101423937 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 55
9  swift                    0x0000000101850a16 swift::Expr::walk(swift::ASTWalker&) + 118
10 swift                    0x000000010141b3ae swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 510
11 swift                    0x000000010154abb0 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1136
12 swift                    0x00000001015dee08 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 600
13 swift                    0x00000001015ddfc8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
14 swift                    0x00000001015de0de swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 174
15 swift                    0x00000001015feb8e swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 846
16 swift                    0x0000000100dc8c3c swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 492
17 swift                    0x0000000100dc75c3 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 435
18 swift                    0x0000000100dc6c87 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 615
19 swift                    0x000000010051fd88 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1192
20 swift                    0x000000010051e878 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3016
21 swift                    0x00000001004d0962 main + 690
22 libdyld.dylib            0x00007fff67fdcef9 start + 1
@harlanhaskins
Copy link
Collaborator Author

cc: @dan-zheng

@dan-zheng
Copy link
Collaborator

Thanks for the discovery! I'm a bit flooded this week but I might take a look later.

@dan-zheng
Copy link
Collaborator

Thanks for taking this on @Azoy!
Just a heads up: this bug seems to be solved on the tensorflow branch by a @dynamicCallable-related PR that hasn't yet been upstreamed to master: #22366
I just verified that the reproducer program compiles fine.

So a fix should just involve upstreaming the PR to master. Would you like to take that on? FYI, that is the only non-upstreamed @dynamicCallable PR. Everything else should be in sync.

cc pschuh (JIRA User), the original PR author

@dan-zheng
Copy link
Collaborator

Update: it seems @Azoy has already done the work to fix the bug! Please see my PR comment about unifying code across branches.

@Azoy: would you like to be an angel and help us unify code? It should just be a matter of copy-pasting code changes from master to tensorflow.

@dan-zheng
Copy link
Collaborator

FYI, I just filed SR-10331, another @dynamicCallable-related bug - sharing here for visibility to prevent further duplicate work.

@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
Projects
None yet
Development

No branches or pull requests

3 participants