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

Allow to use recursion in Starlark #9163

Open
maximyurchuk opened this issue Aug 13, 2019 · 5 comments
Open

Allow to use recursion in Starlark #9163

maximyurchuk opened this issue Aug 13, 2019 · 5 comments
Labels
not stale Issues or PRs that are inactive but not considered stale P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel type: feature request

Comments

@maximyurchuk
Copy link

Description of the problem / feature request:

Allow to use recursion in Starlark. Instead of just detecting recursion maybe its better to limit Starlark stacksize.

Feature requests: what underlying problem are you trying to solve with this feature?

I trying to write my own .bzl files for building C++ code, but native functions is not well documented, because of that I'm just printing variables in my rules for exploration. But I've got an problem with writing generic function, which can dump object content in Starlark, because of lack of recursion.

My implementation of printing function for debug puproses:
my_rule.bzl:

def dump(obj, indent):
    for field in dir(obj):
        attr_value =  getattr(obj, field)
        attr_value_type =  type(getattr(obj, field))
        print(indent, attr_value_type,  field, ": ", )
        dump(attr_value, indent + "  ")
 

def _my_rule(ctx):
    dump(ctx.attr.input.output_groups, "")

my_rule = rule(
    implementation = _my_rule,
    attrs = {
        "input": attr.label(allow_single_file = True),
    },
)

BUILD:

package(default_visibility = ["//visibility:public"])

load("//:my_rule.bzl", "my_rule")


cc_library(
    name = "bar",
    srcs = ["main.cc"],
)

my_rule(
	name = "dump",
	input = ":bar",
)

With this code I've get an error:

Recursion was detected when calling 'dump' from 'dump'

What operating system are you running Bazel on?

Windows 10 x64

What's the output of bazel info release?

release 0.29.0rc5

Any other information, logs, or outputs that you want to share?

Bazel-discuss group thread

@laurentlb laurentlb added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request and removed untriaged labels Aug 14, 2019
@laurentlb
Copy link
Contributor

See discussion here: bazelbuild/starlark#97
and PR: #11822

@brandjon
Copy link
Member

Another practical use case: #8921.

@brandjon brandjon added team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel and removed team-Starlark labels Feb 19, 2021
@sgowroji sgowroji added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 15, 2023
@sgowroji
Copy link
Member

Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@cpsauer
Copy link
Contributor

cpsauer commented Feb 15, 2023

IMO this would still be valuable! Worth keeping open?

@sgowroji sgowroji added not stale Issues or PRs that are inactive but not considered stale and removed stale Issues or PRs that are stale (no activity for 30 days) labels Feb 15, 2023
@sgowroji sgowroji reopened this Feb 15, 2023
@gsaraf
Copy link

gsaraf commented Jul 4, 2023

We are having to overcome this now as well. We need to run code in a non-bazel use of Starlark that merges dictionaries. The workaround of using a queue for dictionaries to merge is significantly more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not stale Issues or PRs that are inactive but not considered stale P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel type: feature request
Projects
None yet
Development

No branches or pull requests

7 participants