aspl-lang / aspl-lang/aspl

compiler: callback invocation wrappers are not generated for callbacks that are never actually instantiated in the C backend

Open
#32 0 comments 0 reactions 0 assignees View on GitHub
bug good first issue
Dominant language
C
Stars
31
Forks
6
PR merge metrics
No merged PRs in 30d

Description

### Bug description

The C backend of the ASPL compiler generates so-called "wrapper functions" for the invocation of callbacks; however, these functions are currently only generated for callbacks that are actually instantiated at least once in the codebase and not for callbacks that are only ever used as types. And while these wrapper functions are not really needed in the sense that they can never be called if the callback is never instantiated anyway, they are actually necessary for the C code output to compile, as the C compiler cannot know that they can never legally be called.

### Reproducing instructions

The above explanation of the bug was very abstract, yet reproducing (and understanding) it is actually quite straight-forward:

```aspl
var callback? cb = null
if(cb != null){
cb?!.()
}
```
```
$ aspl -backend c run .
```

### Expected behaviour

The above code should compile and run without any problems.

### Environment

_No response_

### Additional context

_No response_

### Contributing guidelines

- [x] I agree to follow this project's contributing guidelines

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided ASPL snippet and the `aspl -backend c run .` command. Trace callback invocation wrapper generation in the C backend, focusing on callbacks used only as types; done when this example compiles and runs successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.