Skip to content

[TypeChecker] Always emit a fallback error if type-check failed witho… #21517

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

Merged
merged 3 commits into from
Jan 8, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Dec 22, 2018

…ut producing one

Sometimes constraint solver fails without producing any diagnostics,
it could happen during different phases e.g. pre-check, constraint
generation, or even while attempting to apply solution. Such behavior
leads to crashes down the line in AST Verifier or SILGen which are
hard to diagnose.

Let's guard against that by tracking if solver produced any diagnostics
upon its failure and if no errors were or are scheduled to be produced,
let's produce a fallback fatal error pointing at affected expression.

Resolves: rdar://problem/38885760

@xedin xedin requested review from rudkx and DougGregor December 22, 2018 01:55
@slavapestov
Copy link
Contributor

Can we add a test for this by adding some special kind of Expr or Builtin call that fails in the solver but CSDiag intentionally does not emit an error for?

@xedin
Copy link
Contributor Author

xedin commented Dec 22, 2018

Sure, it seems like the only way to go trying to test this.

@xedin
Copy link
Contributor Author

xedin commented Jan 3, 2019

Added Builtin.trigger_fallback_diagnostic and a test which verifies that fallback fatal error is produced when CSGen fails without returning any diagnostic.

@xedin
Copy link
Contributor Author

xedin commented Jan 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - be77c7fcf17f7539fa7db851e0b49c72c4f39917

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - be77c7fcf17f7539fa7db851e0b49c72c4f39917

@xedin
Copy link
Contributor Author

xedin commented Jan 3, 2019

Slightly edited comment in CSGen, let's re-run the tests...

@xedin
Copy link
Contributor Author

xedin commented Jan 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 7ee85635a962205e11ac6bb55bf548ed6d1151a2

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 7ee85635a962205e11ac6bb55bf548ed6d1151a2

@xedin
Copy link
Contributor Author

xedin commented Jan 3, 2019

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Jan 4, 2019

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jan 4, 2019

/cc @DougGregor @rudkx Could you guys please take a look?

@swift-ci
Copy link
Contributor

swift-ci commented Jan 4, 2019

Build failed
Swift Test Linux Platform
Git Sha - ebaf97e4bb72baee4015100fa01911fccd9a7acb

@swift-ci
Copy link
Contributor

swift-ci commented Jan 4, 2019

Build failed
Swift Test OS X Platform
Git Sha - ebaf97e4bb72baee4015100fa01911fccd9a7acb

// Before producing fatal error here, let's check if there are any "error"
// diagnostics already emitted or waiting to be emitted. Because they are
// a better indication of the problem.
if (!(hadAnyErrors() || TC.Context.hasDelayedConformanceErrors()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm confused as to why we have both the TC.Context.hasDelayedConformanceErrors() check and the specific isInvalid() checks above. Doesn't this one suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the situation I came up with was - solution application failed without diagnostic and it was unrelated to invalid conformances in the current expression, but we already had errors like that record by previous expressions so instead of producing fatal error here, let's just keep going since when delayed conformances are processed they are going to produce one or more errors anyway...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay!

xedin added 3 commits January 7, 2019 10:42
…ut producing one

Sometimes constraint solver fails without producing any diagnostics,
it could happen during different phases e.g. pre-check, constraint
generation, or even while attempting to apply solution. Such behavior
leads to crashes down the line in AST Verifier or SILGen which are
hard to diagnose.

Let's guard against that by tracking if solver produced any diagnostics
upon its failure and if no errors were or are scheduled to be produced,
let's produce a fallback fatal error pointing at affected expression.

Resolves: rdar://problem/38885760
* Incomplete conformance is not necessarily going to produce a diagnostic
* Use `userFacingName` to avoid assert related to special names.
@xedin
Copy link
Contributor Author

xedin commented Jan 7, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - 8310a44bbaf5095c9f3942d1a0f2d65141b29e1f

@swift-ci
Copy link
Contributor

swift-ci commented Jan 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - 8310a44bbaf5095c9f3942d1a0f2d65141b29e1f

@xedin
Copy link
Contributor Author

xedin commented Jan 8, 2019

@swift-ci please test source compatibility

@xedin xedin merged commit 65abb49 into swiftlang:master Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants