Skip to content

[Feature] Enable import of pure functions in circular dependency import #360

@Ph0enixKM

Description

@Ph0enixKM

Is your feature request related to a problem? Please describe.
This problem enables the import of pure functions even if there is an import dependency cycle. This issue implements a logic that works under the hood and has no impact on syntax.

  • If all imported functions are pure, then import is pure. This means that we can import pure functions from file that normally would create a dependency cycle.
  • Pure import is separated from regular import in import_cache.
  • Pure functions are placed before all the generated bash code.
  • Pure functions are the ones that don't depend on external variables nor functions.

Describe the solution you'd like

  • Write a way to detect if function is pure and persist that to the cache
  • If function is defined, we have to compile it so that we know if it's pure. As for generic functions we can assume default type to be Text
  • Create a way to mark file that was imported purely in the import_cache.
  • Compile the pure functions first before resolving the usual import topology

Describe alternatives you've considered
N/A

Additional context
Let's say that we have file main.ab

import { bar } from "other.ab"

fun aux() {
	echo bar()
}

fun foo() {
	echo "foo"
}

and file other.ab.

import { foo } from "main.ab"

fun bar() {
	echo foo() + "bar"
}

Even though there is an import cycle, the functions could be imported perfectly fine since foo is a pure function that does not rely on the context of the file it was created in.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions