Skip to content

New way of directly building FunctionType::Params from ParameterLists #18651

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 8 commits into from
Aug 11, 2018

Conversation

slavapestov
Copy link
Contributor

Recent changes centralized the code for computing the type of functions, subscripts, and enum elements. This removed a lot of duplication but there was still a hack there because to go from a ParameterList to a FunctionType, we had to turn the ParameterList into a TupleType, and then decompose the TupleType into an array of FunctionType::Params. That's silly, so let's make a way to build FunctionType::Params directly and remove all of the old code.

This converts a list of ParameterDecls into a list of
AnyFunctionType::Params; it will eventually replace
these methods on ParameterList:

- getType() (both overloads)
- getInterfaceType()
- getFullInterfaceType()
This is mostly NFC; the output of the api-digester test changed because
the interface type of an enum element now has parentheses around the
'Self' parameter type. This is more consistent with everything else
(and in the future, all function types will have "parentheses").
…erList::getParams()

Note that these functions used to return a FunctionType; now, they
return the result type instead:

- importFunctionType()
- importMethodType()
- importAccessorMethodType()

The parameters were already being returned in the form of a ParameterList
of ParamDecls.

This actually has the effect of making the code simpler, because callers
would always take them apart and build new function types anyway.
It looks like as of 42246ca the importer
deals exclusively with interface types, and recent refactoring eliminated
the requirement to store contextual types into VarDecls and ParamDecls,
so we can remove this last little bit of mapping here.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov requested review from rudkx and CodaFi August 11, 2018 10:37
@slavapestov slavapestov merged commit db63557 into swiftlang:master Aug 11, 2018
@rudkx
Copy link
Contributor

rudkx commented Aug 14, 2018

Nice!

@jrose-apple
Copy link
Contributor

Note that these functions used to return a FunctionType; now, they return the result type instead:

  • importFunctionType()
  • importMethodType()
  • importAccessorMethodType()

Can you change the docs, then? I see that they still provide the ParameterList as an out-parameter, so the names don't have to change, but it's not obvious from the call sites that you're getting a result type, and it should be written down in prose somewhere.

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.

3 participants