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

Using basic_new_heap for assigning elements of symbolic list #2465

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

anutosh491
Copy link
Collaborator

This PR adds an example to address the first TODO as pointed out here (#2450 (comment))

We are trying to replicate this code snippet essentially

from lpython import S
from sympy import Symbol, pi

def mmrv(r: Out[list[S]]) -> None:
    x: S = pi
    l1: list[S]
    l1 = [x]
    print(l1[0])
    r = l1

def test_mrv2():
    ans: list[S]
    temp: list[S]
    mmrv(ans)
    temp = ans
    print(temp[0])

test_mrv2()

@anutosh491
Copy link
Collaborator Author

Also talking about the note which added to the mentioned comment
Note: in LPython, list assignment r = l1 is always a deep copy (unlike in CPython where it is just a refcount increase), so we should initialize r first using basic_new_heap and then use basic_assign to assign the elements. That can be done later.

I see that this is correct and works without flaws, hence for now the line r = l1 can be replicated using r = l1 itself but in future we might prefer the approach pointed above.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this looks good.

@certik
Copy link
Contributor

certik commented Jan 31, 2024

Is this ready to be merged?

@anutosh491
Copy link
Collaborator Author

Is this ready to be merged?

I think it is ready !

@certik certik merged commit 467081e into lcompilers:main Jan 31, 2024
12 of 13 checks passed
@certik
Copy link
Contributor

certik commented Jan 31, 2024

The CI failure is due to #2455.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants