Skip to content

Push FunctionTypeRepr Input Invariants Up #17191

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
Jun 15, 2018

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Jun 14, 2018

Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding. If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

  • The SIL Parser no longer accepts Swift 2-style type declarations
  • Parse is more cleanly able to reject invalid FunctionTypeReprs
  • Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks

@CodaFi
Copy link
Contributor Author

CodaFi commented Jun 14, 2018

@swift-ci please smoke test

@CodaFi CodaFi requested a review from slavapestov June 14, 2018 00:56
@@ -465,60 +465,6 @@ inline IdentTypeRepr::ComponentRange IdentTypeRepr::getComponentRange() {
return ComponentRange(this);
}

/// \brief A function type.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Moving this below TupleTypeRepr might be a mistake. I should probably forward-declare and move the things accessing TupleTypeRepr into TypeRepr.cpp

@@ -1461,7 +1461,7 @@ class PlaceholderExpansionScanner {
bool walkToTypeReprPre(TypeRepr *T) override {
if (auto *FTR = dyn_cast<FunctionTypeRepr>(T)) {
FoundFunctionTypeRepr = true;
if (auto *TTR = dyn_cast_or_null<TupleTypeRepr>(FTR->getArgsTypeRepr())) {
if (auto *TTR = FTR->getArgsTypeRepr()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably doesn't need to be an if at all now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the _or_null that's got me scared.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how you'd ever get a FunctionTypeRepr with no argument types, but fair enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was probably defensive coding. If the tests pass without it I would just remove it.

@@ -889,7 +889,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
// throw it away before lowering.
else if (isa<GenericFunctionType>(BaseTy)) {
auto *fTy = cast<AnyFunctionType>(BaseTy);
auto *nongenericTy = FunctionType::get(fTy->getInput(), fTy->getResult(),
auto *nongenericTy = FunctionType::get(fTy->getParams(), fTy->getResult(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

N.B. Wrong patch

Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding.  If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

- The SIL Parser no longer accepts Swift 2-style type declarations
-  Parse is more cleanly able to reject invalid FunctionTypeReprs
- Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks
@CodaFi CodaFi force-pushed the tuplet-rudiments branch from be1cff6 to 1beb755 Compare June 14, 2018 01:41
@CodaFi
Copy link
Contributor Author

CodaFi commented Jun 15, 2018

@swift-ci please smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Jun 15, 2018

⛵️

@swift-ci please test and merge

@swift-ci swift-ci merged commit a700e23 into swiftlang:master Jun 15, 2018
@CodaFi CodaFi deleted the tuplet-rudiments branch June 15, 2018 22:21
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