Skip to content

Commit 7508596

Browse files
committed
refactor: adopt RustQ 0.10.0
1 parent 9cfbdc2 commit 7508596

3 files changed

Lines changed: 26 additions & 43 deletions

File tree

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ defmodule OXC.MixProject do
7676
[
7777
{:rustler, "~> 0.36 or ~> 0.37 or ~> 0.38", optional: true},
7878
{:rustler_precompiled, "~> 0.8"},
79-
{:rustq, "~> 0.9.11", only: [:dev, :test], runtime: false},
79+
{:rustq, "~> 0.10.0", only: [:dev, :test], runtime: false},
8080
{:ex_doc, "~> 0.35", only: :dev, runtime: false},
8181
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
8282
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"reach": {:hex, :reach, "2.5.0", "c6b2116d0bab5454597479e7b0b6bc224fb3a262b9e15bb16877b4fdd42c3ada", [:mix], [{:boxart, "~> 0.3.3", [hex: :boxart, repo: "hexpm", optional: true]}, {:ex_ast, "~> 0.12.0", [hex: :ex_ast, repo: "hexpm", optional: false]}, {:ex_dna, "~> 1.5", [hex: :ex_dna, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:libgraph, "~> 0.16.0", [hex: :libgraph, repo: "hexpm", optional: false]}, {:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: true]}, {:makeup_js, "~> 0.1", [hex: :makeup_js, repo: "hexpm", optional: true]}, {:quickbeam, "~> 0.10", [hex: :quickbeam, repo: "hexpm", optional: true]}], "hexpm", "b7fa8a1b5b8a1a55b16a0063ddbcedc63b747423b1cf4c26671919c3f56bbaf3"},
2222
"rustler": {:hex, :rustler, "0.38.0", "7a8906998ff0d28e3021c0a73264abcda719bda344b2e58307c6805b0f87c9b4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "704c03c1bf66be12b031c5a389347b91c81c5cb819a24b068b0de36fe4a5652a"},
2323
"rustler_precompiled": {:hex, :rustler_precompiled, "0.8.4", "700a878312acfac79fb6c572bb8b57f5aae05fe1cf70d34b5974850bbf2c05bf", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "3b33d99b540b15f142ba47944f7a163a25069f6d608783c321029bc1ffb09514"},
24-
"rustq": {:hex, :rustq, "0.9.11", "ffe15ea7e2560068d8d25d4b20639989b5ea055fb59a8e0932f57988998bc7a4", [:mix], [{:json_codec, "~> 0.1", [hex: :json_codec, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:reach, "~> 2.0", [hex: :reach, repo: "hexpm", optional: false]}, {:rustler, "~> 0.37", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "a303c480991b8b4f13f160b300a5219b45d5ae72965de0ed82cd2dea3e078677"},
24+
"rustq": {:hex, :rustq, "0.10.0", "c2fcc6a037a53d554ff7281db47d5b20e815f51ca016ab4f53599def19e56280", [:mix], [{:json_codec, "~> 0.1", [hex: :json_codec, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:reach, "~> 2.0", [hex: :reach, repo: "hexpm", optional: false]}, {:rustler, "~> 0.37", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "1c95a46d5f8636d4538569ef0bc1917622c47a7c3fe17ee852ff204d8503366f"},
2525
"sourceror": {:hex, :sourceror, "1.12.0", "da354c5f35aad3cc1132f5d5b0d8437d865e2661c263260480bab51b5eedb437", [:mix], [], "hexpm", "755703683bd014ebcd5de9acc24b68fb874a660a568d1d63f8f98cd8a6ef9cd0"},
2626
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
2727
}

rustq.exs

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use RustQ.Config
22

3-
alias RustQ.{Rust, Rustler}
3+
alias RustQ.Rustler.{Atom, Nif, Term}
44

55
codegen_atom_sources = [
66
"native/oxc_ex_nif/src/codegen.rs",
@@ -32,11 +32,11 @@ codegen_atoms =
3232
end)
3333

3434
rust :codegen_atoms, "native/oxc_ex_nif/src/generated_codegen_atoms.rs" do
35-
Rustler.atoms(codegen_atoms, module: false)
35+
Atom.declaration(codegen_atoms, module: false)
3636
end
3737

3838
rust "native/oxc_ex_nif/src/generated_atoms.rs" do
39-
Rustler.atoms([
39+
Atom.declaration([
4040
:ok,
4141
:error,
4242
{:atom_static, "static"},
@@ -104,11 +104,11 @@ rust "native/oxc_ex_nif/src/generated_atoms.rs" do
104104
end
105105

106106
rust "native/oxc_lint_nif/src/generated_atoms.rs" do
107-
Rustler.atoms([:ok, :error, :warn, :deny, :allow])
107+
Atom.declaration([:ok, :error, :warn, :deny, :allow])
108108
end
109109

110110
rust "native/oxc_fmt_nif/src/generated_atoms.rs" do
111-
Rustler.atoms([
111+
Atom.declaration([
112112
:ok,
113113
:error,
114114
:print_width,
@@ -147,20 +147,20 @@ rust "native/oxc_fmt_nif/src/generated_atoms.rs" do
147147
end
148148

149149
rust "native/oxc_fmt_nif/src/generated_option_helpers.rs" do
150-
Rustler.term_helpers(include: [:get, :get_bool, :get_i64, :get_string, :get_string_list, :get_map])
150+
Term.helpers(include: [:get, :get_bool, :get_i64, :get_string, :get_string_list, :get_map])
151151
end
152152

153-
type_key = Rust.path([:a, "r#type"]) <> "()"
153+
type_key = "a::r#type()"
154154

155155
rust "native/oxc_ex_nif/src/generated_term_helpers.rs" do
156-
Rustler.term_helpers(
156+
Term.helpers(
157157
type_key: type_key,
158158
include: [:get, :is_nil, :opt, :str_val, :bool_val, :f64_val, :list_val, :type_atom, :type_eq, :type_str]
159159
)
160160
end
161161

162162
rust "native/oxc_ex_nif/src/generated_option_helpers.rs" do
163-
Rustler.term_helpers(
163+
Term.helpers(
164164
include: [
165165
:get,
166166
:is_nil,
@@ -174,13 +174,13 @@ rust "native/oxc_ex_nif/src/generated_option_helpers.rs" do
174174
end
175175

176176
rust "native/oxc_ex_nif/src/generated_ast_decoders.rs" do
177-
Rustler.term_decoder(:ProgramInput,
177+
Term.decoder(:ProgramInput,
178178
fields: [
179179
body: [type: {:vec, "Term<'a>"}, key: "a::body()", required: true]
180180
]
181181
)
182182

183-
Rustler.term_decoder(:IfStatementInput,
183+
Term.decoder(:IfStatementInput,
184184
result: "R",
185185
fields: [
186186
test: [type: "Term<'a>", key: "a::test()", required: true],
@@ -191,60 +191,43 @@ rust "native/oxc_ex_nif/src/generated_ast_decoders.rs" do
191191
end
192192

193193
fmt_source = "native/oxc_fmt_nif/src/lib.rs"
194-
fmt_nifs = [format: [lifetime: :a]]
194+
fmt_nifs = [format: []]
195195

196196
rust :fmt_nifs, "native/oxc_fmt_nif/src/generated_nifs.rs" do
197-
Rustler.nif_exports_from_source(fmt_source, fmt_nifs, schedule: :dirty_cpu)
197+
Nif.wrappers_from_source(fmt_source, fmt_nifs, schedule: :dirty_cpu)
198198
end
199199

200200
generate :fmt_native_stubs, "lib/oxc/format/native/generated_stubs.ex" do
201201
build(fn ->
202-
Rustler.nif_stubs_from_source(fmt_source, fmt_nifs, OXC.Format.Native.GeneratedStubs)
202+
Nif.stubs_from_source(fmt_source, fmt_nifs, OXC.Format.Native.GeneratedStubs)
203203
end)
204204
end
205205

206206
lint_source = "native/oxc_lint_nif/src/lib.rs"
207-
lint_nifs = [lint: [lifetime: :a]]
207+
lint_nifs = [lint: []]
208208

209209
rust :lint_nifs, "native/oxc_lint_nif/src/generated_nifs.rs" do
210-
Rustler.nif_exports_from_source(lint_source, lint_nifs, schedule: :dirty_cpu)
210+
Nif.wrappers_from_source(lint_source, lint_nifs, schedule: :dirty_cpu)
211211
end
212212

213213
generate :lint_native_stubs, "lib/oxc/lint/native/generated_stubs.ex" do
214214
build(fn ->
215-
Rustler.nif_stubs_from_source(lint_source, lint_nifs, OXC.Lint.Native.GeneratedStubs)
215+
Nif.stubs_from_source(lint_source, lint_nifs, OXC.Lint.Native.GeneratedStubs)
216216
end)
217217
end
218218

219219
native_nif_groups = [
220-
{"native/oxc_ex_nif/src/parse.rs",
221-
[parse: [lifetime: :a], valid: [], transform: [lifetime: :a], minify: [lifetime: :a]]},
222-
{"native/oxc_ex_nif/src/bundle.rs",
223-
[bundle: [lifetime: :a], bundle_entry: [lifetime: :a], bundle_run: [lifetime: :a]]},
224-
{"native/oxc_ex_nif/src/imports.rs", [select: [lifetime: :a]]},
225-
{"native/oxc_ex_nif/src/transform_many.rs", [transform_many: [lifetime: :a]]},
226-
{"native/oxc_ex_nif/src/codegen.rs", [codegen: [lifetime: :a]]}
220+
{"native/oxc_ex_nif/src/parse.rs", [parse: [], valid: [], transform: [], minify: []]},
221+
{"native/oxc_ex_nif/src/bundle.rs", [bundle: [], bundle_entry: [], bundle_run: []]},
222+
{"native/oxc_ex_nif/src/imports.rs", [select: []]},
223+
{"native/oxc_ex_nif/src/transform_many.rs", [transform_many: []]},
224+
{"native/oxc_ex_nif/src/codegen.rs", [codegen: []]}
227225
]
228226

229-
native_nif_functions =
230-
Enum.flat_map(native_nif_groups, fn {source, nifs} ->
231-
metadata = source |> RustQ.Syn.parse_file!() |> RustQ.Syn.functions()
232-
233-
Enum.map(nifs, fn {name, _opts} ->
234-
implementation = "#{name}_impl"
235-
function = Enum.find(metadata, &(&1.name == implementation))
236-
237-
function || raise ArgumentError, "NIF implementation #{implementation} not found in #{source}"
238-
{name, function}
239-
end)
240-
end)
241-
242227
rust :native_nifs, "native/oxc_ex_nif/src/generated_nifs.rs" do
243-
Enum.flat_map(native_nif_groups, fn {source, nifs} ->
244-
Rustler.nif_exports_from_source(source, nifs, schedule: :dirty_cpu)
245-
end)
228+
Nif.wrappers_from_sources(native_nif_groups, schedule: :dirty_cpu)
246229
end
247230

248231
generate :native_stubs, "lib/oxc/native/generated_stubs.ex" do
249-
content(Rustler.nif_stubs_from_functions(native_nif_functions, OXC.Native.GeneratedStubs))
232+
content(Nif.stubs_from_sources(native_nif_groups, OXC.Native.GeneratedStubs))
250233
end

0 commit comments

Comments
 (0)