I have added a monomorphisation pass to the optimisation process. This pass is currently done before inlining, and makes monomorphic clones of Felix functions, procedures, classes, and variables. Types other than classes, and primitives are not monomorphised.
The main reason for doing all this is so that polymorphic calls to virtual functions of typeclasses become monomorphic which allows them to be instantiated, and subsequently inlined, so that there is zero performance penalty for using virtual functions. Strangely this didn't fix the dispatch to 'ge' in Takfp .. well not so strangely, since this was monomorphic anyhow. The reason is probably that the dispatch is an "apply_prim" which isn't considered for inlining. The actual intent is to do a round of polymorphic inlining first, THEN monomorphise, then do another round of inlining. The first round is mainly to reduce the total number of functions that the monomorphisation has to handle, the second round inlines virtual functions that couldn't be instantiated in the first round. This job took over a weak and uncovered numerous difficulties in the representation. By the far the most difficult issue in general is that the algebraic data types used by the compiler have invariants, and ones which change depending on the processing phase .. and these currently have to be 'remembered'. For example I changed the instantiator so that the instance number of a symbol of index i, where the symbol was already monomorphic, was actually i, rather than spawning a fresh instance number. What I didn't realise was that the instantiator was carefully crafted to proceed from the roots, and the type registry also carefully crafted to register types bottom up: together these factors ensure the numeric ordering of instances is a topological sort of dependency order (except for polymorphic insertions, which don't work for this reason .. :) By fiddling the instance numbers I broke the invariant, and the code generator emitted struct definitions referring to structs that hadn't been declared yet .. breaking the C++ parser. I had to add an extra pass to the code generator to emit the names of all structs like "struct X;" to fix this. I hope that works (it won't if any of the structs are used as complete types, but that never happens for the structs representing function objects). -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Felix-language mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/felix-language
