Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,586 changes: 1,555 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type-hash = { path = "crates/type-hash" }
type-hash-derive = { path = "crates/type-hash-derive" }


alloy-primitives = "1"
auto_impl = "1.2.0"
bincode = "1.3.3"
bitcode = { features = ["serde"], version = "0.6.3" }
Expand Down Expand Up @@ -83,6 +84,7 @@ thiserror = "1.0.58"
tinyvec = "1.10.0"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
uuid = "1"
wincode = "0.5"
wincode-derive = "0.4"
zstd = "0.13.2"
Expand Down
10 changes: 10 additions & 0 deletions crates/flux-utils/src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,16 @@ impl<T: TypeHash + Copy, const N: usize> TypeHash for ArrayVec<T, N> {
};
}

impl<const N: usize> TypeHash for ArrayStr<N> {
const TYPE_HASH: u64 = {
let mut h = 0xcbf2_9ce4_8422_2325u64;
h = fnv1a64_str(h, "ArrayStr");
h = hash_u64(h, N as u64);
h = hash_layout_of::<Self>(h);
h
};
}

mod serde_impl {
use core::fmt;

Expand Down
22 changes: 16 additions & 6 deletions crates/flux-versioned-types-macros/src/evolve/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap;
use syn::{Attribute, Ident, Type, Visibility};

use super::parse::{AddField, EvolutionOp, EvolveInput, EvolveStruct, ModifyField, StructField};
use crate::shared::is_closure;
use crate::shared::{is_closure, without_schema_attrs};

pub(crate) struct FieldInfo {
pub attrs: Vec<Attribute>,
Expand Down Expand Up @@ -73,12 +73,13 @@ pub(crate) fn generate_struct_def(
}

pub(crate) fn generate_base_struct(input: &EvolveInput) -> (TokenStream2, Vec<FieldInfo>) {
let is_final = input.evolutions.is_empty();
let fields: Vec<_> = input
.base
.items
.iter()
.map(|f| {
let attrs = &f.attrs;
let attrs = emitted_attrs(&f.attrs, is_final);
let vis = &f.vis;
let name = &f.name;
let ty = &f.ty;
Expand All @@ -94,9 +95,17 @@ pub(crate) fn generate_base_struct(input: &EvolveInput) -> (TokenStream2, Vec<Fi
(output, field_infos)
}

/// Field attributes for an emitted version: schema-only attributes survive
/// only on the final, queryable version, while the accumulated `FieldInfo`
/// keeps them for later steps. Version-level attributes are never stripped.
fn emitted_attrs(attrs: &[Attribute], is_final: bool) -> Vec<Attribute> {
if is_final { attrs.to_vec() } else { without_schema_attrs(attrs) }
}

fn generate_evolved_struct_fields(
kept_fields: &[&FieldInfo],
ctx: &EvolutionContext,
is_final: bool,
) -> Vec<TokenStream2> {
kept_fields
.iter()
Expand All @@ -106,21 +115,21 @@ fn generate_evolved_struct_fields(

ctx.modify_map.get(&name_str).map_or_else(
|| {
let attrs = &f.attrs;
let attrs = emitted_attrs(&f.attrs, is_final);
let vis = &f.vis;
let ty = &f.ty;
quote! { #(#attrs)* #vis #name: #ty }
},
|modify| {
let attrs = &modify.attrs;
let attrs = emitted_attrs(&modify.attrs, is_final);
let vis = &f.vis;
let ty = &modify.new_ty;
quote! { #(#attrs)* #vis #name: #ty }
},
)
})
.chain(ctx.add_fields.iter().map(|f| {
let attrs = &f.attrs;
let attrs = emitted_attrs(&f.attrs, is_final);
let vis = &f.vis;
let name = &f.name;
let ty = &f.ty;
Expand Down Expand Up @@ -222,13 +231,14 @@ pub(crate) fn generate_evolution(
default_attrs: &[Attribute],
current_fields: &[FieldInfo],
prev_name: &Ident,
is_final: bool,
) -> (TokenStream2, Vec<FieldInfo>) {
let ctx = EvolutionContext::from_evolution(evolution);

let kept_fields: Vec<_> =
current_fields.iter().filter(|f| !ctx.remove_names.contains(&f.name.to_string())).collect();

let struct_fields = generate_evolved_struct_fields(&kept_fields, &ctx);
let struct_fields = generate_evolved_struct_fields(&kept_fields, &ctx, is_final);
let struct_def =
generate_struct_def(&evolution.name, default_attrs, &evolution.attrs, &struct_fields);
let into_impl = generate_into_impl(prev_name, &evolution.name, &kept_fields, &ctx);
Expand Down
21 changes: 16 additions & 5 deletions crates/flux-versioned-types-macros/src/evolve_enum/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ use syn::{Attribute, Expr, Ident, Index};
use super::parse::{
EnumVariant, EvolveEnum, EvolveEnumInput, EvolveEnumOp, ModifyVariant, RemoveVariant,
};
use crate::shared::is_closure;
use crate::shared::{is_closure, without_schema_attrs};

fn generate_enum_def(
name: &Ident,
default_attrs: &[Attribute],
enum_attrs: &[Attribute],
variants: &[EnumVariant],
is_final: bool,
) -> TokenStream2 {
let emit_attrs = |attrs: &[Attribute]| {
if is_final { attrs.to_vec() } else { without_schema_attrs(attrs) }
};
let variant_tokens: Vec<_> = variants
.iter()
.map(|v| {
let vattrs = &v.attrs;
let vattrs = emit_attrs(&v.attrs);
let vname = &v.name;
let disc = v.discriminant.as_ref().map(|d| quote! { = #d });
if v.is_unit() {
Expand All @@ -27,7 +31,7 @@ fn generate_enum_def(
.fields
.iter()
.map(|f| {
let fattrs = &f.attrs;
let fattrs = emit_attrs(&f.attrs);
let ty = &f.ty;
quote! { #(#fattrs)* #ty }
})
Expand Down Expand Up @@ -214,6 +218,7 @@ pub(crate) fn generate_base_enum(input: &EvolveEnumInput) -> (TokenStream2, Vec<
&input.default_attrs,
&input.base.attrs,
&input.base.items,
input.evolutions.is_empty(),
);

(output, input.base.items.clone())
Expand All @@ -224,6 +229,7 @@ pub(crate) fn generate_evolution(
default_attrs: &[Attribute],
current_variants: &[EnumVariant],
prev_name: &Ident,
is_final: bool,
) -> (TokenStream2, Vec<EnumVariant>) {
let mut add_variants = Vec::new();
let mut remove_map = FxHashMap::default();
Expand Down Expand Up @@ -274,8 +280,13 @@ pub(crate) fn generate_evolution(
new_variants.push(av.clone());
}

let enum_def =
generate_enum_def(&evolution.name, default_attrs, &evolution.attrs, &new_variants);
let enum_def = generate_enum_def(
&evolution.name,
default_attrs,
&evolution.attrs,
&new_variants,
is_final,
);
let into_impl = generate_into_impl(
prev_name,
&evolution.name,
Expand Down
6 changes: 6 additions & 0 deletions crates/flux-versioned-types-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use proc_macro::TokenStream;
mod evolve;
mod evolve_enum;
mod rolling;
mod schema;
mod shared;

#[proc_macro]
Expand All @@ -19,3 +20,8 @@ pub fn evolve_enum(input: TokenStream) -> TokenStream {
pub fn roll_chain_into(input: TokenStream) -> TokenStream {
rolling::roll_chain_into(input)
}

#[proc_macro_derive(TelemetrySchema, attributes(serde, telemetry_schema))]
pub fn derive_telemetry_schema(input: TokenStream) -> TokenStream {
schema::derive_telemetry_schema(input)
}
Loading