Modified FrontEnd to parse & highlight function definitions for compilability?
Okay so this is not an answer (it's to big to write a comment for) to your exact question but a dirty workaround. But it works.
We can write a simple wrapper for Compile
which warns us if we get MainEvaluates and Prints them.
Attributes[CompileEx]={HoldAll};
CompileEx[a___]:=Module[{cf,printString,meCases},
cf=Compile[a];
Needs["CompiledFunctionTools`"];
printString=CompiledFunctionTools`CompilePrint[cf];
meCases=StringCases[printString,"MainEvaluate["~~pattern:Repeated[Except["\n"]]~~"]":>pattern];
If[Length[meCases]>0,Print[ToString[Length[meCases]]<>" MainEvaluates detected.\n\n"<>StringJoin[Riffle[meCases,"\n\n"]]]];
cf
]
This does only printing but its easy to let it throw an error or something you would prefer.
A Testrun:
CompileEx[{{i}},If[MatchQ[i,_?OddQ],If[MatchQ[i,_?IntegerQ],Sin[i]^2,0],0]]
2 MainEvaluates detected.
Function[{i}, MatchQ[i, _?OddQ]][ R0]
Function[{i}, MatchQ[i, _?IntegerQ]][ R0]
CompiledFunction[...]
You can save the definition of CompileEx to a package and load it or save it in the kernel/init.m to have it always by you.
I know its not the best solution but hey, better than nothing. But i'm sure, someone here is able to tweek the FrontEnd to do what you want.
One idea is to use the AutoStyleWords
option of cells to color selected words. For example, the following stylesheet colors all words given by Compile`CompilerFunctions
the color RGBColor[.3, .5, .5]
indicating that they are acceptable compiler functions, and other words will remain black, indicating that they are probably not compiler functions:
SetOptions[
EvaluationNotebook[],
StyleDefinitions -> Notebook[
{
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["CompileInput", StyleDefinitions->StyleData["Input"]],
AutoStyleWords->(SymbolName[#]->"CompiledFunction"&/@Compile`CompilerFunctions[])
]
,
Cell[StyleData["CompiledFunction"], FontColor->RGBColor[.3,.5,.5]]
},
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
Then, here's an example of a compiled function using the "CompileInput" style:
You can see that IntegerQ
and MatchQ
have been flagged as noncompilable functions.