[njs] Getting rid of excessive NJS_LEVEL_TEMP.

Dmitry Volyntsev xeioex at nginx.com
Wed May 18 07:02:38 UTC 2022


details:   https://hg.nginx.org/njs/rev/aa27056f4bc9
branches:  
changeset: 1859:aa27056f4bc9
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed May 18 00:01:05 2022 -0700
description:
Getting rid of excessive NJS_LEVEL_TEMP.

diffstat:

 src/njs_async.c     |   5 +----
 src/njs_function.c  |  37 +++++++++++++------------------------
 src/njs_function.h  |  13 -------------
 src/njs_generator.c |   3 +--
 src/njs_parser.c    |   4 +++-
 src/njs_parser.h    |   1 -
 src/njs_scope.c     |   2 +-
 src/njs_vm.c        |  12 ------------
 src/njs_vm.h        |   1 -
 9 files changed, 19 insertions(+), 59 deletions(-)

diffs (304 lines):

diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_async.c
--- a/src/njs_async.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_async.c	Wed May 18 00:01:05 2022 -0700
@@ -59,7 +59,7 @@ njs_await_fulfilled(njs_vm_t *vm, njs_va
     njs_index_t unused)
 {
     njs_int_t           ret;
-    njs_value_t         **cur_local, **cur_closures, **cur_temp, *value;
+    njs_value_t         **cur_local, **cur_closures, *value;
     njs_frame_t         *frame, *async_frame;
     njs_async_ctx_t     *ctx;
     njs_native_frame_t  *top, *async;
@@ -77,13 +77,11 @@ njs_await_fulfilled(njs_vm_t *vm, njs_va
 
     cur_local = vm->levels[NJS_LEVEL_LOCAL];
     cur_closures = vm->levels[NJS_LEVEL_CLOSURE];
-    cur_temp = vm->levels[NJS_LEVEL_TEMP];
     top = vm->top_frame;
     frame = vm->active_frame;
 
     vm->levels[NJS_LEVEL_LOCAL] = async->local;
     vm->levels[NJS_LEVEL_CLOSURE] = njs_function_closures(async->function);
-    vm->levels[NJS_LEVEL_TEMP] = async->temp;
 
     vm->top_frame = async;
     vm->active_frame = async_frame;
@@ -97,7 +95,6 @@ njs_await_fulfilled(njs_vm_t *vm, njs_va
 
     vm->levels[NJS_LEVEL_LOCAL] = cur_local;
     vm->levels[NJS_LEVEL_CLOSURE] = cur_closures;
-    vm->levels[NJS_LEVEL_TEMP] = cur_temp;
 
     vm->top_frame = top;
     vm->active_frame = frame;
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_function.c
--- a/src/njs_function.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_function.c	Wed May 18 00:01:05 2022 -0700
@@ -424,8 +424,8 @@ njs_function_lambda_frame(njs_vm_t *vm, 
     njs_bool_t ctor)
 {
     size_t                 n, frame_size;
-    uint32_t               args_count, value_count, value_size, temp_size;
-    njs_value_t            *value, *bound, **new, **temp;
+    uint32_t               args_count, value_count, value_size;
+    njs_value_t            *value, *bound, **new;
     njs_frame_t            *frame;
     njs_function_t         *target;
     njs_native_frame_t     *native_frame;
@@ -458,10 +458,8 @@ njs_function_lambda_frame(njs_vm_t *vm, 
     value_count = args_count + njs_max(args_count, lambda->nlocal);
 
     value_size = value_count * sizeof(njs_value_t *);
-    temp_size = lambda->temp * sizeof(njs_value_t *);
 
-    frame_size = value_size + temp_size
-                        + ((value_count + lambda->temp) * sizeof(njs_value_t));
+    frame_size = value_size + (value_count * sizeof(njs_value_t));
 
     native_frame = njs_function_frame_alloc(vm, NJS_FRAME_SIZE + frame_size);
     if (njs_slow_path(native_frame == NULL)) {
@@ -471,9 +469,9 @@ njs_function_lambda_frame(njs_vm_t *vm, 
     /* Local */
 
     new = (njs_value_t **) ((u_char *) native_frame + NJS_FRAME_SIZE);
-    value = (njs_value_t *) ((u_char *) new + value_size + temp_size);
+    value = (njs_value_t *) ((u_char *) new + value_size);
 
-    n = value_count + lambda->temp;
+    n = value_count;
 
     while (n != 0) {
         n--;
@@ -481,15 +479,9 @@ njs_function_lambda_frame(njs_vm_t *vm, 
         njs_set_invalid(new[n]);
     }
 
-    /* Temp */
-
-    temp = (njs_value_t **) ((u_char *) native_frame + NJS_FRAME_SIZE
-                                                     + value_size);
-
     native_frame->arguments = value;
     native_frame->arguments_offset = value + (function->args_offset - 1);
     native_frame->local = new + args_count;
-    native_frame->temp = temp;
     native_frame->function = target;
     native_frame->nargs = nargs;
     native_frame->ctor = ctor;
@@ -614,7 +606,7 @@ njs_function_lambda_call(njs_vm_t *vm, v
     njs_int_t              ret;
     njs_frame_t            *frame;
     njs_value_t            *args, **local, *value;
-    njs_value_t            **cur_local, **cur_closures, **cur_temp;
+    njs_value_t            **cur_local, **cur_closures;
     njs_function_t         *function;
     njs_declaration_t      *declr;
     njs_function_lambda_t  *lambda;
@@ -650,13 +642,11 @@ njs_function_lambda_call(njs_vm_t *vm, v
 
     cur_local = vm->levels[NJS_LEVEL_LOCAL];
     cur_closures = vm->levels[NJS_LEVEL_CLOSURE];
-    cur_temp = vm->levels[NJS_LEVEL_TEMP];
 
     /* Replace current level. */
 
     vm->levels[NJS_LEVEL_LOCAL] = vm->top_frame->local;
     vm->levels[NJS_LEVEL_CLOSURE] = njs_function_closures(function);
-    vm->levels[NJS_LEVEL_TEMP] = frame->native.temp;
 
     if (lambda->rest_parameters) {
         ret = njs_function_rest_parameters_init(vm, &frame->native);
@@ -705,7 +695,6 @@ njs_function_lambda_call(njs_vm_t *vm, v
     /* Restore current level. */
     vm->levels[NJS_LEVEL_LOCAL] = cur_local;
     vm->levels[NJS_LEVEL_CLOSURE] = cur_closures;
-    vm->levels[NJS_LEVEL_TEMP] = cur_temp;
 
     return ret;
 }
@@ -805,9 +794,10 @@ njs_function_frame_free(njs_vm_t *vm, nj
 njs_int_t
 njs_function_frame_save(njs_vm_t *vm, njs_frame_t *frame, u_char *pc)
 {
-    size_t              value_count, n;
+    size_t              args_count, value_count, n;
     njs_value_t         *start, *end, *p, **new, *value, **local;
     njs_function_t      *function;
+    njs_function_lambda_t  *lambda;
     njs_native_frame_t  *active, *native;
 
     *frame = *vm->active_frame;
@@ -820,19 +810,18 @@ njs_function_frame_save(njs_vm_t *vm, nj
     native->free_size = 0;
 
     active = &vm->active_frame->native;
-    value_count = njs_function_frame_value_count(active);
+    function = active->function;
+    lambda = function->u.lambda;
 
-    function = active->function;
+    args_count = function->args_offset + njs_max(native->nargs, lambda->nargs);
+    value_count = args_count + njs_max(args_count, lambda->nlocal);
 
     new = (njs_value_t **) ((u_char *) native + NJS_FRAME_SIZE);
-    value = (njs_value_t *) (new + value_count
-                             + function->u.lambda->temp);
-
+    value = (njs_value_t *) (new + value_count);
 
     native->arguments = value;
     native->arguments_offset = value + (function->args_offset - 1);
     native->local = new + njs_function_frame_args_count(active);
-    native->temp = new + value_count;
     native->pc = pc;
 
     start = njs_function_frame_values(active, &end);
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_function.h
--- a/src/njs_function.h	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_function.h	Wed May 18 00:01:05 2022 -0700
@@ -12,7 +12,6 @@ struct njs_function_lambda_s {
     njs_index_t                    *closures;
     uint32_t                       nclosures;
     uint32_t                       nlocal;
-    uint32_t                       temp;
 
     njs_declaration_t              *declarations;
     uint32_t                       ndeclarations;
@@ -50,7 +49,6 @@ struct njs_native_frame_s {
     njs_object_t                   *arguments_object;
     njs_value_t                    *arguments_offset;
     njs_value_t                    **local;
-    njs_value_t                    **temp;
 
     uint32_t                       size;
     uint32_t                       free_size;
@@ -229,17 +227,6 @@ njs_function_frame_args_count(njs_native
 }
 
 
-njs_inline size_t
-njs_function_frame_value_count(njs_native_frame_t *frame)
-{
-    uintptr_t  start;
-
-    start = (uintptr_t) ((u_char *) frame + NJS_FRAME_SIZE);
-
-    return ((uintptr_t) frame->temp - start) / sizeof(njs_value_t *);
-}
-
-
 njs_inline njs_value_t *
 njs_function_frame_values(njs_native_frame_t *frame, njs_value_t **end)
 {
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_generator.c
--- a/src/njs_generator.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_generator.c	Wed May 18 00:01:05 2022 -0700
@@ -3698,7 +3698,6 @@ njs_generate_function_scope(njs_vm_t *vm
     lambda->closures = generator.closures->start;
     lambda->nclosures = generator.closures->items;
     lambda->nlocal = node->scope->items;
-    lambda->temp = node->scope->temp;
 
     arr = node->scope->declarations;
     lambda->declarations = (arr != NULL) ? arr->start : NULL;
@@ -4916,7 +4915,7 @@ njs_generate_temp_index_get(njs_vm_t *vm
         return NJS_ERROR;
     }
 
-    return njs_scope_index(scope->type, scope->temp++, NJS_LEVEL_TEMP,
+    return njs_scope_index(scope->type, scope->items++, NJS_LEVEL_LOCAL,
                            NJS_VARIABLE_VAR);
 }
 
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_parser.c
--- a/src/njs_parser.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_parser.c	Wed May 18 00:01:05 2022 -0700
@@ -562,7 +562,6 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
         }
 
     } else {
-        parser->scope->temp = 0;
         parser->scope->top = NULL;
         parser->node = NULL;
         parser->ret = NJS_OK;
@@ -1357,6 +1356,8 @@ njs_parser_template_literal(njs_parser_t
             return NJS_ERROR;
         }
 
+        node->temporary = 1;
+
         template->right = node;
         temp->right = node;
 
@@ -1370,6 +1371,7 @@ njs_parser_template_literal(njs_parser_t
         temp->right = template;
     }
 
+    temp->temporary = 1;
     temp->left = template;
     temp->index = index;
 
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_parser.h
--- a/src/njs_parser.h	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_parser.h	Wed May 18 00:01:05 2022 -0700
@@ -20,7 +20,6 @@ struct njs_parser_scope_s {
     njs_arr_t                       *closures;
     njs_arr_t                       *declarations;
 
-    uint32_t                        temp;
     uint32_t                        items;
 
     njs_scope_t                     type:8;
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_scope.c
--- a/src/njs_scope.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_scope.c	Wed May 18 00:01:05 2022 -0700
@@ -20,7 +20,7 @@ njs_scope_temp_index(njs_parser_scope_t 
         return NJS_INDEX_ERROR;
     }
 
-    return njs_scope_index(NJS_SCOPE_GLOBAL, scope->temp++, NJS_LEVEL_TEMP,
+    return njs_scope_index(scope->type, scope->items++, NJS_LEVEL_LOCAL,
                            NJS_VARIABLE_VAR);
 }
 
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_vm.c
--- a/src/njs_vm.c	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_vm.c	Wed May 18 00:01:05 2022 -0700
@@ -226,17 +226,6 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
     vm->variables_hash = &scope->variables;
     vm->global_items = scope->items;
 
-    vm->levels[NJS_LEVEL_TEMP] = NULL;
-
-    if (scope->temp != 0) {
-        new = njs_scope_make(vm, scope->temp);
-        if (njs_slow_path(new == NULL)) {
-            return ret;
-        }
-
-        vm->levels[NJS_LEVEL_TEMP] = new;
-    }
-
     if (vm->options.disassemble) {
         njs_disassembler(vm);
     }
@@ -305,7 +294,6 @@ njs_vm_compile_module(njs_vm_t *vm, njs_
 
     lambda->start = generator.code_start;
     lambda->nlocal = scope->items;
-    lambda->temp = scope->temp;
 
     arr = scope->declarations;
     lambda->declarations = (arr != NULL) ? arr->start : NULL;
diff -r c48ecb7b24d7 -r aa27056f4bc9 src/njs_vm.h
--- a/src/njs_vm.h	Tue May 17 23:26:09 2022 -0700
+++ b/src/njs_vm.h	Wed May 18 00:01:05 2022 -0700
@@ -122,7 +122,6 @@ typedef enum {
     NJS_LEVEL_CLOSURE,
     NJS_LEVEL_GLOBAL,
     NJS_LEVEL_STATIC,
-    NJS_LEVEL_TEMP,
     NJS_LEVEL_MAX
 } njs_level_type_t;
 



More information about the nginx-devel mailing list