APrioriInvestments / typed_python

An llvm-based framework for generating and calling into high-performance native code from Python.
Apache License 2.0
197 stars 8 forks source link

type-signature functions don't understand Value correctly #422

Open braxtonmckee opened 1 year ago

braxtonmckee commented 1 year ago

I want this to work correctly, but it doesn't:

    def test_function_signature_with_type_argument(self):
        def castToType(X, T):
            return T.Value

        @Entrypoint
        def castTo(x, T) -> castToType:
            return T(x)

        assert castTo.resultTypeFor(int, Value(str)).typeRepresentation is str

        assert castTo(10, str) == "10"

The problem is that the compiler casts the value 'str' to 'type', instead of using Value(str). Of course, fixing this means that we have to always pass a Value for a type instead of 'type' for any argument which is a type. This is perhaps more specific than what we want in some cases.

To fix this, we may need to add some additional control to the type-signature allowing us to specify what level of detail the compiler (and also interpreter) should assume for a given argument.