From 9268b7aa7c6dee44433c1cbf6780fe9f84158011 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 2 Sep 2016 01:26:19 -0700 Subject: Fix hash copying in _dup. - Spec._dup() incorrectly copied cached hashes and normal/concrete values even when dependency structure was not preserved. - Now these are only copied when *all* dependencies are copied. --- lib/spack/spack/spec.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 99446d21dd..f742ca4616 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1911,8 +1911,9 @@ class Spec(object): self.external = other.external self.external_module = other.external_module self.namespace = other.namespace - self._hash = other._hash - self._cmp_key_cache = other._cmp_key_cache + + self.external = other.external + self.external_module = other.external_module # If we copy dependencies, preserve DAG structure in the new spec if deps: @@ -1940,11 +1941,20 @@ class Spec(object): new_spec._add_dependency( new_nodes[depspec.spec.name], depspec.deptypes) - # Since we preserved structure, we can copy _normal safely. - self._normal = other._normal - self._concrete = other._concrete - self.external = other.external - self.external_module = other.external_module + # These fields are all cached results of expensive operations. + # If we preserved the original structure, we can copy them + # safely. If not, they need to be recomputed. + if deps == True or deps == alldeps: + self._hash = other._hash + self._cmp_key_cache = other._cmp_key_cache + self._normal = other._normal + self._concrete = other._concrete + else: + self._hash = None + self._cmp_key_cache = None + self._normal = False + self._concrete = False + return changed def copy(self, deps=True): -- cgit v1.2.3-60-g2f50