Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler stack-overflows on a combination of recursive const definitions #6540

Open
ironcev opened this issue Sep 12, 2024 · 0 comments
Open
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Sep 12, 2024

The below example will result in the following stack-overflow:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted

Note that the example contains two recursive const definitions, MOD_FN and S_ASSOC/MOD_CONST:

library;

pub const MOD_FN: u8 = mod_fn();

fn mod_fn() -> u8 {
    MOD_FN
}

struct S {}

impl S {
    const S_ASSOC: u8 = MOD_CONST;
}

const MOD_CONST: u8 = S::S_ASSOC;

The overflow happens only if both definitions are present. E.g., if we have only:

library;

pub const MOD_FN: u8 = mod_fn();

fn mod_fn() -> u8 {
    MOD_FN
}

the compiler will emit errors.

Errors will be emitted also in this case:

library;

struct S {}

impl S {
    const S_ASSOC: u8 = MOD_CONST;
}

const MOD_CONST: u8 = S::S_ASSOC;

The overflow happens only when both recursive definitions are present.

When fixing this issue, enable and adjust the recursive_const_stack_overflow test which is linked to this issue via GitHub link in the test TODO.

@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Sep 12, 2024
ironcev added a commit that referenced this issue Sep 14, 2024
…ges (#6545)

## Description

This PR adds additional tests for constants. Those test cases are
important for the implementation of #6351 which will completely
restructure compilation of constants.

Tests for recursive `const` definitions should also be considered before
we start implementing `const fn` and `const trait`. In particular, we
want to better track and provide precise error messages in case of
unintended attempt to recursively define a constant in a complex
situation that includes `const fn` and `const trait`.

Related to #6534, #6537, #6538, #6539, #6540, #6543, and #6544.

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

1 participant