Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Alias analysis for purity detection #297

@lukarade

Description

@lukarade

Is your feature request related to a problem?

Right now, the following cases cannot be handled by the purity analysis.
Calling dtype, is_list_like, _recurse or fspath will result in an UnknownCall being added as a reason for impurity.

# Case 1
import np
dtype = np.dtype(dtype) 

import lib
is_list_like = lib.is_list_like 

# Case 2
def _replace_dtype_fields_recursive(dtype, primitive_dtype):
    "Private function allowing recursion in _replace_dtype_fields."
    _recurse = _replace_dtype_fields_recursive
    ...

# Case 3
# inside os module
if not _exists('fspath'):
    fspath = _fspath
    fspath.__name__ = "fspath"

def _fspath(path):
    """Return the path representation of a path-like object."""
    ...

In case 1 the called symbol is an alias for an imported function.
In case 2 the called symbol is a "private" alias inside the function to enable recursion.
In case 3 the function is renamed and then called via its alias.

Desired solution

To increase the precision of the purity analysis, these cases should be considerate in more depth.
This could be done by implementing an alias analysis into the purity analysis, which can identify pairs of variables and fields which are referencing the same object and therefore can be treated as aliases.

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

These examples were collected by manually analyzing the reasons for the function safeds.data.tabular.containers._table.from_csv_file.
Manual_reasons_analysis_for-safeds.data.tabular.containers._table.from_csv_file.xlsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement 💡New feature or requestpurityInferring the purity of functions

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions