On Sat, Sep 12, 2020 at 08:16:36PM -0400, Cade Brown wrote:
> As per tagged nans, check for JavaScript tagged NaN optimization.
> Essentially, the tag of the NaN (i.e. the mantissa) is interpreted as a
> pointer. Obviously, this is a very advanced use case, probably not worth
> Python guaranteeing such behavior.
> Here is one article:
> https://brionv.com/log/2018/05/17/javascript-engine-internals-nan-boxing/

You are talking about an *internal implementation detail* in the C code 
of the Javascript engine, not a Javascript language feature. There is no 
Javascript API for the JS programmer to perform NAN boxing or to encode 
pointers inside the 51 payload bits of NANs.

Aside from the extra complexity, which may or may not pay off in speed 
improvements, the downside of NAN boxing is the serious security hole 
that if you can introduce an arbitrary NAN value into a JS primitive 
value, you get a pointer to arbitrary memory and can use that to get 
up to all sorts of shenanigans.

To avoid that security hole, JS has to normalise all incoming NANs to a 
single canonical NAN (thus, losing any possibility of user code making 
use of NAN payloads).

In CPython's case, the interpreter uses pointers as object references, 
not the payload bits of a NAN. Jython and IronPython use whatever the 
JVM and .Net CLR use, which probably isn't NANs either.

So while NAN boxing is a clever use of NAN payloads, it's not really 
relevant here. Python code doesn't have a notion of pointers to 
arbitrary addresses, but if it did, user code probably wouldn't have to 
manipulate the payload bits of a NAN float object to get one.



-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/54RN6HEE2LKANJ2Z7INQKLSULOL4J6WJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to