-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New script language for ocamltest #12185
Conversation
Thanks!
On sick leave at the moment butfeel free to assign tome for review. Hope
to be back next week.
|
Your PR or diff contain no examples of the new syntax! You should take a few representative/interesting tests and translate them to the new syntax as part of the PR, so that people get an idea of what the new syntax looks like and what the benefits are. |
Oh, sorry I should have mentioned this is still a work in progress. |
292bba3
to
f94a4d2
Compare
Translated all test files: Most files are translated automatically without any need to change the reference files. Some files (about 150 of them) rely on source locations, I have translated them to Some files have character offsets in their reference files. I have translated them to Then, there are a few special cases:
Now ready for review. |
Nice! I'm looking at the translated test scripts, and I see many instances of the following diff that is not nice: -(* TEST *)
+(* TEST
+{
+}
+*) As as special case, could you support an empty-script syntax and use it in the translator? |
The following also occurs several times with one-line tests: (* TEST
- include dynlink
+{
+ include dynlink;
+}
*) could we revisit the idea of not making the toplevel braces mandatory? We wanted this to let the lexer easily distinguish between the two test syntaxes, but this is not necessary anymore with the translation tool. |
Bonus idea for your translator: when moving to the TEST_BELOW syntax, include a short comment in the whitespace region to explain that the whitespace below the header is the result of an automatic translation tool. |
@gasche these are all good ideas, I'll work on them. |
b5683b9
to
d16741d
Compare
@gasche all done. I've committed the script I used to translate all the tests, only one isn't handled by the script, Note that this latest version doesn't accept the old syntax anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translator inserts blank lines between statements that are not environment actions.
arch_power;
native;
ocamlopt_flags = "-flarge-toc";
ocamlopt.byte;
run;
flags = "-S -function-sections";
function_sections;
{
arch_arm;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_arm64;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_amd64;
reference = "${test_source_directory}/func_sections.reference";
native;
}{
arch_i386;
reference = "${test_source_directory}/func_sections.reference";
native;
}
I think that the output would be more compact and thus easier to read if it 2-indented the environment actions instead:
arch_power;
native;
ocamlopt_flags = "-flarge-toc";
ocamlopt.byte;
run;
flags = "-S -function-sections";
function_sections;
{
arch_arm;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_arm64;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_amd64;
reference = "${test_source_directory}/func_sections.reference";
native;
}{
arch_i386;
reference = "${test_source_directory}/func_sections.reference";
native;
}
ocamltest/ocamltest.org
Outdated
flags = "-w +33" | ||
{ | ||
flags = "-w +33"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the test blocks in ocamltest.org
are still using the mandatory-outer-brace syntax, and could benefit from an update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Done.
@@ -35,6 +36,9 @@ type tsl_item = | |||
|
|||
type tsl_block = tsl_item list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the context of the new syntax, the name tsl_block
to mean "a toplevel script" is a bit confusing as it could equally mean a block as in C. I would remove this synonym and expand it away in the parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the old code and I haven't changed it. My plan is to remove it altogether in the follow-up PR that will remove the old syntax and the translation tool, refactor this AST code, and change the log format.
ocamltest/tsl_parser.mly
Outdated
%token TSL_BEGIN_C_STYLE TSL_END_C_STYLE | ||
%token TSL_BEGIN_OCAML_STYLE TSL_END_OCAML_STYLE | ||
%token COMMA | ||
%token <bool> TSL_BEGIN_C_STYLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
is meh here, could we use type script_position = [ `Above | `Below ]
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ocamltest/tsl_parser.mly
Outdated
%type <Tsl_ast.tsl_block> tsl_block | ||
%start tsl_block_old tsl_block | ||
%type <Tsl_ast.tsl_block> tsl_block_old | ||
%type <Tsl_ast.t> tsl_block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the name tsl_block
confusing, the symbols could be called tsl_script
and tsl_script_old
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted the old one to its original tsl_block
(which will go away soon) and used tsl_script
for the new syntax.
Just a partial response here, will do off-line reviewing also.
And sorry to quote responses, I recently became aware it's not so nice
when viewed in theweb interfacebut really, but when dealing with the
comments in e-mails it would be apain for me not beingable to quote and
do bottom-pposting. I apologize for theinconvenience.
```
flags = "-S -function-sections";
function_sections;
{
arch_arm;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_arm64;
reference = "${test_source_directory}/func_sections.arm.reference";
native;
}{
arch_amd64;
reference = "${test_source_directory}/func_sections.reference";
native;
}{
arch_i386;
reference = "${test_source_directory}/func_sections.reference";
native;
}
```
I am not very comfortable with the `{}` sequence. It's maybe just a
matter of habbits but at the moment I'd prefer to have the two braces on
different lines, although I understnad it will be a bit less compact.
I think that the output would be more compact and thus easier to read if it 2-indented the environment actions instead:
Oh no, please. To me indentation is so strongly associated with nesting
that I'm pretty sure I'll have a hard time not makingmistakes if I write
tests or not misunderstanding tests I read.
|
Same here. If we indent, it gives the impression that they are in the scope of the previous test, which is completely wrong. I have two alternatives:
|
I also thought of proposing to terminate environment updates with Maybe you could try with the compact mode and we could see how it looks like? |
Damien Doligez (2023/04/19 14:14 -0700):
>Oh no, please. To me indentation is so strongly associated with nesting
that I'm pretty sure I'll have a hard time not makingmistakes if I write
tests or not misunderstanding tests I read.
Same here. If we indent, it gives the impression that they are in the scope of the previous test, which is completely wrong.
I have two alternatives:
1. change the syntax to add a `*` in front of test statements to make them stand out
2. do nothing and use the translator in compact mode for all tests
I'd prefer option 2. It looks more straightforward without the starts to
me, and I was the one who proposed starts in the first place.
The current scripting code really looks like "normal" scripting to me,
which is nice, IMO.
|
Here's the compact version for all the scripts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed the implementation and believe that it is correct.
Note: we should wait to see what @shindere wants to say on this PR before merging.
let tsl_block = tsl_block_of_file_safe test_filename in | ||
let (rootenv_statements, test_trees) = test_trees_of_tsl_block tsl_block in | ||
let tsl_ast = tsl_block_of_file_safe test_filename in | ||
let (rootenv_statements, test_trees) = test_trees_of_tsl_ast tsl_ast in | ||
let test_trees = match test_trees with | ||
| [] -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handling of the empty test (empty means "run the default test please") is a bit fragile here as it depends on the behavior of your test_trees_of_tsl_ast
function in subtle ways -- it breaks the reasonable assumption that (env, tests)
is equivalent to ([], [Node (env, Tests.null, [], tests)])
. It would be cleaner to expose a Default case in Tsl_ast.t, and handle that explicitly, something like
let (env, test_trees) = match tsl_ast with
| Default env -> default_test env
| Script ast -> test_trees_of_tsl_ast ast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in fact worse than that, as there is a difference in behavior between env
outside the tests and the env
part of the first node of the test tree, even if there is only one tree, even if we are not running the default tests. I had a few tests failing because of that at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird.
- Can you explain the difference?
- Do you see it as a part of the specification of ocamltest that should not change, or as an irregularity to be fixed by a future PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Ocaml_actions.find_source_module
function is run on the initial environment before starting to interpret the tree. It is run through the Environments.intializers
hook system. It seems to be used to compute the all_modules
variable from a few other variables.
I didn't dig deeply, so I can't say if this would be easy to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look.
I think that we could get rid of those by avoiding environment initializers: config_variables
is basically part of the initial empty environment, and find_source_modules
could be avoided by calling a builtin function to recompute the all_modules
data whenever it is needed by an action, taking the current environment into account (or using the content of the all_modules
variable if specified explicitly by the user).
But this is also unimportant and independent of the present change, so I agree with not doing anything about it for now: the initial user-provided environment (the environment-statement prefix before the first test) have a special status, so be it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This supports the choice of removing the toplevel braces, as the toplevel node has a special status.)
I forgot to mention that I think the new test syntax is a nice improvement over the previous one, making writing tests more pleasant in practice. An example of before/after on a reasonably complex test script chosen at random from the diff: Before:
After:
In fact, it looks like this example is not doing what we want it to do, as the final test block does not depend on the build of backtrace_dynlink.ml and backtrace_dynlink_plugin.ml, which is probably wrong. I remember that @damiendoligez noticed a bug when discussing an example test script earlier, I don't know if this is the same issue -- probably. The test that we want is probably the following:
If I'm not mistaken, this corresponds to the following current-syntax test:
|
Regarding errors in the current scripts: in addition to backtrace_dynlink.ml, it looks like the test scripts for the lib-dynlink-initializers/test*_main.ml files (10 files in total I think) are also wrong for similar reasons, as well as scripts in lib-dynlink-packed and lib-dynlink-pr4229. |
Gabriel Scherer (2023/04/20 07:03 -0700):
@gasche approved this pull request.
I have reviewed the implementation and believe that it is correct.
Note: we should wait to see what @shindere wants to say on this PR
before merging.
Thanks. We'll have an interactive review session next week with
@damiendoligez.
After a careful review, I believe that `test_tree{,s}_of_tsl_ast` are
painful to read but correct. Ideally this code could go away and
instead the function operating on test trees today could start
operating on the AST directly, to remove one intermediate layer. This
needs not necessarily be part of the present PR.
I agree with both points. With the old script language the syntax tree
was not straightforward so I think it made sense to decouple its
translation from its interpretatioN. Now with a much more
straightforward language this separation seems much less critical, at
the very least.
|
Regarding errors in the test scripts: I believe that we should wait after the present PR is merged, and then fix the scripts in a later PR. (Preserve the property that the current PR is doing a one-to-one translation that preserves the current test scripts.) (We could also try to fix the bugs with the current-syntax test scripts, but this is too painful.) |
@damiendoligez and I have done an offline review of this PR. I suggested a few changes which have now been pushed. I'll approve this PR. As a note to the person who will merge it, |
… special. Treat them specially when using the new syntax.
fix test warnings/w59.ml
…ailing now: tool-ocamldoc/Short_description.txt, which needs an update to its reference file.
…matic translation; cut overlong lines
41ab9e8
to
9bb6c19
Compare
Rebased to resolve conflict. |
This PR is the result of much brainstorming with @Octachron @shindere and @gasche.
It introduces a new language for tests scripts that allows for test sequences to avoid the huge nesting of the original language. The nesting is expressed with nested braces instead of the depth counters of the old language.
To do:
For later PRs: