Skip to content

[Sema] Check that at least one buildBlock is callable given arg labels #33885

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

Closed

Conversation

Jumhyn
Copy link
Member

@Jumhyn Jumhyn commented Sep 10, 2020

When validating an @_functionBuilder type, reject types which only provide buildBlock declarations with argument labels (which don't have default values). These declarations will never be callable by the buildBlock calls produced by the function builder transformation, which does not insert any argument labels for buildBlock calls.

if (!argLabels.empty()) {
auto funcLabels = func->getName().getArgumentNames();
if (argLabels.size() > funcLabels.size() ||
funcLabels.slice(0, argLabels.size()) != argLabels) {
Copy link
Member

Choose a reason for hiding this comment

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

This is an approximation of the rule used to actually match call arguments. Do you want to go all the way and use matchCallArguments to get it exactly right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that makes sense for most of the build* functions (since the transform introduces a fixed number of arguments), but I don't think it would work for buildBlock since we won't know the correct number of arguments until we're actually evaluating a call, and every call to buildBlock may differ in the number of arguments.

It seems to me that, given that buildBlock calls may have an unbounded number of arguments (of any type), the best we can do when evaluating the buildBlock declaration is make sure that there are no required labeled arguments. If I'm missing something let me know!

@Jumhyn Jumhyn force-pushed the function-builder-buildblock-arg-labels branch from ebe951f to 0bb6b0f Compare September 10, 2020 14:38
@Jumhyn Jumhyn requested a review from DougGregor September 10, 2020 14:53
When validating an @_functionBuilder type, reject types which only provide `buildBlock` declarations with argument labels (which don't have default values). These declarations will never be callable by the `buildBlock` calls produced by the function builder transformation, which does not insert any argument labels for `buildBlock` calls.
@Jumhyn Jumhyn force-pushed the function-builder-buildblock-arg-labels branch from 0bb6b0f to 81d8ee0 Compare September 18, 2020 13:11
@Jumhyn
Copy link
Member Author

Jumhyn commented Sep 18, 2020

@DougGregor Updated this to incorporate changes from #33972, still interested in your thoughts on the thread above!

@Jumhyn
Copy link
Member Author

Jumhyn commented Sep 25, 2020

@DougGregor Could you give this another look when you have the chance?

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@Jumhyn Jumhyn changed the base branch from master to main October 1, 2020 16:23
@Jumhyn Jumhyn closed this Oct 1, 2021
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