Skip to content

Conversation

@x1unix
Copy link

@x1unix x1unix commented Dec 6, 2025

This PR adds support of proxies. Proxies allow intercepting property access, like Python's __get__ magic method.

Proxies allow implementing different patterns like prototype chaining, read on demand, etc.

Fixes: #777

}

func Fetch(from, i any) any {
if proxy, ok := from.(Proxy); ok {
Copy link
Member

Choose a reason for hiding this comment

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

Relying only on real time to check for proxy interface is not the best strategy. We need to do a pre-optimization and check at compile time whether a special opcode for fetching using this interface can be inserted ahead of time. With just a runtime check for proxy, I cannot accept this pull request.

Copy link
Author

@x1unix x1unix Dec 7, 2025

Choose a reason for hiding this comment

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

I've a couple of questions:

  • By ahead of time optimization, do you mean to implement env check in optimizer.Optimize method?
    • Current API allows using different envs for parsing, optimization and evaluation.
      This means that during eval stage, user can supply an env that may have a proxy (e.g. foo.bar.baz), but this wasn't accounted during parse/optimize stage, so iface check still might be required inside OpFetch.
    • Proxy may be located deeply inside env (or populated at runtime), or returned from a func.
    • Initially, I wanted to use type check instead of an interface as it is 2x cheaper, but couldn't find a suitable approach (see benchmark). Happy to accept different proposals.
    • As 90% of users probably won't need proxies, this feature can be opt-in (feature flag). This will keep perf the same as before and will skip proxy checks by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request/Question] Support proxies for expr.Env

2 participants