RFR: 8367531: Template Framework: use scopes and tokens instead of misbehaving immediate-return-queries [v29]
Roberto Castañeda Lozano
rcastanedalo at openjdk.org
Mon Nov 17 13:57:23 UTC 2025
On Fri, 14 Nov 2025 14:40:49 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?
>
>> 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.
>
> Sounds OK to me, I think it would be worth capturing this rationale and advisory somewhere in the documentation.
> @robcasloz Alright, I added some extra documentation of hashtag locality with [bba7152](https://github.com/openjdk/jdk/pull/27255/commits/bba71529ac081b0f53cd5106f57fb541bd3e0ead)
Thanks, the new documentation looks good!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27255#issuecomment-3541944137
More information about the hotspot-compiler-dev
mailing list