add call spec counter

This commit is contained in:
Folkert 2021-05-09 12:28:09 +02:00
parent 8799973ffe
commit 4f376bf4f8
5 changed files with 44 additions and 22 deletions

View file

@ -736,6 +736,7 @@ pub struct Env<'a, 'i> {
pub ident_ids: &'i mut IdentIds,
pub ptr_bytes: u32,
pub update_mode_counter: u64,
pub call_specialization_counter: u64,
}
impl<'a, 'i> Env<'a, 'i> {
@ -747,10 +748,9 @@ impl<'a, 'i> Env<'a, 'i> {
Symbol::new(self.home, ident_id)
}
pub fn next_update_mode_id(&mut self, op: LowLevel) -> UpdateModeId {
pub fn next_update_mode_id(&mut self) -> UpdateModeId {
let id = UpdateModeId {
id: self.update_mode_counter,
op,
};
self.update_mode_counter += 1;
@ -758,6 +758,16 @@ impl<'a, 'i> Env<'a, 'i> {
id
}
pub fn next_call_specialization_id(&mut self) -> CallSpecId {
let id = CallSpecId {
id: self.call_specialization_counter,
};
self.call_specialization_counter += 1;
id
}
pub fn is_imported_symbol(&self, symbol: Symbol) -> bool {
symbol.module_id() != self.home && !symbol.is_builtin()
}
@ -1036,27 +1046,25 @@ impl<'a> Call<'a> {
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CallSpecId {
id: u64,
}
impl CallSpecId {
pub fn to_bytes(self) -> [u8; 8] {
self.id.to_ne_bytes()
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct UpdateModeId {
op: LowLevel,
id: u64,
}
impl UpdateModeId {
const SIZE: usize = std::mem::size_of::<LowLevel>() + std::mem::size_of::<u64>();
pub fn to_bytes(self) -> [u8; UpdateModeId::SIZE] {
debug_assert_eq!(Self::SIZE, 9);
let mut result = [0; Self::SIZE];
result[0] = self.op as u8;
for (i, b) in self.id.to_ne_bytes().iter().enumerate() {
result[i + 1] = *b;
}
result
pub fn to_bytes(self) -> [u8; 8] {
self.id.to_ne_bytes()
}
}
@ -1067,6 +1075,7 @@ pub enum CallType<'a> {
full_layout: Layout<'a>,
ret_layout: Layout<'a>,
arg_layouts: &'a [Layout<'a>],
specialization_id: CallSpecId,
},
ByPointer {
name: Symbol,
@ -4205,7 +4214,7 @@ pub fn with_hole<'a>(
let call = self::Call {
call_type: CallType::LowLevel {
op,
update_mode: env.next_update_mode_id(op),
update_mode: env.next_update_mode_id(),
},
arguments: arg_symbols,
};
@ -4357,7 +4366,7 @@ pub fn from_can<'a>(
let op = LowLevel::ExpectTrue;
let call_type = CallType::LowLevel {
op,
update_mode: env.next_update_mode_id(op),
update_mode: env.next_update_mode_id(),
};
let arguments = env.arena.alloc([cond_symbol]);
let call = self::Call {
@ -5094,11 +5103,13 @@ fn substitute_in_call<'a>(
arg_layouts,
ret_layout,
full_layout,
specialization_id,
} => substitute(subs, *name).map(|new| CallType::ByName {
name: new,
arg_layouts,
ret_layout: *ret_layout,
full_layout: *full_layout,
specialization_id: *specialization_id,
}),
CallType::ByPointer {
name,
@ -5880,6 +5891,7 @@ fn call_by_pointer<'a>(
full_layout: layout,
ret_layout: *ret_layout,
arg_layouts,
specialization_id: env.next_call_specialization_id(),
};
let call = Call {
call_type,
@ -6138,6 +6150,7 @@ fn call_by_name<'a>(
ret_layout: *ret_layout,
full_layout,
arg_layouts,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
};
@ -6182,6 +6195,7 @@ fn call_by_name<'a>(
ret_layout: *ret_layout,
full_layout,
arg_layouts,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
};
@ -6288,6 +6302,7 @@ fn call_by_name<'a>(
ret_layout: *ret_layout,
full_layout,
arg_layouts,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
}
@ -6351,6 +6366,7 @@ fn call_specialized_proc<'a>(
ret_layout: function_layout.result,
full_layout: function_layout.full,
arg_layouts: function_layout.arguments,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
};
@ -6372,6 +6388,7 @@ fn call_specialized_proc<'a>(
ret_layout: function_layout.result,
full_layout: function_layout.full,
arg_layouts: function_layout.arguments,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
};
@ -6391,6 +6408,7 @@ fn call_specialized_proc<'a>(
ret_layout: function_layout.result,
full_layout: function_layout.full,
arg_layouts: function_layout.arguments,
specialization_id: env.next_call_specialization_id(),
},
arguments: field_symbols,
};