An experiment in static, refcounted, procedural language with ownership
1

Configure Feed

Select the types of activity you want to include in your feed.

fix: polymorphic drop hook

r0nsha (Mar 25, 2024, 5:06 PM +0200) bee08f72 5bf0ba5d

+30 -26
+1 -1
compiler_core/src/ty.rs
··· 915 915 // NOTE: It currently makes sense to not instantiate params that are part of 916 916 // the currently typechecked function. 917 917 panic!( 918 - "type param `{:?}` not part of instantation: {:?}", 918 + "type param `{:?}` not part of instantiation: {:?}", 919 919 p, self.instantiation 920 920 ) 921 921 }
+6 -4
compiler_mir/src/lib.rs
··· 111 111 blocks: Blocks, 112 112 values: Values, 113 113 114 - // A mapping for values to their instantation, used for specialization 114 + // A mapping for values to their instantiation, used for specialization 115 115 instantations: FxHashMap<ValueId, Instantiation>, 116 116 117 117 // A mapping of values to their drop flags ··· 228 228 self.create_value(ty, ValueKind::Register(None)) 229 229 } 230 230 231 - pub fn instantation(&self, value: ValueId) -> Option<&Instantiation> { 231 + pub fn instantiation(&self, value: ValueId) -> Option<&Instantiation> { 232 232 self.instantations.get(&value) 233 233 } 234 234 ··· 241 241 &mut self.instantations 242 242 } 243 243 244 - pub fn create_instantation(&mut self, value: ValueId, instantation: Instantiation) { 245 - self.instantations.insert(value, instantation); 244 + pub fn create_instantiation(&mut self, value: ValueId, instantiation: Instantiation) { 245 + if !instantiation.is_empty() { 246 + self.instantations.insert(value, instantiation); 247 + } 246 248 } 247 249 248 250 pub fn ins(&mut self, block: BlockId) -> InstBuilder {
+2 -8
compiler_mir/src/lower.rs
··· 707 707 hir::ExprKind::Variant(variant) => { 708 708 let id = self.cx.get_or_create_variant_ctor(variant.id); 709 709 let value = self.create_value(self.cx.mir.fn_sigs[id].ty, ValueKind::Fn(id)); 710 - 711 - if !variant.instantiation.is_empty() { 712 - self.body.create_instantation(value, variant.instantiation.clone()); 713 - } 714 - 710 + self.body.create_instantiation(value, variant.instantiation.clone()); 715 711 value 716 712 } 717 713 hir::ExprKind::SliceLit(lit) => { ··· 1327 1323 DefKind::TyAlias | DefKind::BuiltinTy(_) => unreachable!("{:?}", &self.cx.db[id]), 1328 1324 }; 1329 1325 1330 - if !instantiation.is_empty() { 1331 - self.body.create_instantation(value, instantiation.clone()); 1332 - } 1326 + self.body.create_instantiation(value, instantiation.clone()); 1333 1327 1334 1328 value 1335 1329 }
+1 -1
compiler_mir/src/monomorphize.rs
··· 173 173 let mut body_subst = BodySubst::new(); 174 174 175 175 for value in body.values() { 176 - if let Some(instantiation) = body.instantation(value.id) { 176 + if let Some(instantiation) = body.instantiation(value.id) { 177 177 // This is a polymorphic value which requires specialization 178 178 if let Some(new_kind) = self.monomorphize_value(mir, &value.kind, instantiation) { 179 179 body_subst.insert_value(value.id, new_kind);
+6 -3
compiler_mir/src/ownck.rs
··· 458 458 let sig_id = self.cx.def_to_fn_sig[&hook_id]; 459 459 let sig_ty = self.cx.mir.fn_sigs[sig_id].ty; 460 460 let tparams = sig_ty.collect_params(); 461 - let instantiation = Instantiation::from((tparams.as_slice(), targs.as_slice())); 461 + let instantiation = if tparams.is_empty() { 462 + Instantiation::default() 463 + } else { 464 + Instantiation::from((tparams.as_slice(), targs.as_slice())) 465 + }; 462 466 463 467 let callee = self.create_untracked_value(instantiation.fold(sig_ty), ValueKind::Fn(sig_id)); 468 + self.body.create_instantiation(callee, instantiation); 464 469 465 470 let arg = { 466 471 let arg = value; ··· 476 481 args: vec![arg], 477 482 span, 478 483 }); 479 - 480 - self.body.create_instantation(value, instantiation); 481 484 } 482 485 483 486 fn set_drop_flag(&mut self, value: ValueId, span: Span) {
+14
tests/drop-hook.jin
··· 1 + fn main() unit = { 2 + let wow = Wow("bye bye!") 3 + println("hello") 4 + let gen = Gen(1) 5 + } 6 + 7 + type Wow(msg: &str) 8 + type Gen[T](value: T) 9 + 10 + fn `=drop`(w: &mut Wow) unit = 11 + println("dropping wow: {w.msg}") 12 + 13 + fn `=drop`[T](g: &mut Gen[T]) unit = 14 + println("dropping gen")
-9
tests/hooks.jin
··· 1 - fn main() unit = { 2 - let mut wow = Wow("bye bye!") 3 - println("hello") 4 - } 5 - 6 - type Wow*(msg: &str) 7 - 8 - fn `=drop`(w: &mut Wow) unit = 9 - println(w.msg)