Skip to content

Allows the caller to pass in argv to hl.main()#8937

Merged
alexreinking merged 12 commits intomainfrom
jiawen-hl_main
Feb 14, 2026
Merged

Allows the caller to pass in argv to hl.main()#8937
alexreinking merged 12 commits intomainfrom
jiawen-hl_main

Conversation

@jiawen
Copy link
Contributor

@jiawen jiawen commented Feb 7, 2026

No description provided.

@jiawen jiawen requested a review from abadams February 7, 2026 01:03
@jiawen jiawen assigned alexreinking and unassigned alexreinking Feb 7, 2026
@jiawen jiawen requested a review from alexreinking February 7, 2026 01:03
@jiawen
Copy link
Contributor Author

jiawen commented Feb 7, 2026

Any suggestions on how / where to put tests? A simple test would be to use something like SimplyPyGenerator and call it a few times with different values of -f. But then we'd need to verify what was written to disk.

@jiawen
Copy link
Contributor Author

jiawen commented Feb 10, 2026

Hold off on merging - it occurs to me that one can implement hl.main() entirely in Python - there's even a place for it. Then the pybind11 code won't be nearly as messy, using embed().

@mcourteaux mcourteaux marked this pull request as draft February 11, 2026 15:19
@jiawen jiawen marked this pull request as ready for review February 12, 2026 20:42
@jiawen
Copy link
Contributor Author

jiawen commented Feb 12, 2026

@alexreinking PTAL. Much cleaner I think.

@jiawen jiawen requested a review from alexreinking February 12, 2026 20:42
Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with one nitpick

Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argv arrays are meant to be NULL-pointer terminated. I don't think we rely on this today, but a very reasonable refactor to generate_filter_main might rely on it later.

mutable_argv.push_back(const_cast<char *>(s.c_str()));
}
int result = Halide::Internal::generate_filter_main((int)argv.size(), argv.data(), PyGeneratorFactoryProvider());
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size(), mutable_argv.data(), PyGeneratorFactoryProvider());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size(), mutable_argv.data(), PyGeneratorFactoryProvider());
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size() - 1, mutable_argv.data(), PyGeneratorFactoryProvider());

@jiawen jiawen requested a review from alexreinking February 13, 2026 18:27
Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed up the formatting in _generator_filter_main and tweaked names to make it clear that a Python list of arguments is getting translated into a compliant argv array.

@alexreinking alexreinking merged commit b8c7457 into main Feb 14, 2026
17 checks passed
@alexreinking alexreinking deleted the jiawen-hl_main branch February 14, 2026 23:40
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.

2 participants