Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks
Ph0enixKM opened this issue Jul 26, 2024 · 0 comments
Open
4 tasks
Assignees
Labels
compiler enhancement New feature or request

Comments

@Ph0enixKM
Copy link
Member

Ph0enixKM commented Jul 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant