On Fri, Aug 07, 2020 at 11:48:40PM -0400, David Mertz wrote:
> On Fri, Aug 7, 2020, 6:03 PM Paul Moore <p.f.mo...@gmail.com> wrote:
> 
> > > x: int[0:]  # any ints greater than or equal to zero would match, others
> > would fail
> > > x: int[:101]  # any ints less than 101 match
> > > x: int[0:101:2]  # even less than 101
> >
> > I suspect the biggest issue with this is that it's likely to be
> > extremely hard (given the dynamic nature of Python) to check such type
> > assertions statically.
> 
> 
> Yes, it's hard in the sense that it would require solving the halting
> problem.

How so?

I don't see how static bounds checking would be fundamentally more 
difficult than static type checking. Static languages often check what 
bounds they can at compile time, and optionally insert bound checking 
runtime code for ambiguous places. See for example this comment:

"""
2.5 Static Analysis

Bounds checking has relied heavily on static analysis to
optimize performance [15]. Checks can be eliminated if
it can be statically determined that a pointer is safe, i.e.
always within bounds, or that a check is redundant due to
a previous check
"""

https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/baggy-USENIX2009.pdf

I believe that JS++ does something similar:

https://www.onux.com/jspp/blog/jspp-0-9-0-efficient-compile-time-analysis-of-out-of-bounds-errors/

and Checked C aims for similar compile-time bounds checking:

https://www.microsoft.com/en-us/research/project/checked-c/


In any case, nobody expects to solve the Halting Problem for arbitrarily 
complex code. It is still useful to be able to detect some failures even 
if you can't detect them all:

https://web.archive.org/web/20080509165811/http://perl.plover.com/yak/typing/notes.html


-- 
Steven
_______________________________________________
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/WDS3JQZ7YNIKB5ZMHGRJY5223D2YRYTR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to