In files:
test/hotspot/jtreg/compiler/lib/template_framework/DataName.java
test/hotspot/jtreg/compiler/lib/template_framework/StructuralName.java
We sample, and throw an exception if there is nothing found: "No variable: ..."
This can happen because of just a regular programming mistake, but also by a specific missing understanding of the lambda / token evaluation order. See the description in
test/hotspot/jtreg/compiler/lib/template_framework/Template.java
* When working with {@link DataName}s and {@link StructuralName}s, it is important to be aware of the
* relevant scopes, as well as the execution order of the {@link Template} lambdas and the evaluation
* of the {@link Template#body} tokens. When a {@link Template} is rendered, its lambda is invoked. In the
* lambda, we generate the tokens, and create the {@link Template#body}. Once the lambda returns, the
* tokens are evaluated one by one. While evaluating the tokens, the {@link Renderer} might encounter a nested
* {@link TemplateToken}, which in turn triggers the evaluation of that nested {@link Template}, i.e.
* the evaluation of its lambda and later the evaluation of its tokens. It is important to keep in mind
* that the lambda is always executed first, and the tokens are evaluated afterwards. A method like
* {@code dataNames(MUTABLE).exactOf(type).count()} is a method that is executed during the evaluation
* of the lambda. But a method like {@link #addDataName} returns a token, and does not immediately add
* the {@link DataName}. This ensures that the {@link DataName} is only inserted when the tokens are
* evaluated, so that it is inserted at the exact scope where we would expect it.
So if someone now thinks they are inserting a DataName, but it only creates a token, and then query for dataNames right in the same lambda, then they may get this exception "No variable: ...".
It would be nice if they got a hint. For example, they could use a nested template:
- Outer Template
- insert dataName / structuralName
- call nested Template: it should already have access to the dataName from the outer Template.
Make sure there are examples of exactly this issue, where you get the exception, and one where it is fixed so you don't get the exception. That could be a useful example to reference in the exception as well.
And: the exception "No variable: ..." is actually not great any more. We used to call them "variables", but now they are rather DataNames or StructuralNames, which is a more abstract name. So fix the message as well while you are at it ;)
test/hotspot/jtreg/compiler/lib/template_framework/DataName.java
test/hotspot/jtreg/compiler/lib/template_framework/StructuralName.java
We sample, and throw an exception if there is nothing found: "No variable: ..."
This can happen because of just a regular programming mistake, but also by a specific missing understanding of the lambda / token evaluation order. See the description in
test/hotspot/jtreg/compiler/lib/template_framework/Template.java
* When working with {@link DataName}s and {@link StructuralName}s, it is important to be aware of the
* relevant scopes, as well as the execution order of the {@link Template} lambdas and the evaluation
* of the {@link Template#body} tokens. When a {@link Template} is rendered, its lambda is invoked. In the
* lambda, we generate the tokens, and create the {@link Template#body}. Once the lambda returns, the
* tokens are evaluated one by one. While evaluating the tokens, the {@link Renderer} might encounter a nested
* {@link TemplateToken}, which in turn triggers the evaluation of that nested {@link Template}, i.e.
* the evaluation of its lambda and later the evaluation of its tokens. It is important to keep in mind
* that the lambda is always executed first, and the tokens are evaluated afterwards. A method like
* {@code dataNames(MUTABLE).exactOf(type).count()} is a method that is executed during the evaluation
* of the lambda. But a method like {@link #addDataName} returns a token, and does not immediately add
* the {@link DataName}. This ensures that the {@link DataName} is only inserted when the tokens are
* evaluated, so that it is inserted at the exact scope where we would expect it.
So if someone now thinks they are inserting a DataName, but it only creates a token, and then query for dataNames right in the same lambda, then they may get this exception "No variable: ...".
It would be nice if they got a hint. For example, they could use a nested template:
- Outer Template
- insert dataName / structuralName
- call nested Template: it should already have access to the dataName from the outer Template.
Make sure there are examples of exactly this issue, where you get the exception, and one where it is fixed so you don't get the exception. That could be a useful example to reference in the exception as well.
And: the exception "No variable: ..." is actually not great any more. We used to call them "variables", but now they are rather DataNames or StructuralNames, which is a more abstract name. So fix the message as well while you are at it ;)
- relates to
-
JDK-8344942 Template-Based Testing Framework
-
- Resolved
-