Skip to content

[ParseableInterfaces] Support inheriting default arguments in module interfaces via '= super' #24073

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 7 commits into from
Apr 19, 2019

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Apr 16, 2019

Since we try not to synthesize inherited initializers, we want to be explicit and print them in subclasses. Since the default argument kind was Inherited, though, we were printing them as:

override public init(value: Swift.Int = super)

which didn't parse. Harlan initially tried fixing this by changing how we print the module interfaces (#23933) but that approach isn't always correct. This PR changes how we consume them by updating the parser to accept the = super syntax in module interface files to mean the argument kind is Inherited.

I also added diagnostics for = super showing up where it shouldn't, but maybe that's overkill since module interfaces are generated?

Resolves rdar://49789274

@nathawes
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@harlanhaskins harlanhaskins left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! And thanks for adding Syntax tests too.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Looks pretty good, only minor comments!

…interfaces

Also:
- additionally require the containing and overridden initializers are
  designated, as that's the only case in which we should produce the '= super'
  syntax in module interfaces
- Add notes to point out the locations of the overriden initializer when it's
  not designated, and the corresponding parameter in that initializer when it
  doesn't have a default argument to inherit.
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1e10252

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1e10252

@nathawes
Copy link
Contributor Author

@swift-ci please test Linux

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Do you think we need a SILGen or execution test to make sure the value's getting parsed correctly? That can probably be a follow-up commit, but it seems like a good idea to me.

… an execution test

Also pass the decls themselves rather than their locations when diagnosing
incorrect usage of '= super'.
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes
Copy link
Contributor Author

@jrose-apple I've added the execution test, but I haven't actually written one before. Does this look ok?

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d4f1894

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thank you!

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - d4f1894

//
// RUN: %target-build-swift -I%t -L%t -lInherited -o %t/main %target-rpath(%t) %t/main.swift -swift-version 5
// RUN: %target-codesign %t/main %t/%target-library-name(Inherited)
// RUN: %target-run %t/main | %FileCheck --check-prefix=OUTPUT %s
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, look like this broke device testing. In order to make sure libInherited.dylib gets copied to the device, you have to pass it as an argument to %t/main. (That's the hack we came up with, anyway: pretend it's an input.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you're way ahead of me. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure what I was missing, but @harlanhaskins helped me out!

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