facebookincubator / cinder

Cinder is Meta's internal performance-oriented production version of CPython.

Home Page:https://trycinder.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unsound list to Array conversion

bennn opened this issue · comments

What version of SP are you using

43d1ce7 2021-10-21

What program did you run?

  # typed.py
  from __static__ import Array, int32
  def h(x:Array[int32])->int32:
    print(x)
    return x[0]
  from typed import h
  x = ["B"]
  print(h(x))
  # ['B'] # from typed code!
  # B

What happened?

No error

What should have happened?

A runtime error --- either because ["B"] is not an array or because "B" is not an int32.

On the bright side, I haven't been able to use the wrong types to get a serious error. Adding (+) and comparing (<) x[0] with another int32 gives an error about mixing strings and numbers.

In general, we were wondering what's the SP strategy for Arrays and Vectors at the boundaries to untyped code. Is there a conversion story like for int32, should these boundaries always error, or something else?

Right now, typed code can send an Array to Python, so I'd expect the function h to look for an Array object and reject everything else.

This is definitely a bug, h should be checking it's arg type. I'll check why it isn't doing so!

Oh, this was already fixed back in December in the above-linked commit, we just hadn't closed the issue :) It looks like it wasn't actually anything specific to arrays, just a problem with how we reported (or failed to report) arg typecheck errors in the jit.

In general, we were wondering what's the SP strategy for Arrays and Vectors at the boundaries to untyped code. Is there a conversion story like for int32, should these boundaries always error, or something else?

Our Array/Vector types are actually at runtime thin subclasses of the existing Python array.array type, which contains compact arrays of primitive values: https://docs.python.org/3/library/array.html. So the type is usable in either static or non-static code; in the former case you get nice compiler integration with SP primitive integer types, in the latter case you interact with it using the normal array API and boxed values.