Skip to content

Improve how operator typing rules are specified and checked #91

@bpandreotti

Description

@bpandreotti

Currently, the type checking for all operator terms happens inside the Parser::make_op function, in a huge (and ever increasing) match statement. This means that to add a new operator, a maintainer needs to modify this function in the parser, and implement the type checking rules manually, which can be non-trivial, and has lead to bugs before. It would be better if this type checking logic were in a different module, and if there was some simpler way to specify the typing rules for an operator.

The ideal version of this would be if a maintainer could add a new operator without having to even touch rust code, by just editing a configuration file. Carcara could then read this file at compile-time, and enforce the type checking rules specified in it. One way this might look is a .toml file, like this:

[[operator]]
name = "str.replace_re"
return_type = "String"
arg_types = ["String", "RegLan", "String"]

Alternatively, we can use the syntax used by SMT-LIB theory declarations:

(str.replace_re String RegLan String String) 

It might be the case that not all operators can be succintly defined with this configuration language, especially considering the behaviour of some operators changes depending on parser config. In that case, I think it makes sense to have built-in operators, whose typing rules are still defined in rust, as well as the custom operators:

enum Operator {
    Add,
    Sub,
    // ...
    Custom(CustomOperator), // Read from config file
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions