introduce vere/version.h

version numbers - currently for u3e and u3v - should be kept in their own header
to avoid dependency loops since anything should be able to source these.

I would like to avoid literal comparison like:

if (ver_w == 2) { }

and instead opt for

if (ver_w == U3V_VER2) { }

or

if (ver_w == U3V_LATEST) { }

Though this may seem overkill at first given the only version we've incremented
is u3H->ver_w, this is the simplest solution to avoid dependency loops
This commit is contained in:
barter-simsum 2023-01-25 13:17:56 -05:00
parent 7028310886
commit 8b0438ab3b
7 changed files with 65 additions and 39 deletions

View File

@ -377,10 +377,10 @@
*/
inline void u3a_config_loom(c3_w ver_w) {
switch (ver_w) {
case /* U3V_VER1 */ 1:
case U3V_VER1:
u3C.vits_w = 0;
break;
case /* U3V_VER2 */ 2:
case U3V_VER2:
u3C.vits_w = 1;
break;
default:

View File

@ -464,10 +464,10 @@ _ce_patch_verify(u3_ce_patch* pat_u)
c3_w mem_w[pag_wiz_i];
c3_zs ret_zs;
if ( u3e_version != pat_u->con_u->ver_w ) {
if ( U3E_VERLAT != pat_u->con_u->ver_w ) {
fprintf(stderr, "loom: patch version mismatch: have %"PRIc3_w", need %u\r\n",
pat_u->con_u->ver_w,
u3e_version);
U3E_VERLAT);
return c3n;
}
@ -692,7 +692,7 @@ _ce_patch_compose(void)
_ce_patch_create(pat_u);
pat_u->con_u = c3_malloc(sizeof(u3e_control) + (pgs_w * sizeof(u3e_line)));
pat_u->con_u->ver_w = u3e_version;
pat_u->con_u->ver_w = U3E_VERLAT;
pgc_w = 0;
for ( i_w = 0; i_w < nor_w; i_w++ ) {

View File

@ -5,6 +5,7 @@
#include "c3.h"
#include "allocate.h"
#include "version2.h"
/** Data structures.
**/
@ -18,11 +19,11 @@
/* u3e_control: memory change, control file.
*/
typedef struct _u3e_control {
c3_w ver_w; // version number
c3_w nor_w; // new page count north
c3_w sou_w; // new page count south
c3_w pgs_w; // number of changed pages
u3e_line mem_u[0]; // per page
u3e_version ver_w; // version number
c3_w nor_w; // new page count north
c3_w sou_w; // new page count south
c3_w pgs_w; // number of changed pages
u3e_line mem_u[0]; // per page
} u3e_control;
/* u3_cs_patch: memory change, top level.
@ -60,7 +61,6 @@
/** Constants.
**/
# define u3e_version 1
/** Functions.
**/

View File

@ -568,14 +568,14 @@ static void
_pave_home(void)
{
/* a pristine home road will always have compressed references */
u3a_config_loom(/* U3V_LATEST */ 2);
u3a_config_loom(U3V_VERLAT);
c3_w* mem_w = u3_Loom + u3C.walign_w;
c3_w siz_w = c3_wiseof(u3v_home);
c3_w len_w = u3C.wor_i - u3C.walign_w;
u3H = (void *)_pave_north(mem_w, siz_w, len_w);
u3H->ver_w = u3v_version;
u3H->ver_w = U3V_VERLAT;
u3R = &u3H->rod_u;
_pave_parts();
@ -608,15 +608,15 @@ _find_home(void)
// possible that in the snapshot committed, they're different
u3R->cap_p = u3R->mat_p = u3C.wor_i - c3_wiseof(*u3H);
if (u3v_version > ver_w) {
u3m_migrate(u3v_version);
u3a_config_loom(u3v_version);
if (U3V_VERLAT > ver_w) {
u3m_migrate(U3V_VERLAT);
u3a_config_loom(U3V_VERLAT);
}
else if ( u3v_version < ver_w ) {
else if ( U3V_VERLAT < ver_w ) {
fprintf(stderr, "loom: checkpoint version mismatch: "
"have %u, need %u\r\n",
ver_w,
u3v_version);
U3V_VERLAT);
abort();
}
@ -2105,7 +2105,8 @@ _migrate_move(u3a_road *rod_u)
/* ;;: having to do this is strange. Why does u3m_reclaim produce a few
boxes with a null reference count? Is this a bug? By ignoring these
boxes, we're essentially freeing them on move. */
boxes, we're essentially freeing them on move. Pack has the same problem
obviously */
if (!old_u->use_w)
continue;
@ -2146,19 +2147,20 @@ _migrate_move(u3a_road *rod_u)
ver_w - target version
*/
void
u3m_migrate(c3_w ver_w)
u3m_migrate(u3v_version ver_w)
{
if (u3H->ver_w == ver_w)
return;
/* 1 -> 2 is all that is currently supported */
c3_dessert(u3H->ver_w == 1 &&
ver_w == 2);
c3_dessert(u3H->ver_w == U3V_VER1 &&
ver_w == U3V_VER2);
/* only home road migration is supported */
c3_dessert((uintptr_t)u3H == (uintptr_t)u3R);
fprintf(stderr, "loom: migration running. This may take several minutes to perform\r\n");
fprintf(stderr, "loom: have version: %" PRIc3_w " migrating to version: %" PRIc3_w "\r\n",
fprintf(stderr, "loom: migration running. This may take several minutes to perform.\r\n");
fprintf(stderr, "loom: have version: %"PRIc3_w" migrating to version: %"PRIc3_w"\r\n",
u3H->ver_w, ver_w);
/* packing first simplifies migration logic and minimizes required buffer space */

View File

@ -5,6 +5,7 @@
#include "c3.h"
#include "types.h"
#include "version2.h"
/** System management.
**/
@ -163,6 +164,6 @@
ver_w - target version
*/
void
u3m_migrate(c3_w ver_w);
u3m_migrate(u3v_version ver_w);
#endif /* ifndef U3_MANAGE_H */

32
pkg/noun/version2.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef U3_VERSION2_H /* ;;: temporary name until name conflict in new
vere repo is resolved -- possibly by
removing version.h altogether (the one that
defines URBIT_VERSION in BUILD.bazel
genrule version_hdr) and supplying as a -D
argument via "defines" rule
https://bazel.build/reference/be/c-cpp
https://bazel.build/reference/be/make-variables#custom_variables
https://bazel.build/reference/be/make-variables
*/
#define U3_VERSION2_H
/* VORTEX
*/
typedef enum u3v_version {
U3V_VER1 = 1,
/* 1 -> 2: 1 bit pointer compression to enable 8G loom */
U3V_VER2 = 2,
U3V_VERLAT = U3V_VER2,
} u3v_version;
/* EVENTS
*/
typedef enum u3e_version {
U3E_VER1 = 1,
U3E_VERLAT = U3E_VER1,
} u3e_version;
#endif /* ifndef U3_VERSION2_H */

View File

@ -3,8 +3,10 @@
#ifndef U3_VORTEX_H
#define U3_VORTEX_H
#include "allocate.h"
#include "c3.h"
#include "imprison.h"
#include "version2.h"
/** Data structures.
**/
@ -22,9 +24,9 @@
** NB: version must be last for discriminability in north road
*/
typedef struct _u3v_home {
u3a_road rod_u; // storage state
u3v_arvo arv_u; // arvo state
c3_w ver_w; // version number
u3a_road rod_u; // storage state
u3v_arvo arv_u; // arvo state
u3v_version ver_w; // version number
} u3v_home;
@ -37,17 +39,6 @@
/** Constants.
**/
/*
version change log:
1 -> 2:
- 1 bit pointer compression to enable 8G loom
*/
/* ;;: TODO: refactor so that this is possible -- dependency loop if used in options.h */
/* # define U3V_VER1 1 */
/* # define U3V_VER2 2 */
/* # define u3v_version U3V_VER2 */
# define u3v_version 2
/** Functions.
**/