Fix dependency cycle detection

This fixes dependency cycle detection in the concurrent compiler and
includes a test case therefor.