Skip to content

Simplify type conversion model #429

@braxtonmckee

Description

@braxtonmckee

Right now we have a complicated hierarchy of conversion types, ranging from Signature to Upcast to ImplicitContainers to New. Its more complicated than we really need and supports a use case we don't care about, at the cost of complexity and poor performance, both in the compiler and in the interpreter. Matching a function signature should be one shot and clear, not a multiple-pass process.

To do this, we should end up with three conversion levels: Signature, Implicit, and New. Signature means change nothing about the object - it can only do things like unwrap an 'int' that's known as 'object', or pack an int into an object. New means create a new instance however you can - including converting an int -> str, and 'Implicit' means you can cast untyped containers to typed containers.

In this model, f(x: int) won't accept 1.5 or 1.0, and f(x: TupleOf(OneOf(None, int)) won't accept TupleOf(int), but would try to coerce 'tuple'. In practice, we've found that we don't really want to rely on type-conversion to pick which implementation of a function we use, since that tends to be hard to predict. So instead, we want to support minimal conversion, but still allow promotion of untyped data to typed data, since that allows for more idiomatic usages and can often be implemented efficiently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions