Update inplace variables to not lose connection when source node is optimized.
Created by: jmitrevs
In the original implementation, inplace variables are created when initializing an object, which can run into problems if the source node is changed due to optimizers. This PR moves the linking to a later stage, after the optimizations have run.
This is a replacement for #472, making use of the new features in the master branch.