ir: Correctly build Scopes.