emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 5dedd4f295 4/5: Race condition seems to be re


From: Christian Johansson
Subject: [elpa] externals/phps-mode 5dedd4f295 4/5: Race condition seems to be resolved
Date: Fri, 18 Mar 2022 15:47:05 -0400 (EDT)

branch: externals/phps-mode
commit 5dedd4f29596edeb6ce44ada39cbbb661dca8542
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Race condition seems to be resolved
---
 TODO.md                   | 10 ++--------
 phps-mode-lex-analyzer.el | 50 ++++++++++++++++++++---------------------------
 phps-mode-serial.el       |  1 -
 phps-mode.el              | 10 ++++++++--
 4 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/TODO.md b/TODO.md
index f1bd6ff500..57cc5ba73c 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,12 +2,6 @@
 
 ## Code intelligence
 
-* Fix race-condition in incremental parser when running asynchronous using 
threads
-
-Perform an edit while an incremental parse is going to reproduce
-
-Fix by reloading file or running C-r to rescan and clear cache
-
 * Bookkeeping of chained object operators like WC()->cart->subtotal
 * Bookkeeping of variables inside classes with multiple methods seems to not 
work
 * Move bookkeeping and imenu generation to main thread to be able to populate 
Sematic Subsystem in the future
@@ -17,5 +11,5 @@ Fix by reloading file or running C-r to rescan and clear cache
 
 ## Other
 
-* Support for mmm-mode or similar
-* Build in eldoc support like php-eldoc
\ No newline at end of file
+* Support for mmm-mode or similar?
+* Build in eldoc support like php-eldoc?
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 40a84cf572..7fa1f25530 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -201,8 +201,8 @@
            phps-mode-lex-analyzer--lexer-index
            (cdr (cdr (car phps-mode-lexer--generated-new-tokens)))))))))
 
-(defun phps-mode-lex-analyzer--re2c-run (&optional allow-cache-read 
force-synchronous)
-  "Run lexer, optionally ALLOW-CACHE-READ and FORCE-SYNCHRONOUS mode."
+(defun phps-mode-lex-analyzer--re2c-run (&optional force-synchronous 
allow-cache-read allow-cache-write)
+  "Run lexer, optionally FORCE-SYNCHRONOUS mode, ALLOW-CACHE-READ and 
ALLOW-CACHE-WRITE."
   (interactive)
   (require 'phps-mode-macros)
   (phps-mode-debug-message (message "Lexer run"))
@@ -216,8 +216,6 @@
     (when force-synchronous
       (setq async nil))
 
-    (message "Starting new serial-command 1: %S" buffer-name)
-
     (phps-mode-serial-commands
      buffer-name
 
@@ -234,14 +232,13 @@
         nil
         nil
         buffer-file-name
-        allow-cache-read))
+        allow-cache-read
+        allow-cache-write))
 
      (lambda(lex-result)
        (when (get-buffer buffer-name)
          (with-current-buffer buffer-name
 
-           (message "%S Serial command 1 step 2 start: %S" (current-thread) 
buffer-name)
-
            ;; Move variables into this buffers local variables
            (setq phps-mode-lex-analyzer--tokens (nth 0 lex-result))
            (setq phps-mode-lex-analyzer--states (nth 1 lex-result))
@@ -272,8 +269,6 @@
            ;; Reset buffer changes minimum index
            (phps-mode-lex-analyzer--reset-changes)
 
-           (message "%S Serial command 1 step 2 end: %S" (current-thread) 
buffer-name)
-
            ;; Signal parser error (if any)
            (when phps-mode-lex-analyzer--parse-error
 
@@ -346,7 +341,7 @@
 
 (defun phps-mode-lex-analyzer--incremental-lex-string
     (buffer-name buffer-contents incremental-start-new-buffer point-max
-                 head-states incremental-state incremental-state-stack 
incremental-heredoc-label incremental-heredoc-label-stack 
incremental-nest-location-stack head-tokens &optional force-synchronous 
filename)
+                 head-states incremental-state incremental-state-stack 
incremental-heredoc-label incremental-heredoc-label-stack 
incremental-nest-location-stack head-tokens &optional force-synchronous 
filename allow-cache-write)
   "Incremental lex region."
   (let ((async (and (boundp 'phps-mode-async-process)
                     phps-mode-async-process))
@@ -355,8 +350,6 @@
     (when force-synchronous
       (setq async nil))
 
-    (message "Starting new serial-command 2: %S" buffer-name)
-
     (phps-mode-serial-commands
 
      buffer-name
@@ -373,14 +366,14 @@
         incremental-heredoc-label-stack
         incremental-nest-location-stack
         head-tokens
-        filename))
+        filename
+        nil
+        allow-cache-write))
 
      (lambda(lex-result)
        (when (get-buffer buffer-name)
          (with-current-buffer buffer-name
 
-           (message "%S Serial command 2 step 2 start: %S" (current-thread) 
buffer-name)
-
            (phps-mode-debug-message
             (message "Incrementally-lexed-string: %s" result))
 
@@ -418,8 +411,6 @@
            ;; Reset buffer changes minimum index
            (phps-mode-lex-analyzer--reset-changes)
 
-           (message "%S Serial command 2 step 2 end: %S" (current-thread) 
buffer-name)
-
            ;; Signal parser error (if any)
            (when phps-mode-lex-analyzer--parse-error
 
@@ -698,7 +689,8 @@
                              incremental-nest-location-stack
                              head-tokens
                              force-synchronous
-                             (if (buffer-modified-p) nil buffer-file-name))
+                             (if (buffer-modified-p) nil buffer-file-name)
+                             (not (buffer-modified-p)))
 
                             (phps-mode-debug-message
                              (message "Incremental tokens: %s" 
incremental-tokens)))
@@ -724,7 +716,10 @@
           (push (list 'RUN-FULL-LEXER) log)
           (phps-mode-debug-message
            (message "Running full lexer"))
-          (phps-mode-lex-analyzer--re2c-run nil force-synchronous))
+          (phps-mode-lex-analyzer--re2c-run
+           force-synchronous
+           nil
+           (not (buffer-modified-p))))
 
         log))))
 
@@ -832,8 +827,6 @@
 
         ;; Kill active thread (if any)
         (phps-mode-serial--kill-active (buffer-name))
-
-        (message "Killing active thread (if any exists): %S" (buffer-name))
         
         ;; If we haven't scheduled incremental lexer before - do it
         (when (and (boundp 'phps-mode-idle-interval)
@@ -1089,7 +1082,7 @@
          token-start)))
     parser-tokens))
 
-(defun phps-mode-lex-analyzer--lex-string (contents &optional start end states 
state state-stack heredoc-label heredoc-label-stack nest-location-stack tokens 
filename allow-cache-read)
+(defun phps-mode-lex-analyzer--lex-string (contents &optional start end states 
state state-stack heredoc-label heredoc-label-stack nest-location-stack tokens 
filename allow-cache-read allow-cache-write)
   "Run lexer on CONTENTS."
   ;; Create a separate buffer, run lexer inside of it, catch errors and return 
them
   ;; to enable nice presentation
@@ -1098,22 +1091,20 @@
   (let ((loaded-from-cache)
         (cache-key))
 
-    ;; Load cache if possible
+    ;; Build cache key if possible
     (when (and
            phps-mode-cache--use-p
-           filename
-           (not start)
-           (not end))
+           filename)
       (setq
        cache-key
        filename)
+
+      ;; Load cache if possible and permitted
       (when (and
              allow-cache-read
              (phps-mode-cache-test-p
               cache-key
               filename))
-        (message
-         "Loaded from cache: %S" cache-key)
         (setq
          loaded-from-cache
          (phps-mode-cache-load
@@ -1237,8 +1228,9 @@
           ;; Save cache if possible and permitted
           (when (and
                  phps-mode-cache--use-p
+                 allow-cache-write
                  cache-key)
-            (message "Saved to cache")
+            ;; (message "Saved to cache")
             (phps-mode-cache-save
              data
              cache-key))
diff --git a/phps-mode-serial.el b/phps-mode-serial.el
index 1ab4a673d8..d359694277 100644
--- a/phps-mode-serial.el
+++ b/phps-mode-serial.el
@@ -61,7 +61,6 @@
   (when (and
          (gethash key phps-mode-serial--async-threads)
          (thread-live-p (gethash key phps-mode-serial--async-threads)))
-    (message "Killing thread: %S" (gethash key 
phps-mode-serial--async-threads))
     (thread-signal (gethash key phps-mode-serial--async-threads) 'quit nil)))
 
 (defun phps-mode-serial-commands (key start end &optional start-error 
end-error async async-by-process)
diff --git a/phps-mode.el b/phps-mode.el
index ffdcc87a25..9fe415eab6 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -78,7 +78,10 @@
   "Re-scan buffer."
   (interactive)
   (phps-mode-lex-analyzer--reset-local-variables t)
-  (phps-mode-lex-analyzer--re2c-run nil))
+  (phps-mode-lex-analyzer--re2c-run
+   nil
+   (not (buffer-modified-p))
+   (not (buffer-modified-p))))
 
 ;;;###autoload
 (defun phps-mode-flycheck-setup ()
@@ -239,7 +242,10 @@
    t)
 
   ;; Initial run of lexer
-  (phps-mode-lex-analyzer--re2c-run t))
+  (phps-mode-lex-analyzer--re2c-run
+   nil
+   (not (buffer-modified-p))
+   (not (buffer-modified-p))))
 
 (provide 'phps-mode)
 ;;; phps-mode.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]