Prevent mutation of double-cached cells #429
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @joamatab,
This patch fixes some difficult-to-find errors having to do with mutability (you'll see it even fixes one of the existing tests, for the
grating_coupler_tree
!). Essentially, before adding a component to the CACHE, we first check if the component has already been added or not, under a different name. If it has, it copies the component before adding it again to the CACHE. This prevents errors that could arise in a variety of cases, for examplename
supplied@cell
-decorated function, without being first copiedfrom_yaml
cells, which have identical contentFurthermore I remove calls to
unlock()
withincell()
andimport_gds()
, which I think makes everything a bit safer! Overall, I hope this MR takes a bit of a mental load off the developer, not to have to remember these patterns which are potentially dangerous. Instead, a MutabilityError should be thrown reliably in those cases.