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

Reject infinite size struct definition #682

Closed
Y-Nak opened this issue Mar 2, 2022 · 4 comments
Closed

Reject infinite size struct definition #682

Y-Nak opened this issue Mar 2, 2022 · 4 comments
Labels
flag: beta-required Required for first beta release good first issue Good for newcomers mentor This issue is mentored type: bug

Comments

@Y-Nak
Copy link
Member

Y-Nak commented Mar 2, 2022

What is wrong?

Currently, the below codes are not appropriately rejected and lead to ICE when it is instantiated.

Self recursion

struct Foo:
    foo: Foo

contract MyContract:
    pub fn func(foo: Foo):
       pass

Mutual recursion

struct Foo:
    x: Bar
    
struct Bar:
    x: Foo

contract MyContract:
    pub fn func(foo: Foo):
       pass

How can it be fixed

Reject recursive struct definition in analyzer.
This could be done by checking recursions in analyzer::items::StructId::sink_diagnostics using analyzer::items::StructId::struct_depency_graph.

@Y-Nak Y-Nak added good first issue Good for newcomers type: bug flag: beta-required Required for first beta release mentor This issue is mentored labels Mar 2, 2022
@Narasimha1997
Copy link
Contributor

I can work on this.

@Narasimha1997
Copy link
Contributor

Narasimha1997 commented May 7, 2022

@Y-Nak

salsa create panics when it sees a cycle in the dependency graph.

Here is the error message:

---- struct_recursive_cycles stdout ----
thread 'struct_recursive_cycles' panicked at 'Internal error, cycle detected:

DatabaseKeyIndex { group_index: 0, query_index: 57, key_index: 0 }
DatabaseKeyIndex { group_index: 0, query_index: 57, key_index: 1 }
', /home/narasimha/.cargo/registry/src/github.com-1ecc6299db9ec823/salsa-0.16.1/src/lib.rs:490:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is there any way we can catch this Panic and handle it?

Check out the related issue here

@Y-Nak
Copy link
Member Author

Y-Nak commented May 7, 2022

@Narasimha1997
Hi! Thanks for working on the issue!

One way to catch the cycle would be to use salsa::cycle. We use it here for example.

@Narasimha1997
Copy link
Contributor

@Y-Nak thanks for reverting back.
Also if possible can you suggest me a suitable error message for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: beta-required Required for first beta release good first issue Good for newcomers mentor This issue is mentored type: bug
Projects
None yet
Development

No branches or pull requests

2 participants