Skip to content

Unchecked vector access #24

@ziman

Description

@ziman

Here's a program reading out of bounds:

$ echo '(module (_ (load.byte "" 1)) (export))' > example.mlf
$ malfunction compile example.mlf -o example

The program compiles fine. Then I run it.

$ ./example
Fatal error: exception Invalid_argument("index out of bounds")

It seems that the read is checked but I would expect to get a segfault or (most likely) nothing printed at all because that's what Malfunction does whenever you make any other mistake. I have not benchmarked how much overhead it incurs but not having unchecked array access feels wrong, especially in such an inherently unsafe environment.

Given that we don't want to add %primitives, I can see two options:

  1. Making Mvecget and Mvecset translate to the unchecked primitives instead. This will make them faster, and give you undefined behaviour if you get it wrong, which is consistent with the behaviour of Malfunction everywhere else.

  2. Creating new unchecked builtins. Then for debugging purposes, a compiler targetting Malfunction could switch to checked builtins to get a bit of runtime checking for free.

I'm happy to implement either. Are there better ways to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions