Skip to content

[dynamo][side-effects] Add mutable_local invariants to Variable Trackers #133027

@anijain2305

Description

@anijain2305

🐛 Describe the bug

In a recent PR - #132912 - we came across a nasty silent incorrectness bug. This prompted me to think about a few invariants that we should maintain

  1. if var.mutable_local is MutableSideEffects - var.source must not be None
  2. if var.mutable_local is MutableLocal - var.source must be None (this was in violation in the above issue, making side effects infra to do funky things)
  3. if var.mutable_local is None - var must be a ConstantVariable (this could be relaxed and needs more thought, TupleVariable with constants etc) - This will ensure that we track mutable_local correctly in all cases.

We should probably change the attr name mutable_local to something else. The local in the name suggest to me that the tracked object is created inside the frame (as opposed to existing). Some suggestions for rename are

var.mutable_local to var.mutation_type (Not fully convinced that this good name, suggestions welcome)
MutableLocal to MutableNew (even local is confusing - is it from f_locals? Or is it created inside the frame?)
MutableSideEffects to MutableExisting (opposite of MutableNew)

cc @ezyang @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames @jansel if this makes sense.

Error logs

No response

Minified repro

No response

Versions

NA

Metadata

Metadata

Assignees

Labels

enhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: dynamooncall: pt2triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions