diff --git a/compiler/mono/src/alias_analysis.rs b/compiler/mono/src/alias_analysis.rs index 204c2b9480..c4da70e2b2 100644 --- a/compiler/mono/src/alias_analysis.rs +++ b/compiler/mono/src/alias_analysis.rs @@ -24,7 +24,7 @@ pub fn proc_spec(proc: &Proc) -> Result { // introduce the arguments let mut argument_layouts = Vec::new(); for (i, (layout, symbol)) in proc.args.iter().enumerate() { - let value_id = builder.add_get_tuple_field(block, morphic_lib::ARG_VALUE_ID, i as u32)?; + let value_id = builder.add_get_tuple_field(block, ValueId::ARGUMENT, i as u32)?; env.symbols.insert(*symbol, value_id); argument_layouts.push(*layout); diff --git a/vendor/morphic_lib/src/api.rs b/vendor/morphic_lib/src/api.rs index 632d71b491..f057927ea4 100644 --- a/vendor/morphic_lib/src/api.rs +++ b/vendor/morphic_lib/src/api.rs @@ -91,10 +91,12 @@ pub struct TypeNameBuf(Vec); #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ValueId(pub u32); -/// Value id 0 always refers to the argument to the current function. -/// -/// Every function takes exactly one argument. Multiple arguments can be represented via tuples. -pub const ARG_VALUE_ID: ValueId = ValueId(0); +impl ValueId { + /// The `ValueId` that refers to the argument to the current function. + /// + /// Every function takes exactly one argument. Multiple arguments can be represented via tuples. + pub const ARGUMENT: Self = ValueId(0); +} /// A reference to an arena-allocated join point in a function body. /// @@ -171,12 +173,16 @@ pub trait TypeContext { fn add_bag_type(&mut self, item_type: TypeId) -> Result; } -#[derive(Debug, Default)] +#[derive(Debug)] struct SeqGen { next: u32, } impl SeqGen { + fn new() -> Self { + Self { next: 0 } + } + fn next(&mut self) -> u32 { let result = self.next; self.next += 1; @@ -208,7 +214,7 @@ impl Default for TypeDefBuilder { impl TypeDefBuilder { pub fn new() -> Self { Self { - tid_gen: SeqGen::default(), + tid_gen: SeqGen::new(), } } @@ -304,16 +310,16 @@ impl Default for FuncDefBuilder { impl FuncDefBuilder { pub fn new() -> Self { let mut result = Self { - tid_gen: SeqGen::default(), - bid_gen: SeqGen::default(), - vid_gen: SeqGen::default(), - jid_gen: SeqGen::default(), + tid_gen: SeqGen::new(), + bid_gen: SeqGen::new(), + vid_gen: SeqGen::new(), + jid_gen: SeqGen::new(), blocks: BTreeMap::new(), join_points: BTreeMap::new(), callee_spec_vars: BTreeMap::new(), update_mode_vars: BTreeSet::new(), }; - // Generate `ARG_VALUE_ID` + // Generate `ValueId::ARGUMENT` result.vid_gen.next(); result } @@ -799,12 +805,17 @@ pub struct ModDef { func_defs: BTreeMap, } -#[derive(Default)] pub struct ModDefBuilder { type_names: BTreeSet, func_defs: BTreeMap, } +impl Default for ModDefBuilder { + fn default() -> Self { + Self::new() + } +} + impl ModDefBuilder { pub fn new() -> Self { Self { @@ -842,12 +853,17 @@ pub struct Program { entry_points: BTreeMap, } -#[derive(Default)] pub struct ProgramBuilder { mods: BTreeMap, entry_points: BTreeMap, } +impl Default for ProgramBuilder { + fn default() -> Self { + Self::new() + } +} + impl ProgramBuilder { pub fn new() -> Self { Self {