Remove cached pyid_to_type when encountering error (#205) #207

Merged
sb10q merged 1 commits from host_var_err_msg into master 2022-03-04 16:23:25 +08:00
Collaborator

After caching the type of a host object for handling recursive types, if we encounter errors like incompatible types, the cache should be removed for the report_modinit to work properly.
Keeping the wrong cache there might also cause the type check for other function to miss some errors related to that host object

After caching the type of a host object for handling recursive types, if we encounter errors like incompatible types, the cache should be removed for the `report_modinit` to work properly. Keeping the wrong cache there might also cause the type check for other function to miss some errors related to that host object
ychenfo force-pushed host_var_err_msg from a8c52c4a94 to c99173f9a8 2022-03-02 22:15:13 +08:00 Compare
Author
Collaborator

force-pushed to format the modified part of the code in this PR.

force-pushed to format the modified part of the code in this PR.
Owner

Keeping the wrong cache there might also cause the type check for other function to miss some errors related to that host object

How did you find this problem? Do you have example code that demonstrates it?

> Keeping the wrong cache there might also cause the type check for other function to miss some errors related to that host object How did you find this problem? Do you have example code that demonstrates it?
Author
Collaborator

How did you find this problem? Do you have example code that demonstrates it?

Just by looking at the code. Yes, the code is as below.

This is only a really minor point though, because we still will not let any ill-typed program to pass since as long as there is one type error, we do not go to the codegen phase.

from min_artiq import *
from numpy import int32

@nac3
class A:
    a_a: Kernel[int32]
    def __init__(self, aa):
        self.a_a = aa

ga = A(1.2)

@kernel
def accept_A(a: A):
    pass

@nac3
class Demo:
    core: KernelInvariant[Core]

    def __init__(self):
        self.core = Core()

    @kernel
    def run(self):
        accept_A(ga)
    
    @kernel
    def fun(self):
        accept_A(ga)

if __name__ == "__main__":
    Demo().run()

output at 59ac5aae8a:

nac3artiq.CompileError: compilation failed
----------
type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 33 column 13

output after this PR:

----------
type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 33 column 13
----------
type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 40 column 18

errors in both functions using the value ga are shown.

> How did you find this problem? Do you have example code that demonstrates it? Just by looking at the code. Yes, the code is as below. This is only a really minor point though, because we still will not let any ill-typed program to pass since as long as there is one type error, we do not go to the codegen phase. ```python from min_artiq import * from numpy import int32 @nac3 class A: a_a: Kernel[int32] def __init__(self, aa): self.a_a = aa ga = A(1.2) @kernel def accept_A(a: A): pass @nac3 class Demo: core: KernelInvariant[Core] def __init__(self): self.core = Core() @kernel def run(self): accept_A(ga) @kernel def fun(self): accept_A(ga) if __name__ == "__main__": Demo().run() ``` output at https://git.m-labs.hk/M-Labs/nac3/commit/59ac5aae8acc957895a8a170c21d7fcae0a0c2c3: ``` nac3artiq.CompileError: compilation failed ---------- type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 33 column 13 ``` output after this PR: ``` ---------- type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 33 column 13 ---------- type error at identifier `ga` (error when getting type of field `a_a` (Incompatible types: float and int32)) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/./demo.py: line 40 column 18 ``` errors in both functions using the value `ga` are shown.
sb10q merged commit 84b4bd920b into master 2022-03-04 16:23:25 +08:00
sb10q deleted branch host_var_err_msg 2022-03-04 16:23:25 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#207
No description provided.