Open Manishearth opened 8 years ago
The monomorphization can be triggered easily (e.g. cast to a function pointer). The tricky bit here is marking the monomorphized function so that it gets exported.
Somewhat of a prior art: SPECIALISE pragma in haskell.
I don't think an intrinsic is appropriate here. An attribute or some other way to "eagerly" monomorphize makes more sense. As @eddyb says, the problem isn't the monomorphisation, it's ensuring the monomorphised function isn't removed as dead-code.
Yeah, so the issue is instructing the compiler which monomorphizations should not be removed as dead code. An attribute on a method or trait method works, but what are the heuristics on it being included? The intrinsic lets us define these heuristic per-type, e.g. "only export this function if this other function monomorphization gets called". But I prefer the attribute solution myself -- just concerned about the binary size.
For gdb to be able to index things like hashmaps, we need to ensure that the index implementation is monomorphized correctly.
I would like to have an intrinsic, which when found in a monomorphized function, will force monomorphization of the provided argument. For example, in
Vec::new()
, we can includeforce_monomorphization(<Vec<T> as Index>::index)
.Alternatively, we could specially mark methods (index and deref? all of
std::ops
? has to be parametric overself
but not parametric over other non-Self
args.) that are always monomorphized if the corresponding concrete self type already exists. Perhaps only in debug mode. This may bloat binary size, but eh, debug mode.cc @rust-lang/compiler @tromey