What makes a good engineering PhD topic and is this one?
How does one do a PhD where the goal is to make something?

This is country specific, and needs approval from your PhD advisor.
But the lab I am working in at CEA in France has several PhD candidates working on Frama-C. In the UK see also this.
You could also continue or take advantage of my work on Bismon (funded by CHARIOT &amp; DECODER projects; see this DRAFT report). You may consider (with approval from your PhD advisor) implementing your ideas as a GCC plugin, or as an extension of the Clang static analyzer, or something generating OpenCL.
Of course, the ongoing Brexit is adding issues at end of 2020 (e.g. end of Erasmus, no more European funding to UK research labs)

From a more mathematical perspective could a perfect algorithm/model be devised ?

Probably not a perfect one. Be however aware of Rice's theorem and of the Halting problem.
Read also J.Pitrat's last book on Artificial Beings - the conscious of a conscious machine, which is closely related to your topic. Also become familiar with abstract interpretation and type inference techniques. Consider generating C code.