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

@ -3809,6 +3809,7 @@ fn make_specializations<'a>(
ident_ids: &mut ident_ids, ident_ids: &mut ident_ids,
ptr_bytes, ptr_bytes,
update_mode_counter: 0, update_mode_counter: 0,
call_specialization_counter: 0,
}; };
// TODO: for now this final specialization pass is sequential, // TODO: for now this final specialization pass is sequential,
@ -3871,6 +3872,7 @@ fn build_pending_specializations<'a>(
ident_ids: &mut ident_ids, ident_ids: &mut ident_ids,
ptr_bytes, ptr_bytes,
update_mode_counter: 0, update_mode_counter: 0,
call_specialization_counter: 0,
}; };
// Add modules' decls to Procs // Add modules' decls to Procs

View file

@ -218,9 +218,10 @@ fn call_spec(
full_layout: _, full_layout: _,
ret_layout: _, ret_layout: _,
arg_layouts: _, arg_layouts: _,
specialization_id,
} => { } => {
// TODO annotate each call with a unique identifier let array = specialization_id.to_bytes();
let spec_var = CalleeSpecVar(&[]); let spec_var = CalleeSpecVar(&array);
let arg_value_id = build_tuple_value(builder, env, block, call.arguments)?; let arg_value_id = build_tuple_value(builder, env, block, call.arguments)?;
let slice = &symbol.to_ne_bytes(); let slice = &symbol.to_ne_bytes();

View file

@ -1408,7 +1408,7 @@ fn compile_test_help<'a>(
let test = Expr::Call(crate::ir::Call { let test = Expr::Call(crate::ir::Call {
call_type: crate::ir::CallType::LowLevel { call_type: crate::ir::CallType::LowLevel {
op, op,
update_mode: env.next_update_mode_id(op), update_mode: env.next_update_mode_id(),
}, },
arguments: arena.alloc([lhs, rhs]), arguments: arena.alloc([lhs, rhs]),
}); });

View file

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

View file

@ -101,6 +101,7 @@ mod test_reporting {
ident_ids: &mut ident_ids, ident_ids: &mut ident_ids,
ptr_bytes: 8, ptr_bytes: 8,
update_mode_counter: 0, update_mode_counter: 0,
call_specialization_counter: 0,
}; };
let _mono_expr = Stmt::new( let _mono_expr = Stmt::new(
&mut mono_env, &mut mono_env,