Skip to content

calyx-py: Remove mutable global state for position tracking #2541

@sampsyo

Description

@sampsyo

The calyx-py AST library tracks (Python) source positions using mutable global state. There are global configuration variables that control the tracking:

"""
The base path that fileinfos will be relative with respect to. If None, absolute paths will be used.
"""
FILEINFO_BASE_PATH = None
"""
Determines if sourceinfo and @pos attributes should be emitted or not.
"""
EMIT_SOURCELOC = True

And a couple of global tables that store the actual data in class variables, like this:

FileTable.table[filename] = FileTable.counter
FileTable.counter += 1

Both of these can cause classic global-mutable-state problems with testability and so on. It would be better to associate all of these with the root Program class instead. This way, it would be possible to construct two different Programs from the same Python code and not have them clobber each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: calyx-pyItems that have to do with the builder libraryPriority: LowDon't do these during a deadlineS: AvailableCan be worked upongood first issueGood issue to start contributing on Calyx

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions