Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

fix for #17 #265

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

fix for #17 #265

wants to merge 3 commits into from

Conversation

jamdagni86
Copy link

This is something which I could come up with in a couple of hours. The idea is to merge the constituent tuple arguments into a single argument (by joining argument names with τ) and get them unpacked inside the function using array notation.

Let me know your thoughts on the same. Unit tests are still work in progress; will update the PR once they are ready!

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@jamdagni86
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

raise util.ParseError(node, msg)
self.vars[name] = Var(name, Var.TYPE_PARAM, arg_index=i)
if isinstance(name, list):
self.add_vars(i, 'τ'.join(name), node)
Copy link
Contributor

Choose a reason for hiding this comment

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

As it turns out the arg tuples can be nested:

>>> def f((a, (b, c))):
...  print a, b, c
... 
>>> f((1, (2, 3)))
1 2 3

This points to a recursive approach similar to the way _tie_target() in stmt.py works. My intuition is that we can use the exact same mechanism (grumpy.TieTarget struct) for unpacking the args.

Also, Var represents Python variables and are used to resolve names and handle scoping rules so I don't think you want to create a pseudo Var to represent the tuple. Instead you want to put the special unpacking logic somewhere around here. But instead of assigning to each of the locals for the args, that's where you want to do the unpacking use the TieTarget mechanism.

Copy link
Author

Choose a reason for hiding this comment

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

@trotterdylan - Since we are passing the Tuple as a single argument, we'll need some sort of Vars to hold the values inside the function as we need to Tie these arguments to the respective variables/arguments. Instead of pseudo Vars, what do you suggest?

Another approach could be to unpack them while constructing the arguments to the function itself and pass all the unpacked values as directly.

Let me know!

Copy link
Contributor

Choose a reason for hiding this comment

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

You can allocate a Go variable to hold the temporary value. Look for uses of Block.alloc_temp() in the code. The way this works for assignments is very similar to what I imagine you will need to do. It's a little indirect, but here's the relevant alloc for normal assignments: https://github.com/google/grumpy/blob/master/compiler/stmt.py#L640

I think the code for tuple argument unpacking will be very similar to that for tuple assignments. Hopefully you can reuse _build_assign_target(), _tie_target(), etc.

@jamdagni86 jamdagni86 changed the title potential fix for #17 - for review only fix for #17 Aug 29, 2017
@jamdagni86
Copy link
Author

jamdagni86 commented Aug 30, 2017

@trotterdylan - The build is failing in go 1.9 as mentioned in #378

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants