nac3artiq: update InnerResolver's "pyid_to_type" table if class contain constructor function #309

Merged
sb10q merged 7 commits from issue-139-2 into master 2022-07-28 19:18:36 +08:00
Contributor

The code below failed because the InnerResolver's 'pyid_to_type' table didn't store the type information for the classes that don't have their own constructor.

@nac3
class A
    @kernel
    def __init__(self):
        pass


@nac3
class B(A):
    pass


@nac3
class C(B):
    pass


@nac3
class Demo:
    core: KernelInvariant[Core]

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

    @kernel
    def run(self):
    	c = C()

>>>
nac3artiq.CompileError: compilation failed
----------
type error at identifier `C` (<class 'type'> is not registered with NAC3 (@nac3 decorator missing?))

In the register step, TopLevelComposer::reigster_top_level won't return the constructor's type of the class that doesn't have a constructor and therefore the 'pyid_to_type' will not be abled to store the type information for the class (the ty is None here).

Although class without its own constructor function will inherit an init function from its base class in the analyze_top_level_class_fields_methods step, the 'pyid_to_type' table never got updated.

This change update the 'pyid_to_type' table in the InnerResolver's get_obj_type function when an init method exists in the methods list of a class definition.

The code below failed because the InnerResolver's 'pyid_to_type' table didn't store the type information for the classes that don't have their own constructor. ``` @nac3 class A @kernel def __init__(self): pass @nac3 class B(A): pass @nac3 class C(B): pass @nac3 class Demo: core: KernelInvariant[Core] def __init__(self): self.core = Core() @kernel def run(self): c = C() >>> nac3artiq.CompileError: compilation failed ---------- type error at identifier `C` (<class 'type'> is not registered with NAC3 (@nac3 decorator missing?)) ``` In the register step, TopLevelComposer::reigster_top_level won't return the constructor's type of the class that doesn't have a constructor and therefore the 'pyid_to_type' will not be abled to store the type information for the class (the ty is None [here](https://git.m-labs.hk/M-Labs/nac3/src/branch/master/nac3artiq/src/lib.rs#L416-L418)). Although class without its own constructor function will inherit an __init__ function from its base class in the analyze_top_level_class_fields_methods step, the 'pyid_to_type' table never got updated. This change update the 'pyid_to_type' table in the InnerResolver's get_obj_type function when an __init__ method exists in the methods list of a class definition.
z78078 added 3 commits 2022-07-22 12:44:59 +08:00
z78078 added 2 commits 2022-07-22 12:47:55 +08:00
z78078 added 2 commits 2022-07-22 12:50:15 +08:00
sb10q merged commit b514f91441 into master 2022-07-28 19:18:36 +08:00
sb10q deleted branch issue-139-2 2022-07-28 19:18:36 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
1 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#309
No description provided.