Skip to content

NFC for SR-12085 Clean up TypeCheckType so it never returns Type(). #29780

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

Closed
wants to merge 1 commit into from

Conversation

dfsweeney
Copy link
Contributor

Added ErrorType::get(Context) to TypeCheckType.cpp and clients.
Replaced assertions checking for null pointers with type->hasError() checks.
Note that getDynamicBridgedThroughObjCClass can still return null pointers so
the assert checks are still there for callers.

No functional change. This cleans up some instances of return Type() in TypeCheckType.cpp. There are a lot of other instances of return Type() but this gets the 15 of them in TypeCheckType.cpp plus a few others in direct clients to the functions in TypeCheckType.cpp that returned Type(). @CodaFi helped me with this.

This is my first one so I'm not sure I'm doing it right. Running all the validation tests gives me:

Expected Passes    : 6490
Expected Failures  : 5
Unsupported Tests  : 100
Unexpected Failures: 205

both before and after this change when I build with ninja. A lot of the validation test failures are in stdlib--I am not sure why.

The two validation test failures in Sema are:

Swift(macosx-x86_64) :: Sema/type_checker_perf/fast/rdar42672946.swift
Swift(macosx-x86_64) :: Sema/type_checker_perf/slow/rdar23327871.swift.gyb

I checked out swift-DEVELOPMENT-SNAPSHOT-2020-02-08-a and then put the commit directly on top of that. I hope that is OK--I tried a couple of things but that seemed to build clean.

Resolves SR-12085.

@owenv
Copy link
Contributor

owenv commented Feb 12, 2020

@dfsweeney Welcome to the project! Depending on your build setup, it's not unusual for many of the validation tests to fail locally trying to import StdlibCollectionUnitTest, which may be the case here. Those two Sema tests are both performance tests, so it's possible those are local-only failures too, but I'm less sure.

Let's try running tests on CI and see what happens.

@owenv
Copy link
Contributor

owenv commented Feb 12, 2020

@swift-ci please smoke test

@owenv owenv requested a review from CodaFi February 12, 2020 04:56
@dfsweeney
Copy link
Contributor Author

I found a bug I introduced that caused the smoke test to fail in 4 tests. Note I still have one failure in tests, in Parse/operators.swift. I'm working on that one. A lot of the validation tests are failing on import StdlibCollectionUnittest where the module is not found. I probably need to add something to the build-script to figure that out.

@dfsweeney
Copy link
Contributor Author

Cleared up one of the errors in Parse/operators.swift. Still getting

 /Users/dfs/swift-source/swift/test/Parse/operators.swift:125:5: error: unexpected error produced: broken standard library: cannot find intrinsic operations on Optional<T> foo??bar // expected-error{{broken standard library}} expected-error{{consecutive statements}} {{6-6=;}}

The pattern of returning Type() and then checking the result for null is pretty common. I thought I got all the clients of the original 15 in TypeCheckType but they propagate up and down the call chain. In general replacing

if (!type)

with

if (!type || type->hasError())

keeps the logic in the same flow, but it's pretty easy to miss that and then let the execution run into code that does other things. Sometimes you get a diagnostic that triggers a test failure, but I'm not sure there's 100% coverage.

If I can figure out where I missed a check that's causing the one remaining test failure the patch would run clean, but I'm a little worried that this might cause more problems at a distance.

@CodaFi
Copy link
Contributor

CodaFi commented Feb 14, 2020

You can assert as a postcondition inside the APIs you convert then. Asserting in the clients is gonna be a game of whack-a-mole, as you’ve already discovered.

@dfsweeney
Copy link
Contributor Author

I cleared the last warning in the tests.

@swift-ci please smoke test

@dfsweeney
Copy link
Contributor Author

(I'm not sure if I can trigger a smoke test myself, if not can one of you please start it? Thanks!)

@theblixguy
Copy link
Collaborator

Only people with commit access can.

@swift-ci please test

@dfsweeney
Copy link
Contributor Author

Thanks!

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@dfsweeney
Copy link
Contributor Author

I rebased these on top of the swift-5.2-branch locally. (There was one merge conflict that I had to clear up. it builds and all the tests pass.) Can I push that to the branch for this pull request or will things really get weird? I think it would change the base branch for the pull request and I don't know if that's OK or not in GitHub land. Any ideas?

@CodaFi
Copy link
Contributor

CodaFi commented Feb 17, 2020

I rebased these on top of the swift-5.2-branch locally.

You shouldn't rebase on top of a release branch. Master is where this patch is going to land, and if we need to cherry-pick it, we'll do it from there. 5.2 is missing a whole heckuva lot of commits.

@dfsweeney
Copy link
Contributor Author

Thanks for reviewing! I replied to each of the above, I'm pretty sure I understand but it helps to write it out. Sorry for the message generation. For the basing/rebasing, should I rebase this on to master and push it to the branch associated with the pull request? I was having some trouble getting the master branch to build.

I will work through the changes above.

@CodaFi
Copy link
Contributor

CodaFi commented Feb 18, 2020

For the basing/rebasing, should I rebase this on to master and push it to the branch associated with the pull request?

You shouldn't need to keep rebasing unless there's merge conflicts you have to resolve. But if you need to, pull and rebase onto master. I usually set a remote called upstream that points to Apple's copy of swift and run

$ git pull --rebase upstream master --autostash

every so often to keep in sync.

I was having some trouble getting the master branch to build.

Do you have any logs or errors to share?

@dfsweeney
Copy link
Contributor Author

Thanks again! wrt the build problems, I was not using the swift/master branch of llvm, which made a lot of stuff flip out. At some point I just checked out the master branch (without swift/). Just one of those things getting used to a project, finding things you can break by accident. I am doing something like what you have above with an upstream branch. I am pushing through the rest of the above.

@dfsweeney dfsweeney closed this Feb 18, 2020
@dfsweeney dfsweeney deleted the sr12085_2 branch February 18, 2020 23:01
@dfsweeney dfsweeney restored the sr12085_2 branch February 18, 2020 23:02
@dfsweeney
Copy link
Contributor Author

ok that's not what I wanted to happen, I think I left something out of the git push.

@dfsweeney dfsweeney reopened this Feb 18, 2020
Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

My high-level comment remains the same: The asserts about structural properties need to come out. If they cannot be removed with confidence, perhaps we should break this PR down into smaller pieces and work from the leaf functions up incrementally.

@dfsweeney
Copy link
Contributor Author

I cleared the structural assertions and pushed up but something looks weird about this--now it says that I want to merge 945 commits, which looks wrong. Anyway, can somebody fire off the checks at least? I will try to figure out what I did or did not do. If necessary I can close this PR and open a new one but then the history will be lost.

@CodaFi
Copy link
Contributor

CodaFi commented Mar 11, 2020

I believe you pulled without a rebase. Try

git pull --rebase upstream master

Where upstream is a remote entry pointing to apple/swift

@CodaFi
Copy link
Contributor

CodaFi commented Mar 30, 2020

There's some good cleanups in here. If we chunk this apart, I think we can merge them in this order:

  • The Parameter cleanup in TypeCheckType
  • The known stdlib decls bits

The rest require more infrastructure be converted first - I don't feel comfortable doing this completely piecemeal. We should work from the leaves (like the known stdlib decls parts) up.

@dfsweeney
Copy link
Contributor Author

I agree with you, there's a lot of infrastructure going on. I will leave in the Parameter cleanup and the changes that don't depend on client behavior and take out the changes that rely too much on what the callers do, if that makes sense.

@dfsweeney
Copy link
Contributor Author

I rebuilt this with git reset/git add -p and force-updated the branch. This should have only the straightforward changes and not the other stuff we've been talking about. @CodaFi please let me know if I left anything in there that you don't expect or vice versa. Thanks!

@CodaFi
Copy link
Contributor

CodaFi commented Apr 22, 2020

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 38c3cf350cc89d4de5e5685c441e574ded81d281

@dfsweeney
Copy link
Contributor Author

dfsweeney commented Apr 23, 2020 via email

@CodaFi
Copy link
Contributor

CodaFi commented Apr 23, 2020

Builder died

@swift-ci test macOS

@varungandhi-apple
Copy link
Contributor

@CodaFi is this good to merge?

@varungandhi-apple
Copy link
Contributor

Oof, there's a merge conflict now @dfsweeney 😬

@dfsweeney
Copy link
Contributor Author

dfsweeney commented May 1, 2020 via email

@CodaFi
Copy link
Contributor

CodaFi commented May 2, 2020

@dfsweeney Apologies for leaving this by the wayside - and for causing all of these merge conflicts. I believe I'm done messing around with type resolution for the time being. If you'd like, I can cherry-pick and shepherd this patch through myself and have you review the changes.

@CodaFi
Copy link
Contributor

CodaFi commented May 2, 2020

To get some context down: I'm in the process of converting the mutating usages of TypeLoc into either requests or just breaking apart the TypeLoc. I was hoping we could merge this patch as a capstone to that refactoring process, but there have been intervening issues in TypeCheckType that required my immediate attention lately.

@dfsweeney
Copy link
Contributor Author

Hi @CodaFi it's all good, a lot of things are going on.

I just force-pushed again to clear the merge conflict. There are a couple of llvm_unreachables in TypeCheckType.cpp that I have been hoping I would think of a better solution for.

If you could cherry-pick it through that would be great! Let me know what you need me to do. Thanks!

@CodaFi
Copy link
Contributor

CodaFi commented May 7, 2020

@swift-ci test

@swiftlang swiftlang deleted a comment from swift-ci May 7, 2020
Replaced "return Type();" in TypeChecker::getXType() methods in
TypeCheckType.cpp with "return ErrorType.get(ctx);" along with
appropriate diagnostics. Type() is equivalent to nullptr. Cleaned up
clients to test for Type->hasError rather than nullptr.
@dfsweeney
Copy link
Contributor Author

I fixed that one spot where we crossed wires on the ASTContext parameter from TypeChecker::validateType.

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - 82c5d64cf1d5b57bf57c004739ed4d033999e7cc

@theblixguy
Copy link
Collaborator

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2020

Build failed
Swift Test Linux Platform
Git Sha - 82c5d64cf1d5b57bf57c004739ed4d033999e7cc

@CodaFi
Copy link
Contributor

CodaFi commented Jun 11, 2020

Hey @dfsweeney, I finally cleared the blocker to doing this refactoring. I've taken this patch as the basis for a cleanup in #32321. I'm gonna close this out. Please feel free to review the linked PR if you have some time.

@CodaFi CodaFi closed this Jun 11, 2020
@dfsweeney
Copy link
Contributor Author

Thanks! I'm glad this finally came in for a landing.

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.

6 participants