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-13421] Type checker regression and crash in Xcode 12 beta 5 #55862

Open
rastersize opened this issue Aug 19, 2020 · 4 comments
Open

[SR-13421] Type checker regression and crash in Xcode 12 beta 5 #55862

rastersize opened this issue Aug 19, 2020 · 4 comments
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 regression swift 5.3 type checker Area → compiler: Semantic analysis

Comments

@rastersize
Copy link

Previous ID SR-13421
Radar rdar://67417121
Original Reporter @rastersize
Type Bug
Environment
  • Xcode 12 beta 5 (12A8189h)

  • Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1) Target: x86_64-apple-darwin19.5.0

  • Nimble 8.1.1 and 9.0.0-rc.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.3Regression, CompilerCrash, Regression, TypeChecker
Assignee None
Priority Medium

md5: 34d150037f0b6c1807d377f1be03a70c

relates to:

  • SR-12291 Regression in overload resolution

Issue Description:

The type checker in Swift distributed with Xcode 12 beta 5 fails on existing code (that has worked since at least Xcode 11). For smaller samples the type checker “just” fails with a Ambiguous use of 'expect', however for targets with more cases it causes a crash (see below for a stack trace).

I’ve also filed FB8464226 for this.

What did you do?

I installed Xcode 12 beta 5 and tried to build our existing (test) code:

expect {
    try JSONDecoder().decode(Model.self, from: data)
}.to(throwError())

What did you expect to happen?

I expected the code to compile.

What actually happened instead?

The code failed to compile with a `ambiguous use of 'expect'` error. With these two candidates:

  1. Sources/Nimble/DSL.swift#L1-L8

    • public func expect<T>(_ expression: @autoclosure @escaping () throws -> T?, file: FileString = #file, line: UInt = #line) -> Expectation<T>
  2. Sources/Nimble/DSL.swift#L10-L17

    • public func expect<T>(_ file: FileString = #file, line: UInt = #line, expression: @escaping () throws -> T?) -> Expectation<T>

Project that demonstrates the issue

https://github.com/rastersize/Xcode12Beta5Nimble

After cloning do the following:

  1. Run carthage.sh bootstrap

    • The script works around a Carthage bug with Xcode 12 beta 4+ and universal binaries. As newer versions of Xcode 12 will produce an arm64 slice for both the simulator and device, and a universal binary can’t contain two slices for the same architecture.
  2. Open the Xcode project

  3. Build for testing

Workaround

Change the call-site of expect to specify using the non-autoclosure function. That is:

expect(expression: {
    try JSONDecoder().decode(SomeModel.self, from: data)
}).to(throwError())

Not as pretty but it works for now.

Stack trace from crash

9.  While type-checking expression at [/Users/<redacted>/DecodableOptionalTests.swift:18:21 - line:18:120] RangeText="expect { try decoder.decode(TestModel.self, from: decodeOptionallyValidData()) }.toNot(throwError()"
0  swift                    0x00000001082a1a85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001082a0a85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001082a203f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff712ff5fd _sigtramp + 29
4  libsystem_kernel.dylib   0x00007fff7124b35e __ioctl + 10
5  swift                    0x0000000104aed413 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ConcreteDeclRef, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, swift::constraints::ConstraintLocatorBuilder) + 8899
6  swift                    0x0000000104aea352 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder) + 11970
7  swift                    0x0000000104af5b5d (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 477
8  swift                    0x0000000104accb02 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 18
9  swift                    0x0000000104ac31e3 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 371
10 swift                    0x0000000104ac2ed0 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 6400
11 swift                    0x0000000104cabf1a swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1242
12 swift                    0x0000000104cab988 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 360
13 swift                    0x0000000104d90e4b swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 9115
14 swift                    0x0000000104d8c69a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
15 swift                    0x0000000104d8c373 swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 387
16 swift                    0x0000000104ac2f0a swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 6458
17 swift                    0x0000000104cabf1a swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1242
18 swift                    0x0000000104cab988 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 360
19 swift                    0x0000000104d90e4b swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 9115
20 swift                    0x0000000104d8c69a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
21 swift                    0x0000000104d8c373 swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 387
22 swift                    0x0000000104ac2f0a swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 6458
23 swift                    0x0000000104cabf1a swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1242
24 swift                    0x0000000104cab988 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 360
25 swift                    0x0000000104d90e4b swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 9115
26 swift                    0x0000000104d8c69a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
27 swift                    0x0000000104d8b0a7 swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 2231
28 swift                    0x0000000104d93e7d llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 925
29 swift                    0x0000000104d8c148 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 440
30 swift                    0x0000000104dc9a84 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 1380
31 swift                    0x0000000104dcc699 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 953
32 swift                    0x0000000104dc9394 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 164
33 swift                    0x0000000103f44bab swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 6859
34 swift                    0x0000000103e0596d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6845
35 swift                    0x0000000103d8a277 main + 1255
36 libdyld.dylib            0x00007fff71106cc9 start + 1
error: Illegal instruction: 4 (in target '<redacted>Tests' from project '<redacted>')
@rastersize
Copy link
Author

A colleague of mine noted that this is likely due to the new “forward scan” behavior for trailing closures.

@typesanitizer
Copy link

@swift-ci create

@rastersize
Copy link
Author

Confirmed still a problem in Xcode 12 beta 6.

@typesanitizer
Copy link

cc @xedin

@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
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 regression swift 5.3 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants