Skip to content

Improve multi-file enum diagnostics #9180

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 2 commits into from
May 2, 2017

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented May 2, 2017

Given a setup where one file declares an enum and the other switches on it, decomposition fails because it can't get any useful interface types out of the AST. Version 1 of this patch adds a short hack that just throws in the enum case constructor heads into the space and reports that back to the user because it's better than nothing, but there's got to be a better way to do this.

@slavapestov?

@slavapestov
Copy link
Contributor

Why are there no interface types in the AST? The enum should be validated before it is referenced from inside any function bodies

@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

Here's what I'm getting back from this setup:

// Test File 1
func f(_ x : Foo) {
  switch x {
    
  }
}

// Test File 2
enum Foo {
  case bar(Bool)
  case baz(Bool)
}
(lldb) p eed->dump()
(enum_element_decl "bar")
(lldb) p E->dump()
(enum_decl "Foo" interface type='Foo.Type' access=internal @_fixed_layout
  (enum_case_decl
    (enum_element_decl "bar"))
  (enum_element_decl "bar")
  (enum_case_decl
    (enum_element_decl "baz"))
  (enum_element_decl "baz"))
(lldb) 

@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

Ah, wait: This is an ordering problem. I need everything in the other file to be typechecked before I ask for the interface type of the enum decl.

@slavapestov
Copy link
Contributor

Well, you don't want to type check everything in the other file -- that would be a performance problem. However, since the declaration 'Foo' is referenced here, probably all of the enum cases contained therein should also be validated. How was this working before?

@slavapestov
Copy link
Contributor

You could try just calling TypeChecker::validateDecl() on the enum case decl before getting its type.

@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

That works, but it means I have to thread an instance of the typechecker through this whole thing, and probably validate a lot of enum element declarations that will already go through validation. Is there some later phase of semantic analysis I can stick this in to get around that?

@slavapestov
Copy link
Contributor

Well, validating a decl more than once is a no-op. We validate all case members of referenced enums later anyway since we need that to compute layouts in IRGen.

@CodaFi CodaFi force-pushed the cross-pollination branch from a6233a7 to ce68627 Compare May 2, 2017 04:31
@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

@swift-ci please smoke test

@CodaFi CodaFi force-pushed the cross-pollination branch 4 times, most recently from fa20e48 to a0b7f57 Compare May 2, 2017 18:43
@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

Yep, that got it.

@swift-ci please test macOS platform

@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - a0b7f57210787e1374b08d10b72d82e8e5e34669
Test requested by - @CodaFi

@CodaFi CodaFi force-pushed the cross-pollination branch from a0b7f57 to 5722984 Compare May 2, 2017 20:09
@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

@swift-ci please smoke test

@CodaFi CodaFi changed the title [WIP] Improve multi-file enum diagnostics Improve multi-file enum diagnostics May 2, 2017
@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

⛵️

@CodaFi CodaFi merged commit ab9f280 into swiftlang:master May 2, 2017
@CodaFi CodaFi deleted the cross-pollination branch May 2, 2017 20:46
@nkcsgexi
Copy link
Contributor

nkcsgexi commented May 2, 2017

@CodaFi are you planning to merge this to swift-4.0-branch?

@CodaFi
Copy link
Contributor Author

CodaFi commented May 2, 2017

Along with your last pull request. Just gonna take it all in that one place if that's OK.

@nkcsgexi
Copy link
Contributor

nkcsgexi commented May 2, 2017

That will be a good idea! Thank you!

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