···915915 // NOTE: It currently makes sense to not instantiate params that are part of
916916 // the currently typechecked function.
917917 panic!(
918918- "type param `{:?}` not part of instantation: {:?}",
918918+ "type param `{:?}` not part of instantiation: {:?}",
919919 p, self.instantiation
920920 )
921921 }
+6-4
compiler_mir/src/lib.rs
···111111 blocks: Blocks,
112112 values: Values,
113113114114- // A mapping for values to their instantation, used for specialization
114114+ // A mapping for values to their instantiation, used for specialization
115115 instantations: FxHashMap<ValueId, Instantiation>,
116116117117 // A mapping of values to their drop flags
···228228 self.create_value(ty, ValueKind::Register(None))
229229 }
230230231231- pub fn instantation(&self, value: ValueId) -> Option<&Instantiation> {
231231+ pub fn instantiation(&self, value: ValueId) -> Option<&Instantiation> {
232232 self.instantations.get(&value)
233233 }
234234···241241 &mut self.instantations
242242 }
243243244244- pub fn create_instantation(&mut self, value: ValueId, instantation: Instantiation) {
245245- self.instantations.insert(value, instantation);
244244+ pub fn create_instantiation(&mut self, value: ValueId, instantiation: Instantiation) {
245245+ if !instantiation.is_empty() {
246246+ self.instantations.insert(value, instantiation);
247247+ }
246248 }
247249248250 pub fn ins(&mut self, block: BlockId) -> InstBuilder {
+2-8
compiler_mir/src/lower.rs
···707707 hir::ExprKind::Variant(variant) => {
708708 let id = self.cx.get_or_create_variant_ctor(variant.id);
709709 let value = self.create_value(self.cx.mir.fn_sigs[id].ty, ValueKind::Fn(id));
710710-711711- if !variant.instantiation.is_empty() {
712712- self.body.create_instantation(value, variant.instantiation.clone());
713713- }
714714-710710+ self.body.create_instantiation(value, variant.instantiation.clone());
715711 value
716712 }
717713 hir::ExprKind::SliceLit(lit) => {
···13271323 DefKind::TyAlias | DefKind::BuiltinTy(_) => unreachable!("{:?}", &self.cx.db[id]),
13281324 };
1329132513301330- if !instantiation.is_empty() {
13311331- self.body.create_instantation(value, instantiation.clone());
13321332- }
13261326+ self.body.create_instantiation(value, instantiation.clone());
1333132713341328 value
13351329 }
+1-1
compiler_mir/src/monomorphize.rs
···173173 let mut body_subst = BodySubst::new();
174174175175 for value in body.values() {
176176- if let Some(instantiation) = body.instantation(value.id) {
176176+ if let Some(instantiation) = body.instantiation(value.id) {
177177 // This is a polymorphic value which requires specialization
178178 if let Some(new_kind) = self.monomorphize_value(mir, &value.kind, instantiation) {
179179 body_subst.insert_value(value.id, new_kind);
+6-3
compiler_mir/src/ownck.rs
···458458 let sig_id = self.cx.def_to_fn_sig[&hook_id];
459459 let sig_ty = self.cx.mir.fn_sigs[sig_id].ty;
460460 let tparams = sig_ty.collect_params();
461461- let instantiation = Instantiation::from((tparams.as_slice(), targs.as_slice()));
461461+ let instantiation = if tparams.is_empty() {
462462+ Instantiation::default()
463463+ } else {
464464+ Instantiation::from((tparams.as_slice(), targs.as_slice()))
465465+ };
462466463467 let callee = self.create_untracked_value(instantiation.fold(sig_ty), ValueKind::Fn(sig_id));
468468+ self.body.create_instantiation(callee, instantiation);
464469465470 let arg = {
466471 let arg = value;
···476481 args: vec![arg],
477482 span,
478483 });
479479-480480- self.body.create_instantation(value, instantiation);
481484 }
482485483486 fn set_drop_flag(&mut self, value: ValueId, span: Span) {
+14
tests/drop-hook.jin
···11+fn main() unit = {
22+ let wow = Wow("bye bye!")
33+ println("hello")
44+ let gen = Gen(1)
55+}
66+77+type Wow(msg: &str)
88+type Gen[T](value: T)
99+1010+fn `=drop`(w: &mut Wow) unit =
1111+ println("dropping wow: {w.msg}")
1212+1313+fn `=drop`[T](g: &mut Gen[T]) unit =
1414+ println("dropping gen")
-9
tests/hooks.jin
···11-fn main() unit = {
22- let mut wow = Wow("bye bye!")
33- println("hello")
44-}
55-66-type Wow*(msg: &str)
77-88-fn `=drop`(w: &mut Wow) unit =
99- println(w.msg)