Skip to content

Conversation

@HassanElDesouky
Copy link
Contributor

In this PR I removed all of the setInvalid()s from the TypeCheckDeclPrimary file and modified all of the test messages as discussed in both of these comments:

  1. [TypeChecker] <unknown> diagnostic location regarding Codable derived conformances #30824 (comment)
  2. [TypeChecker] <unknown> diagnostic location regarding Codable derived conformances #30824 (comment)

All of the tests pass locally on Ubuntu, however, there's only one test that I wasn't able to make it work and it's this test in Parse/enum.swift

I found out that the compiler crashes because of removing only the setInvalid() in the TypeCheckDeclPrimary at L721 If I didn't remove it this test will pass, however, the diagnostic will change for all of the other tests of course. I was thinking of removing this test which is causing the headache but of course, I'm sure that this is not the correct way to do it :)

How can I solve this?

cc @CodaFi @xedin @LucianoPAlmeida

#30824 aka #31037 Follow-up.

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.

Please only limit the removal to the part of TypeCheckDeclPrimary we discussed earlier. Some of these tests have regressed in diagnostic quality because of this change.

@HassanElDesouky
Copy link
Contributor Author

Please only limit the removal to the part of TypeCheckDeclPrimary we discussed earlier. Some of these tests have regressed in diagnostic quality because of this change.

I'm sorry, I thought you mean remove all of the setInvalid()s occurrences in the file. Anyways, I'll get back to it. However, what should I do about https://github.com/apple/swift/blob/master/test/Parse/enum.swift#L367?

@CodaFi
Copy link
Contributor

CodaFi commented Apr 17, 2020

If there's a crash because of a structural problem in the type checker, we need to address that at a more fundamental level. That may involve fixing up TypeCheckPattern to be more tolerant of invalid code.

@HassanElDesouky HassanElDesouky marked this pull request as draft April 19, 2020 00:13
@HassanElDesouky HassanElDesouky marked this pull request as ready for review April 22, 2020 13:15
@HassanElDesouky
Copy link
Contributor Author

Because of all of the regression that happened, I decided to remove only the setInvalid()s in this function, for now. https://github.com/apple/swift/blob/426583523e063be1ed75027044f56873b7b73183/lib/Sema/TypeCheckDeclPrimary.cpp#L483

The next thing was this test case which was causing a compiler crash

there's only one test that I wasn't able to make it work and it's this test in Parse/enum.swift https://github.com/apple/swift/blob/426583523e063be1ed75027044f56873b7b73183/test/Parse/enum.swift#L367

As @CodaFi pointed me, the problem was in the TypeCheckPattern file.

Why the compiler is crashing?
The compiler crash was caused by this assertion at
https://github.com/apple/swift/blob/426583523e063be1ed75027044f56873b7b73183/lib/Sema/TypeCheckPattern.cpp#L98

I think that's because at
https://github.com/apple/swift/blob/426583523e063be1ed75027044f56873b7b73183/lib/Sema/TypeCheckDeclPrimary.cpp#L721
was setting the redeclaration as invalid so when it goes into this line it will go into the if statement and the loop will skip over it. However now, after deleting the setInvalid line in TypeCheckDeclPrimary this if statement won't be true so it won't go into it and thus, fail in the assertion at L98 in TypeCheckPattern

My solution
My solution was just to delete the assertion line and everything went fine.

Diagnostics regressions
I think there's a regression in this file, however, I don't know how to fix it.
https://github.com/apple/swift/blob/2afd1b0027798e7c661c59771dbf4652fe119d00/test/TypeCoercion/overload_noncall.swift#L55

Sorry for the long summery, but I just wanted to share what I came to. :)

cc @CodaFi , @LucianoPAlmeida , @xedin

@HassanElDesouky HassanElDesouky requested a review from CodaFi April 22, 2020 14:10

if (auto *oe = dyn_cast<EnumElementDecl>(e)) {
// Ambiguities should be ruled out by parsing.
assert(!foundElement && "ambiguity in enum case name lookup?!");
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't just remove this assertion. This amounts to a non-trivial behavior change in this function - it's now going to break ambiguities by selecting the last returned result from a lookup. The trouble here isn't the assert, it's the

    if (e->isInvalid()) {
      continue;
    }

check guarding the filtering behavior. That condition was correct in 2016 when this was written, but is not great now that we've stabilized the computation of interface types and defined isInvalid in terms of it.

Copy link
Contributor

@CodaFi CodaFi Apr 23, 2020

Choose a reason for hiding this comment

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

I think this means this code just needs to become tolerant of duplicates (e.g. by diagnosing them?). Quite what that means exactly I'm not sure - I need to go page all of this back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean I might need to check for redeclarations in TypeCheckPattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for helping me. And Ramadan Kareem! 🙏 :)

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.

We're getting closer. I think you may have fallen down a bit of a rabbit hole - but that's not unexpected given how old this code is!

@CodaFi
Copy link
Contributor

CodaFi commented Apr 23, 2020

Regardless, let's see what happens, eh?

@swift-ci test

@CodaFi
Copy link
Contributor

CodaFi commented Apr 23, 2020

@swift-ci test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2effbb7

@CodaFi
Copy link
Contributor

CodaFi commented Apr 23, 2020

Huh,

@swift-ci test source compatibility Debug

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

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.

5 participants