[gnome-builder/wip/clang-cache] clang: overwrite previously cached entry when needed



commit 65fdeacd5513d69b150cae7bb3e99ca762d19bd9
Author: Christian Hergert <christian hergert me>
Date:   Tue May 12 22:27:46 2015 -0700

    clang: overwrite previously cached entry when needed
    
    Update the cached entry if our new serial is greater than the previously
    cached value. This brings back interactive diagnostics using the
    cache evicting EggTaskCache.

 libide/clang/ide-clang-completion-provider.c |    3 +-
 libide/clang/ide-clang-diagnostic-provider.c |    2 +
 libide/clang/ide-clang-private.h             |    2 +-
 libide/clang/ide-clang-service.c             |   23 ++++++++++++
 libide/clang/ide-clang-service.h             |    1 +
 libide/clang/ide-clang-symbol-resolver.c     |    2 +
 libide/clang/ide-clang-translation-unit.c    |   48 ++++++++++++++++---------
 libide/clang/ide-clang-translation-unit.h    |    2 +-
 8 files changed, 63 insertions(+), 20 deletions(-)
---
diff --git a/libide/clang/ide-clang-completion-provider.c b/libide/clang/ide-clang-completion-provider.c
index 895c9d0..ce03e36 100644
--- a/libide/clang/ide-clang-completion-provider.c
+++ b/libide/clang/ide-clang-completion-provider.c
@@ -347,7 +347,8 @@ ide_clang_completion_provider_populate (GtkSourceCompletionProvider *provider,
 
   ide_clang_service_get_translation_unit_async (service,
                                                 file,
-                                                NULL,
+                                                0,
+                                                state->cancellable,
                                                 ide_clang_completion_provider_tu_cb,
                                                 state);
 
diff --git a/libide/clang/ide-clang-diagnostic-provider.c b/libide/clang/ide-clang-diagnostic-provider.c
index 296b57f..f1121e1 100644
--- a/libide/clang/ide-clang-diagnostic-provider.c
+++ b/libide/clang/ide-clang-diagnostic-provider.c
@@ -100,6 +100,7 @@ ide_clang_diagnostic_provider_diagnose__file_find_other_cb (GObject      *object
 
   ide_clang_service_get_translation_unit_async (service,
                                                 file,
+                                                0,
                                                 g_task_get_cancellable (task),
                                                 get_translation_unit_cb,
                                                 g_object_ref (task));
@@ -137,6 +138,7 @@ ide_clang_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider,
 
       ide_clang_service_get_translation_unit_async (service,
                                                     file,
+                                                    0,
                                                     cancellable,
                                                     get_translation_unit_cb,
                                                     g_object_ref (task));
diff --git a/libide/clang/ide-clang-private.h b/libide/clang/ide-clang-private.h
index ee69930..0f73654 100644
--- a/libide/clang/ide-clang-private.h
+++ b/libide/clang/ide-clang-private.h
@@ -33,7 +33,7 @@ IdeClangTranslationUnit *_ide_clang_translation_unit_new (IdeContext        *con
                                                           CXTranslationUnit  tu,
                                                           GFile             *file,
                                                           IdeHighlightIndex *index,
-                                                          gint64             sequence);
+                                                          gint64             serial);
 void                     _ide_clang_dispose_string       (CXString          *str);
 
 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (CXString, _ide_clang_dispose_string)
diff --git a/libide/clang/ide-clang-service.c b/libide/clang/ide-clang-service.c
index b033f3b..4d2c3e5 100644
--- a/libide/clang/ide-clang-service.c
+++ b/libide/clang/ide-clang-service.c
@@ -466,10 +466,12 @@ ide_clang_service_get_translation_unit_cb (GObject      *object,
 void
 ide_clang_service_get_translation_unit_async (IdeClangService     *self,
                                               IdeFile             *file,
+                                              gint64               min_serial,
                                               GCancellable        *cancellable,
                                               GAsyncReadyCallback  callback,
                                               gpointer             user_data)
 {
+  IdeClangTranslationUnit *cached;
   g_autoptr(GTask) task = NULL;
 
   g_return_if_fail (IDE_IS_CLANG_SERVICE (self));
@@ -478,8 +480,29 @@ ide_clang_service_get_translation_unit_async (IdeClangService     *self,
 
   task = g_task_new (self, cancellable, callback, user_data);
 
+  if (min_serial == 0)
+    {
+      IdeContext *context;
+      IdeUnsavedFiles *unsaved_files;
+
+      context = ide_object_get_context (IDE_OBJECT (self));
+      unsaved_files = ide_context_get_unsaved_files (context);
+      min_serial = ide_unsaved_files_get_sequence (unsaved_files);
+    }
+
+  /*
+   * If we have a cached unit, and it is new enough, then re-use it.
+   */
+  if ((cached = egg_task_cache_peek (self->units_cache, file)) &&
+      (ide_clang_translation_unit_get_serial (cached) >= min_serial))
+    {
+      g_task_return_pointer (task, g_object_ref (cached), g_object_unref);
+      return;
+    }
+
   egg_task_cache_get_async (self->units_cache,
                             file,
+                            TRUE,
                             cancellable,
                             ide_clang_service_get_translation_unit_cb,
                             g_object_ref (task));
diff --git a/libide/clang/ide-clang-service.h b/libide/clang/ide-clang-service.h
index 1553c95..d9a36b8 100644
--- a/libide/clang/ide-clang-service.h
+++ b/libide/clang/ide-clang-service.h
@@ -31,6 +31,7 @@ G_DECLARE_FINAL_TYPE (IdeClangService, ide_clang_service, IDE, CLANG_SERVICE, Id
 
 void                     ide_clang_service_get_translation_unit_async  (IdeClangService      *self,
                                                                         IdeFile              *file,
+                                                                        gint64                min_serial,
                                                                         GCancellable         *cancellable,
                                                                         GAsyncReadyCallback   callback,
                                                                         gpointer              user_data);
diff --git a/libide/clang/ide-clang-symbol-resolver.c b/libide/clang/ide-clang-symbol-resolver.c
index 0642ec2..ee200ea 100644
--- a/libide/clang/ide-clang-symbol-resolver.c
+++ b/libide/clang/ide-clang-symbol-resolver.c
@@ -97,6 +97,7 @@ ide_clang_symbol_resolver_lookup_symbol_async (IdeSymbolResolver   *resolver,
 
   ide_clang_service_get_translation_unit_async (service,
                                                 file,
+                                                0,
                                                 cancellable,
                                                 ide_clang_symbol_resolver_lookup_symbol_cb,
                                                 g_object_ref (task));
@@ -183,6 +184,7 @@ ide_clang_symbol_resolver_get_symbols_async (IdeSymbolResolver   *resolver,
 
   ide_clang_service_get_translation_unit_async (service,
                                                 file,
+                                                0,
                                                 cancellable,
                                                 ide_clang_symbol_resolver_get_symbols_cb,
                                                 g_object_ref (task));
diff --git a/libide/clang/ide-clang-translation-unit.c b/libide/clang/ide-clang-translation-unit.c
index 4a2abdb..7c7fa42 100644
--- a/libide/clang/ide-clang-translation-unit.c
+++ b/libide/clang/ide-clang-translation-unit.c
@@ -46,7 +46,7 @@ struct _IdeClangTranslationUnit
   IdeObject          parent_instance;
 
   CXTranslationUnit  tu;
-  gint64             sequence;
+  gint64             serial;
   GFile             *file;
   IdeHighlightIndex *index;
   GHashTable        *diagnostics;
@@ -74,7 +74,8 @@ enum {
   PROP_0,
   PROP_FILE,
   PROP_INDEX,
-  PROP_SEQUENCE,
+  PROP_NATIVE,
+  PROP_SERIAL,
   LAST_PROP
 };
 
@@ -143,7 +144,7 @@ _ide_clang_translation_unit_new (IdeContext        *context,
                                  CXTranslationUnit  tu,
                                  GFile             *file,
                                  IdeHighlightIndex *index,
-                                 gint64             sequence)
+                                 gint64             serial)
 {
   IdeClangTranslationUnit *ret;
 
@@ -155,11 +156,10 @@ _ide_clang_translation_unit_new (IdeContext        *context,
                       "context", context,
                       "file", file,
                       "index", index,
+                      "native", tu,
+                      "serial", serial,
                       NULL);
 
-  ret->tu = tu;
-  ret->sequence = sequence;
-
   return ret;
 }
 
@@ -460,11 +460,11 @@ ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self)
 }
 
 gint64
-ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self)
+ide_clang_translation_unit_get_serial (IdeClangTranslationUnit *self)
 {
   g_return_val_if_fail (IDE_IS_CLANG_TRANSLATION_UNIT (self), -1);
 
-  return self->sequence;
+  return self->serial;
 }
 
 static void
@@ -505,8 +505,8 @@ ide_clang_translation_unit_get_property (GObject    *object,
       g_value_set_boxed (value, ide_clang_translation_unit_get_index (self));
       break;
 
-    case PROP_SEQUENCE:
-      g_value_set_int64 (value, ide_clang_translation_unit_get_sequence (self));
+    case PROP_SERIAL:
+      g_value_set_int64 (value, ide_clang_translation_unit_get_serial (self));
       break;
 
     default:
@@ -532,6 +532,14 @@ ide_clang_translation_unit_set_property (GObject      *object,
       ide_clang_translation_unit_set_index (self, g_value_get_boxed (value));
       break;
 
+    case PROP_SERIAL:
+      self->serial = g_value_get_int64 (value);
+      break;
+
+    case PROP_NATIVE:
+      self->tu = g_value_get_pointer (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -558,16 +566,22 @@ ide_clang_translation_unit_class_init (IdeClangTranslationUnitClass *klass)
                          _("Index"),
                          _("The highlight index for the translation unit."),
                          IDE_TYPE_HIGHLIGHT_INDEX,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |G_PARAM_STATIC_STRINGS));
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
-  gParamSpecs [PROP_SEQUENCE] =
-    g_param_spec_int64 ("sequence",
-                        _("Sequence"),
-                        _("The sequence number when created."),
-                        G_MININT64,
+  gParamSpecs [PROP_NATIVE] =
+    g_param_spec_pointer ("native",
+                          _("Native"),
+                          _("The native translation unit pointer."),
+                          (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  gParamSpecs [PROP_SERIAL] =
+    g_param_spec_int64 ("serial",
+                        _("Serial"),
+                        _("A sequence number for the translation unit."),
+                        0,
                         G_MAXINT64,
                         0,
-                        (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+                        (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
diff --git a/libide/clang/ide-clang-translation-unit.h b/libide/clang/ide-clang-translation-unit.h
index 1604dd0..244307a 100644
--- a/libide/clang/ide-clang-translation-unit.h
+++ b/libide/clang/ide-clang-translation-unit.h
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeClangTranslationUnit, ide_clang_translation_unit, IDE, CLANG_TRANSLATION_UNIT, 
IdeObject)
 
-gint64             ide_clang_translation_unit_get_sequence             (IdeClangTranslationUnit  *self);
+gint64             ide_clang_translation_unit_get_serial               (IdeClangTranslationUnit  *self);
 IdeDiagnostics    *ide_clang_translation_unit_get_diagnostics          (IdeClangTranslationUnit  *self);
 IdeDiagnostics    *ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit  *self,
                                                                         GFile                    *file);


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