From efb0896f21e03f64e3a14e7c09994e81956f47b9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 3 Apr 2023 15:21:24 +0200 Subject: refactor(api): make typed dicts appear as types in the source code problem: can we have Serde? solution: we have Serde at home This by itself is just a change of notation, that could be quickly merged to avoid messy merge conflicts, but upcoming changes are planned: - keysets no longer need to be defined in one single file. `keysets.h` is just the initial automatic conversion of the previous `keysets.lua`. keysets just used in a single api/{scope}.h can be moved to that file, later on. - Typed dicts will have more specific types than Object. this will enable most of the existing manual typechecking boilerplate to be eliminated. We will need some annotation for missing value, i e a boolean will need to be represented as a TriState (none/false/true) in some cases. - Eventually: optional parameters in form of a `Dict opts` final parameter will get added in some form to metadata. this will require a discussion/desicion about type forward compatibility. --- src/nvim/api/extmark.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 0a627a889c..a6586e3031 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -1,6 +1,7 @@ #ifndef NVIM_API_EXTMARK_H #define NVIM_API_EXTMARK_H +#include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" #include "nvim/decoration.h" #include "nvim/macros.h" -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/api/extmark.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index a6586e3031..3c979fa4f6 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -6,7 +6,6 @@ #include "nvim/decoration.h" #include "nvim/macros.h" #include "nvim/map.h" -#include "nvim/map_defs.h" #include "nvim/types.h" EXTERN Map(String, handle_T) namespace_ids INIT(= MAP_INIT); -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Codeā„¢, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- src/nvim/api/extmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 3c979fa4f6..a7baad496f 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -8,7 +8,7 @@ #include "nvim/map.h" #include "nvim/types.h" -EXTERN Map(String, handle_T) namespace_ids INIT(= MAP_INIT); +EXTERN Map(String, int) namespace_ids INIT(= MAP_INIT); EXTERN handle_T next_namespace_id INIT(= 1); #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/api/extmark.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index a7baad496f..7c300350e1 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -8,8 +8,8 @@ #include "nvim/map.h" #include "nvim/types.h" -EXTERN Map(String, int) namespace_ids INIT(= MAP_INIT); -EXTERN handle_T next_namespace_id INIT(= 1); +EXTERN Map(String, int) namespace_ids INIT( = MAP_INIT); +EXTERN handle_T next_namespace_id INIT( = 1); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/extmark.h.generated.h" -- cgit From 4f8941c1a5f1ef6caa410feeb52e343db22763ce Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 12:23:42 +0100 Subject: refactor: replace manual header guards with #pragma once It is less error-prone than manually defining header guards. Pretty much all compilers support it even if it's not part of the C standard. --- src/nvim/api/extmark.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 7c300350e1..88f1e9e8ad 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -1,5 +1,4 @@ -#ifndef NVIM_API_EXTMARK_H -#define NVIM_API_EXTMARK_H +#pragma once #include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" @@ -14,4 +13,3 @@ EXTERN handle_T next_namespace_id INIT( = 1); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/extmark.h.generated.h" #endif -#endif // NVIM_API_EXTMARK_H -- cgit From 574d25642fc9ca65b396633aeab6e2d32778b642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 17:21:58 +0800 Subject: refactor: move Arena and ArenaMem to memory_defs.h (#26240) --- src/nvim/api/extmark.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 88f1e9e8ad..d41a9828be 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -1,8 +1,10 @@ #pragma once +#include // IWYU pragma: keep + #include "nvim/api/keysets.h" -#include "nvim/api/private/defs.h" -#include "nvim/decoration.h" +#include "nvim/api/private/defs.h" // IWYU pragma: keep +#include "nvim/decoration_defs.h" // IWYU pragma: keep #include "nvim/macros.h" #include "nvim/map.h" #include "nvim/types.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- src/nvim/api/extmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index d41a9828be..0a28be98c5 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -2,7 +2,7 @@ #include // IWYU pragma: keep -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/decoration_defs.h" // IWYU pragma: keep #include "nvim/macros.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/api/extmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 0a28be98c5..2989dee53d 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -7,7 +7,7 @@ #include "nvim/decoration_defs.h" // IWYU pragma: keep #include "nvim/macros.h" #include "nvim/map.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" EXTERN Map(String, int) namespace_ids INIT( = MAP_INIT); EXTERN handle_T next_namespace_id INIT( = 1); -- cgit From 718053b7a97c4e2fbaa6077d3c9f4dc7012c8aad Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Nov 2023 07:47:36 +0800 Subject: refactor: fix runtime_defs.h (#26259) --- src/nvim/api/extmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 2989dee53d..491e468d95 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -2,7 +2,7 @@ #include // IWYU pragma: keep -#include "nvim/api/keysets_defs.h" +#include "nvim/api/keysets_defs.h" // IWYU pragma: keep #include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/decoration_defs.h" // IWYU pragma: keep #include "nvim/macros.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/api/extmark.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/extmark.h') diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h index 491e468d95..124feaabfb 100644 --- a/src/nvim/api/extmark.h +++ b/src/nvim/api/extmark.h @@ -5,8 +5,8 @@ #include "nvim/api/keysets_defs.h" // IWYU pragma: keep #include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/decoration_defs.h" // IWYU pragma: keep -#include "nvim/macros.h" -#include "nvim/map.h" +#include "nvim/macros_defs.h" +#include "nvim/map_defs.h" #include "nvim/types_defs.h" EXTERN Map(String, int) namespace_ids INIT( = MAP_INIT); -- cgit