ldc-developers/ldc — pull request #484 by AlexeyProkhin (2013-10-05 07:37:02+00:00)
Title: Yet another attempt to reduce mtype diff

The main issue of our current approach is that llvm function types are created in `DtoType` based on `TypeFunction` that does not provide information about what kind of context argument the function uses. It is the reason why we had to add `TypeFunction::funcdecl` and restrict merging of function types. In the pull request I tried to avoid any major frontend modifications.
As you probably know a function type is internally represented by `IrFuncType` which holds all kinds of stuff like return value, arguments, abi transformations. Most importantly it holds context argument. The `IrFuncTy fty` used to be a member only of `TypeFunction` which, as we already established, does not provide information about context. So I added `fty` to `FuncDeclaration` and `TypeDelegate` which do provide the information. After that I just had to be careful to use correct `fty` because there were three places it could be instead of just one:
* `FuncDeclaration::fty`
* `TypeDelegate::fty`
* `TypeFunction::fty` (it is still used for function pointers)

Unfortunately, it solved only half of the problem at hand. It just guaranteed that a function did not end up with some other function's `fty` because of type merging. `TypeFunction::funcdecl` was still needed to implement `DtoType`. The only sane solution I saw was not to use `DtoType` for functions that require context argument at all. I replaced `DtoType(fd->type)` with `DtoTypeFunction(fd)` and made `DtoType` to return function types always without context argument. Seems to work like charm. With any luck it won't cause unsurmountable regressions (or better yet, won't cause any regressions :) )