Skip to content
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

kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs #3422

Merged
merged 4 commits into from
May 10, 2019

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Apr 24, 2019

(This PR is motivated by repeated experiences trying to explain to people how GAP encodes function bodies. It is meant to make this code slightly more accessible.)

A long, long time ago, the statements and expressions which make up GAP function bodies were each coded as a separate GAP object. This is very inefficient for various reasons, so it was changed; now expressions and statements were simply a bunch of bytes within a single GAP object of type T_BODY, with a specific format. Yet they all retained their "identity" in the form of a type number, such as T_WHILE to indicate a statement representing a while loop. To these day, the kernel code refers to these as "TNUMs".

This can be rather confusing, as those TNUMs have nothing to do anymore with the GAP object TNUMs; yet they do not only still have the same name, but also they all share the same T_ prefix. E.g. we have T_STRING (an object tnum) and T_STRING_EXPR (an expression tnum).

We discussed this on slack some time ago. The consensus seemed to be that we should rename these, turning the T_ into either STAT_ or EXPR_, depending on the type.
One alternative would be to use the same prefix for both, as there really is no difference between the two on a purely technical (low) level; the main importance for distinguishing the two cases is in validation of the coded function's structure, resp. whether in knowing which dispatch table to look when evaluating them. But for that it's not necessary to give them different names...
Alas, since a lot of code now tries hard to distinguish precisely between the two, I think it makes sense to go with the split here for now; if one day in the future we decided to unify expressions and statement terminology again, doing it for these "tnums" will be about the easiest part anyway ;-).

To perform the actual change, I wrote a little shell script, which I put into this PR. That makes it trivial to change things around: if we want another pair of prefixes: no problem. Also, if we merge some other PRs which will conflict with this PR (e.g. @sebasguts's PR #3371 which definitely should be merged before this PR), then it is trivial for me to recreate this PR.

Before this can be merged, some steps should be taken:

  • make sure everybody is OK with this change (obviously)
  • merge other conflicting PRs, such as PR Add a coder to reread syntaxtrees #3371
  • come up with a better term than "statement or expression tnum" and use that consistently (perhaps "statement type" and "expression type"
  • to reduce confusion further, possibly rename a few existing identifiers in the kernel code which already have the STAT_ prefix (there are none with EXPR_ prefix), namely:
    • STAT_HEADER
    • STAT_MARK_CACHE
    • STAT_LVARS
    • STAT_LVARS_PTR

@fingolfin fingolfin added do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) topic: kernel release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes kind: discussion discussions, questions, requests for comments, and so on labels Apr 24, 2019
@sebasguts
Copy link
Member

I would be totally happy with this PR, and also distinguishing stats and exprs is valid imho.

I will try to fix #3371 soon (hopefully today or tomorrow) so we can get on with this. I assume you will leave the scripts in the PR, so I can apply them to other code I have already written using syntax trees? If not, it is also fine.

Copy link
Contributor

@stevelinton stevelinton left a comment

Choose a reason for hiding this comment

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

I entirely support the PR.

Maybe the script should check for the presence (and, if necessary the version) of perl and give a suitable error message if it's not there, just to minimise frustration.

@fingolfin fingolfin changed the title WIP/RFC: kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs May 7, 2019
@fingolfin fingolfin marked this pull request as ready for review May 7, 2019 22:00
@fingolfin fingolfin changed the title kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs WIP kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs May 7, 2019
@coveralls
Copy link

coveralls commented May 7, 2019

Coverage Status

Coverage increased (+4.0e-05%) to 85.153% when pulling 7ff1653 on fingolfin:mh/cnum into 578ea99 on gap-system:master.

@fingolfin fingolfin changed the title WIP kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs kernel: rename expression and statement "TNUMs" to avoid confusion with actual TNUMs May 8, 2019
@codecov
Copy link

codecov bot commented May 8, 2019

Codecov Report

Merging #3422 into master will decrease coverage by <.01%.
The diff coverage is 99.51%.

@@            Coverage Diff             @@
##           master    #3422      +/-   ##
==========================================
- Coverage   85.34%   85.34%   -0.01%     
==========================================
  Files         699      699              
  Lines      346091   346092       +1     
==========================================
- Hits       295373   295372       -1     
- Misses      50718    50720       +2
Impacted Files Coverage Δ
src/julia_gc.c 77.4% <ø> (ø) ⬆️
src/code.h 97.29% <100%> (ø) ⬆️
src/syntaxtree.c 96.12% <100%> (ø) ⬆️
src/stats.c 95.18% <100%> (ø) ⬆️
src/vars.h 98.41% <100%> (ø) ⬆️
src/vars.c 94.07% <100%> (ø) ⬆️
src/code.c 99.78% <100%> (ø) ⬆️
src/exprs.c 97.91% <100%> (ø) ⬆️
src/funcs.c 98.78% <100%> (ø) ⬆️
src/hookintrprtr.c 67.34% <100%> (ø) ⬆️
... and 4 more

@@ -330,7 +330,7 @@ static UInt ExecIfElifElse(Stat stat)
** then 0 is returned.
**
** A for-loop with <n> statements in its body is represented by a bag of
** type 'T_FOR' with <n>+2 subbags. The first subbag is an assignment bag
** type 'STAT_FOR' with <n>+2 subbags. The first subbag is an assignment bag
Copy link
Member Author

Choose a reason for hiding this comment

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

There are still lots of these comments which claim that statements and expressions are "represented by a bag", and which talk about "subbags", and so on. I think it is out of scope for this PR, but it would be kinda nice to improve that.

E.g. instead of T_FUNCCALL_0ARGS we have EXPR_FUNCCALL_0ARGS,
and instead of T_PROCCCALL_0ARGS we have STAT_PROCCCALL_0ARGS.
@fingolfin fingolfin removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label May 9, 2019
@fingolfin
Copy link
Member Author

From my point of view, this could be merged now.

@sebasguts
Copy link
Member

I would be very happy if this can get merged. It conflicts with #3441 which I can update afterwards

@fingolfin fingolfin merged commit 84cd55e into gap-system:master May 10, 2019
@fingolfin fingolfin deleted the mh/cnum branch May 10, 2019 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: discussion discussions, questions, requests for comments, and so on release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants