Skip to content
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

Preliminary support for function builders #25221

Merged
merged 37 commits into from Jun 12, 2019

Conversation

Projects
None yet
4 participants
@rjmccall
Copy link
Member

commented Jun 3, 2019

Provide basic support for function builders, which allow the convenient creation of eDSLs for complex lists and hierarchies.

An evolution pitch for this is forthcoming. That pitch proposes a somewhat more general feature than is implemented here; this work reflects what's available in the current Xcode developer preview.

@rjmccall

This comment has been minimized.

Copy link
Member Author

commented Jun 3, 2019

@swift-ci Please test.

@rjmccall rjmccall changed the title [WIP/unapproved] Basic support for function builders [WIP] Basic support for function builders Jun 3, 2019

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 487ca9c9d4aafeaf886d80c3c9f2305f7242d9b4

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 487ca9c9d4aafeaf886d80c3c9f2305f7242d9b4

@DougGregor

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

@swift-ci please smoke test

@DougGregor

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

@swift-ci build toolchain

@DougGregor

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

@swift-ci please smoke test

@DougGregor

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

@swift-ci build toolchain

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - 6f5660fe6735e026453b77827005952b854d3b54

Install command
tar zxf swift-PR-25221-239-ubuntu16.04.tar.gz
More info

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

macOS Toolchain
Download Toolchain
Git Sha - 6f5660fe6735e026453b77827005952b854d3b54

Install command
tar -zxf swift-PR-25221-312-osx.tar.gz --directory ~/

@rjmccall rjmccall force-pushed the rjmccall:function-builders branch 2 times, most recently to a591499 Jun 5, 2019

@rjmccall

This comment has been minimized.

Copy link
Member Author

commented Jun 6, 2019

@swift-ci Please test.

@rjmccall

This comment has been minimized.

Copy link
Member Author

commented Jun 6, 2019

@DougGregor Thanks for fixing the build! Unfortunately I didn't notice that you did this until after I clobbered it with my own fix. 😃

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Build failed
Swift Test Linux Platform
Git Sha - 487ca9c9d4aafeaf886d80c3c9f2305f7242d9b4

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Build failed
Swift Test OS X Platform
Git Sha - a591499

rjmccall and others added some commits Apr 16, 2019

Factor the computation of default arguments into ParameterListInfo.
Provide a place where we can capture more information about the parameters
from a declaration being called.
Add an unused request for getting the type of a custom attribute.
Includes code anticipating property delegates in part because it's
been largely stolen from Doug's PR for that.
[Type checker] Transform multi-statement closures via function builders.
When calling a function whose parameter specifies a function builder
with a multi-statement closure argument, transform the closure into
a single expression via the function builder. Should the result
type checker, replace the closure body with the single expression.
[DSL] Allow function builders to opt in to "if" statements.
If a function builder contains a buildIf function, then "if" statements
will be supported by passing an optional of the "then" branch.
"if" statements with an "else" statement are unsupported at present.
[CodeCompletion] Enable type completion at beginning of attribute
for 'VarDecl' or if we don't know the kind of the decl.
Property delegate allows arbitrary type name (with `@propertyDelegate`
attr).
Rework the requests for getting a parameter's function-builder type.
Turn the generic CustomAttrTypeRequest into a helper function and
introduce a FunctionBuilderTypeRequest that starts from a ParamDecl.
This has better caching characteristics and also means we only need to
do a single cache lookup in order to resolve the type in the normal path.
It also means we don't need as much parameterization in the cache.

In addition, check that the parameter has function type in the request,
not just when late-checking the attribute, and add a check that it isn't
an autoclosure.

DougGregor and others added some commits Apr 23, 2019

[Function builders] Allow uses of generic function builders.
Use the opened type from the callee declaration to open up references to
generic function builders that contain type parameters. This allows general
use of generic function builders.
[CodeCompletion] Function builder: add test case for attribute at params
Make sure we don't suggest any builtin attributes, but only custom type
names.

rdar://problem/50074177
[Function builders] Prescan closure bodies for a 'return' statement.
Since we short-circuit in the function builder application when we
hit something we cannot translate, relying on that visitor to
detect 'return' statements (which disable the application) is bogus.
Use a separate, earlier visitor to find 'return' statements consistently.

Fixes rdar://problem/50266341.
Support if-else chains on function builders.
A substantial amount of this patch goes towards trying to get at least
minimal diagnostics working, since of course I messed up the rule a few
times when implementing this.

rdar://50149837
[Type checker] Don't re-insert node types when merging solutions.
Merging partial solutions can end up assigning the same type to a
particular typed node (expression, parameter, etc.), which can lead to
unbalanced set/clear when exploring the solution space (and later on,
crashes). Don't re-insert such information.

This is the same approach taken for type variable bindings, but it's
all pretty unfortunate: partial solutions should only record
information relative to their part of the constraint system, which
would save time and memory during solving. Howver, that's too big a
change for right now.

Fixes rdar://problem/50853028.
[DSL] Clean up assignment of types to synthesized TypeExprs.
The implicit TypeExprs for function builders were getting inconsistently set
types, which would sometimes be the metatype and sometimes not be the
metatype, leading to a crash in the new test code.

@rjmccall rjmccall force-pushed the rjmccall:function-builders branch from 3c41ffe to b4cdbc0 Jun 12, 2019

@rjmccall

This comment has been minimized.

Copy link
Member Author

commented Jun 12, 2019

@swift-ci Please test.

@rjmccall rjmccall changed the title [WIP] Basic support for function builders Preliminary support for function builders Jun 12, 2019

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

Build failed
Swift Test OS X Platform
Git Sha - a591499

@swift-ci

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

Build failed
Swift Test Linux Platform
Git Sha - a591499

@rjmccall

This comment has been minimized.

Copy link
Member Author

commented Jun 12, 2019

We are planning to merge this now in order to simplify progressive development on top of it, since (1) the core team is in basic agreement that we should add this feature in some form and (2) it's a rather large patch and requires constant attention to keep valid. We still anticipate significant changes to the design. I'll be making a similar announcement in the pitch thread.

@rjmccall rjmccall merged commit e65dfc8 into apple:master Jun 12, 2019

4 checks passed

Swift Test Linux Platform No test results found.
Details
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform No test results found.
Details
Swift Test OS X Platform (smoke test)
Details

@rjmccall rjmccall deleted the rjmccall:function-builders branch Jun 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.