Skip to content

✨ feat(mq-macros): add proc-macro crate and refactor builtin definitions#1682

Merged
harehare merged 1 commit intomainfrom
feat/mq-macros
May 4, 2026
Merged

✨ feat(mq-macros): add proc-macro crate and refactor builtin definitions#1682
harehare merged 1 commit intomainfrom
feat/mq-macros

Conversation

@harehare
Copy link
Copy Markdown
Owner

@harehare harehare commented May 3, 2026

Introduce mq-macros crate with #[mq_fn] attribute macro to replace the local define_builtin! macro in mq-lang, making builtin function definitions more idiomatic and type-explicit.

Introduce `mq-macros` crate with `#[mq_fn]` attribute macro to replace
the local `define_builtin!` macro in `mq-lang`, making builtin function
definitions more idiomatic and type-explicit.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 3, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/mq-macros (422841a) with main (4ba20af)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a04e38f) during the generation of this report, so 4ba20af was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new internal procedural macro crate, mq-macros, and uses it to replace the local builtin-definition macro in mq-lang. In the broader codebase, this refactors how builtin functions are declared and dispatched without changing the builtin surface area itself.

Changes:

  • Added a new mq-macros proc-macro crate with #[mq_fn] and builtin_dispatch! for builtin registration/lookup code generation.
  • Rewrote mq-lang builtin definitions from inline macro invocations to named Rust functions annotated with #[mq_fn].
  • Wired the new crate into the workspace and mq-lang dependency graph.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/mq-macros/src/lib.rs Adds the new proc-macro implementations for builtin statics and dispatch generation.
crates/mq-macros/Cargo.toml Declares the new proc-macro crate and its parsing/codegen dependencies.
crates/mq-lang/src/eval/builtin.rs Migrates builtin declarations to annotated functions and replaces manual hash dispatch with macro-generated dispatch.
crates/mq-lang/Cargo.toml Adds the new internal macro crate as a dependency.
Cargo.toml Registers mq-macros as a workspace member and workspace dependency.
Cargo.lock Locks the new crate and dependency graph changes.

Comment on lines +1 to +3
use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::quote;
Comment on lines +151 to +152
#[proc_macro]
pub fn builtin_dispatch(input: TokenStream) -> TokenStream {
@harehare
Copy link
Copy Markdown
Owner Author

harehare commented May 3, 2026

@copilot
Please port the fnv1a_hash_64 implementation from mq-lang to mq-macros.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

@copilot
Please port the fnv1a_hash_64 implementation from mq-lang to mq-macros.

Done in d543419. The fnv1a_hash_64 implementation is now in mq-macros/src/lib.rs as a private const fn. It serves two roles:

  1. Compile time – called inside builtin_dispatch! during macro expansion to pre-compute each HASH_* constant as a plain u64 literal (no longer a const fn call in the generated code).
  2. Runtime – the macro also emits the fnv1a_hash_64 function definition into the call site so get_builtin_functions_by_str can hash the incoming lookup string.

The duplicate definition in mq-lang/src/eval/builtin.rs has been removed.

@harehare harehare merged commit 5f38fa4 into main May 4, 2026
19 checks passed
@harehare harehare deleted the feat/mq-macros branch May 4, 2026 02:21
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.

3 participants