Skip to content

Add Value::function_name() for def/lambda/native callables#183

Closed
connyay wants to merge 3 commits into
facebook:mainfrom
connyay:cjh-fn-name
Closed

Add Value::function_name() for def/lambda/native callables#183
connyay wants to merge 3 commits into
facebook:mainfrom
connyay:cjh-fn-name

Conversation

@connyay

@connyay connyay commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Adds Value::function_name(self) -> Option<&'v str>. Returns the name for Def, FrozenDef, and NativeFunction; None for everything else.

Motivation: embedders often build host-side constructors like handler("name", run=my_fn) and then want the name of the callable that got passed in so they can stash it and call it later through Evaluator or the module registry. The underlying fields (Def::def_info.name, NativeFunction::name) are pub(crate), so today you can't do this from outside the starlark crate without reaching into crate-private state.

Exposes callable names to embedders. The underlying fields
(Def::def_info.name, NativeFunction::name) are pub(crate), so this
isn't reachable from outside the starlark crate today.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 23, 2026
@meta-codesync

meta-codesync Bot commented Apr 23, 2026

Copy link
Copy Markdown

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D102210564. (Because this pull request was imported automatically, there will not be any future comments.)

@connyay connyay closed this May 18, 2026
meta-codesync Bot pushed a commit that referenced this pull request May 19, 2026
Summary:
Adds `Value::function_name(self) -> Option<&'v str>`. Returns the name for `Def`, `FrozenDef`, and `NativeFunction`; `None` for everything else.

Motivation: embedders often build host-side constructors like `handler("name", run=my_fn)` and then want the name of the callable that got passed in so they can stash it and call it later through Evaluator or the module registry. The underlying fields (`Def::def_info.name`, `NativeFunction::name`) are `pub(crate)`, so today you can't do this from outside the starlark crate without reaching into crate-private state.

Pull Request resolved: #183

Reviewed By: JakobDegen

Differential Revision: D102210564

fbshipit-source-id: 5e71480ef51ee3758ed6cfc799803bb112604ed9
meta-codesync Bot pushed a commit to facebook/buck2 that referenced this pull request May 19, 2026
Summary:
Adds `Value::function_name(self) -> Option<&'v str>`. Returns the name for `Def`, `FrozenDef`, and `NativeFunction`; `None` for everything else.

Motivation: embedders often build host-side constructors like `handler("name", run=my_fn)` and then want the name of the callable that got passed in so they can stash it and call it later through Evaluator or the module registry. The underlying fields (`Def::def_info.name`, `NativeFunction::name`) are `pub(crate)`, so today you can't do this from outside the starlark crate without reaching into crate-private state.

X-link: facebook/starlark-rust#183

Reviewed By: JakobDegen

Differential Revision: D102210564

fbshipit-source-id: 5e71480ef51ee3758ed6cfc799803bb112604ed9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

1 participant