[enhancement] DSLX should not care about function definition order as long as visible in some scope at invocation
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
### What's hard to do? (limit 100 words)
Unlike Rust (or even Python), DSLX requires functions to be defined above first use.
Borrowing from https://doc.rust-lang.org/book/ch03-03-how-functions-work.html, this does not work:
```
fn main() -> () {
trace_fmt!("Hello, world!");
another_function();
}
fn another_function() { trace_fmt!("Another function."); }
```
```
0001: fn main() -> () {
0002: trace_fmt!("Hello, world!");
0003: another_function();
~~~~~~~~~~^--------------^ ParseError: Cannot find a definition for name: "another_function"
```
This should work as long as `another_function` is defined in some scope visible to the body of `main`.
### Current best alternative workaround (limit 100 words)
You must define the functions in order:
```
fn another_function() { trace_fmt!("Another function."); }
fn main() -> () {
trace_fmt!("Hello, world!");
another_function();
}
```
### Your view of the "best case XLS enhancement" (limit 100 words)
Seems we need a first pass to collect the functions defined in scope.
Contributor guide
Assessment
This issue has not been assessed yet.