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

Add remove_generalized_iteration rule #217

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

jiwonz
Copy link
Contributor

@jiwonz jiwonz commented Sep 27, 2024

Closes #203

Examples

Input

for i,v in {1,2,3} do
	print(i,v)
end

Output

do local _DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_invardf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_controldf0c36eb99574eba={1,2,3} if type(_DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba)=='table'then local _m=getmetatable(_DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba)if type(_m)=='table'and type(_m.__iter)=='function'then _DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_invardf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_controldf0c36eb99574eba=_m.__iter()else _DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_invardf0c36eb99574eba, _DARKLUA_REMOVE_GENERALIZED_ITERATION_controldf0c36eb99574eba=pairs(_DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba)end end for i,v in _DARKLUA_REMOVE_GENERALIZED_ITERATION_iterdf0c36eb99574eba,_DARKLUA_REMOVE_GENERALIZED_ITERATION_invardf0c36eb99574eba,_DARKLUA_REMOVE_GENERALIZED_ITERATION_controldf0c36eb99574eba do
	print(i,v)
end
end

Notes

  • Hash function blake3 was used
  • Adds RuntimeIdentifier public struct which is for injecting variables in runtime
  • Adds GenericFor.mutate_expressions()

Limitations (Notes from #203)

  1. Using pairs(input) does not necessarily conform to the order of Luau generic iteration (for example, consecutive array indices starting from 1 go first)
  2. Doesn't handle iterating over userdata (with __iter defined), which is supported by Luau
  3. There may also be issues with accessing __iter if __metatable is set

Credits

TO-DOs

  • Add tests (btw, the output was tested in lua5.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A rule for removing (converting) generalized iteration
1 participant