Comments (4)
🤔 I had never really thought about this problem because I don't use Python much and I haven't been involved in the development of the Python target. But in Python, everything is an object, and Python is "pass-by-object-reference." This suggests that anything passed down to another reactor must either be deep copied or considered immutable. The latter of seems unenforceable in Python but the former would be costly.
from lf-python-support.
I don't think "everything" needs to be deep copied, only things that remain in scope at the source reactor, namely state variables (or global variables, but in that case it is obvious what you are doing). Any local variable containing a reference to a state variable will also create problems.
Python does not have any notion of "Const" variables, so I think we are stuck and just have to carefully document this flaw.
from lf-python-support.
Right. How can we check whether a value is accessible through the source reactor's state though? If there is no good answer to that question, then we need to either always copy to be safe, or rely on the programmer to do the right thing.
from lf-python-support.
This suggests that anything passed down to another reactor must either be deep copied or considered immutable. The latter of seems unenforceable in Python but the former would be costly.
Python does not have any notion of "Const" variables, so I think we are stuck and just have to carefully document this flaw.
Integers, floats, and strings in Python are immutable. Tuples and frozensets
of immutable objects are immutable. Immutability can be emulated using arbitrary user-defined classes; furthermore, abstract data types can be implemented using tuples and primitives and be made immutable thereby. It is true that Python does not have "const" variables, but I don't think we need that in order to solve this problem. To my knowledge, we just need Python messages to be immutable, which seems like a practical solution to me because Python programmers are already used to being forced to make certain objects hashable, which is typically more restrictive than immutability.
We could even force messages to be immutable by throwing a runtime error if they are not hashable -- I think this would give wrong answers (both false positive and false negative) sometimes, but it would be very easy and it would at least "kind of" work.
This has already been a known issue for some time though and also applies to some other targets, especially the C target. The solution in the C target would involve parsing the C code as if non-unsafe C code were an integral part of LF. I suspect we will have to do this eventually if the C target is not superseded by the C++ target or Rust target.
from lf-python-support.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lf-python-support.