Skip to content

Fix a Source Break With Function Builders #32893

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 1 commit into from
Jul 17, 2020
Merged

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Jul 15, 2020

Before 09db290, the function builder
transform used to try to detect when the builder type wasn't fully
resolved. In such a case, rather than fail the solution set as we do
currently, it would construct a null TypeLoc, then stash the type-
variable-laden builder type inside of a TypeExpr and rely on CSGen
to reinterpret that as a request to read the stashed type as it was
constructing the rest of the system. This used to rely on the ability to construct
an implicit TypeExpr node with a null type but now such a thing is
banned by the TypeExpr interface.

Instead, we have to detect this case and construct an explicit
TypeExpr node pointing to all the usual fake data. This node's type will
be used to resolve the build* member, but the final applied type of the
node will be the builder type we stashed earlier - hopefully with
outstanding type variables solved.

rdar://65116204, SR-13132

@CodaFi CodaFi requested a review from hamishknight July 15, 2020 01:13
@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 15, 2020

@swift-ci smoke test

@hamishknight
Copy link
Contributor

Don't we also need some logic in CSGen to pick up the cached type? Otherwise we'll open a fresh type var disconnected from the rest of the system. Here's a test case that relies on them being connected:

protocol P {}
extension String : P {}

@_functionBuilder
struct FooBuilder<T> {}

extension FooBuilder where T : P {
  static func buildBlock(_ x: Int, _ y: Int) -> String { "" }
}

func foo<T : P>(@FooBuilder<T> fn: () -> T) {}

foo {
  0
  0
}

Copy link
Member

@DougGregor DougGregor 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!

Before 09db290, the function builder
transform used to try to detect when the builder type wasn't fully
resolved. In such a case, rather than fail the solution set as we do
currently, it would construct a null TypeLoc, then stash the type-
variable-laden builder type inside of a TypeExpr and rely on CSGen
to reinterpret that as a request to read the stashed type as it was
constructing the rest of the system. This used to rely on the ability to construct
an implicit TypeExpr node with a null type but now such a thing is
banned by the TypeExpr interface.

Instead, we have to detect this case and construct an *explicit*
TypeExpr node pointing to all the usual fake data. This node's type will
be used to resolve the build* member, but the final applied type of the
node will be the builder type we stashed earlier - hopefully with
outstanding type variables solved.

rdar://65116204
@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 17, 2020

@swift-ci smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Thanks! I think we should get a radar filed to adjust this properly.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 17, 2020

@swift-ci smoke test macOS platform

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 17, 2020

@swift-ci smoke test Windows

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 17, 2020

@CodaFi CodaFi merged commit 3e090b4 into swiftlang:master Jul 17, 2020
@CodaFi CodaFi deleted the build-a-bear branch July 17, 2020 04:26
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