rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.96k stars 12.68k forks source link

Add intrinsic to force-monomorphize; or some other solution for Index #34528

Open Manishearth opened 8 years ago

Manishearth commented 8 years ago

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 include force_monomorphization(<Vec<T> as Index>::index).

Alternatively, we could specially mark methods (index and deref? all of std::ops? has to be parametric over self 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

eddyb commented 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.

nagisa commented 8 years ago

Somewhat of a prior art: SPECIALISE pragma in haskell.

Aatch commented 8 years ago

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.

Manishearth commented 8 years ago

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.