RFR: 8367531: Template Framework: use scopes and tokens instead of misbehaving immediate-return-queries [v29]
Emanuel Peter
epeter at openjdk.org
Fri Nov 14 14:29:16 UTC 2025
On Fri, 14 Nov 2025 14:16:06 GMT, Roberto Castañeda Lozano <rcastanedalo at openjdk.org> wrote:
> > It is only "hardcoded" to never let hashtags and setFuelCost escape, it just implicitly downgrades a scope on those two "dimensions".
>
> Is this a design choice or a constraint of the current implementation? I could imagine situations in which it could be useful to let a hashtag escape across Template boundaries, no? Something like:
>
> ```
> var innerTemplate = Template.make(() -> transparentScope(let("foo", "42")));
> var outerTemplate = Template.make(() -> scope(
> innerTemplate.asToken(),
> "// value of foo: #foo"
> ));
> outerTemplate.render();
> ```
I think this would lead to issues once you use a template recursively. What would you do if `foo` was already defined, and now you call `innerTemplate`?
So I suppose it is a choice, yes. But I don't think the alternatives would be better.
- You could just throw an exception at the second definition. But then you would need a way to check for existence of hashtag names ... not great.
- You could just hide outer definitions... basically they would work like scoped values: you can bind and re-bind them. But that brings its own complexity that I don't want to push on the users if it's not absolutely necessary.
If you really do need access to something from an outer template, you should just pass it via template argument. That makes the flow explicit. That's my opinion.
Or do you already see some case where something like a "scoped value" would be really really useful? I suppose we could still add that in the future. Another thought: hooks are a bit like "scoped value" ... except that they carry no "value" ;)
What do you think?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27255#issuecomment-3533046093
More information about the hotspot-compiler-dev
mailing list