Make log parameters lazy instead of auto ref.

This enables passing arguments doing complex computations for debug messages without worrying about impacting execution speed when debug logging is disabled.
Fix an error in the dependency resolution due to a signed/unsigned comparison. See #285.

Also added some diagnostic output to the dependency resolution algorithm.