Skip to content

Commit b1cd0d5

Browse files
authored
Merge pull request #18 from QuantumBFS/auto-juliaformatter-pr
Automatic JuliaFormatter.jl run
2 parents 2a07f68 + 45c5e20 commit b1cd0d5

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

src/compiler/codegen/qobj.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ function codegen_ifnot(::TargetQobjQASM, ci::CodeInfo, st::CodeGenQobjState)
311311
error("classical post processing measurement result in Qobj is not supported")
312312
condition = st.register_map[creg.id]
313313
else
314-
error("invalid value for measurement result: $creg, possible fix: run :julia optimization pass before codegen")
314+
error(
315+
"invalid value for measurement result: $creg, possible fix: run :julia optimization pass before codegen",
316+
)
315317
end
316318

317319
length(condition) == 1 || error("Qobj only allows single bit condition for if statement")

src/compiler/optimize.jl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ Base.iterate(p::Core.Compiler.Pair, st) = Core.Compiler.iterate(p, st)
1818

1919
Base.getindex(m::Core.Compiler.MethodLookupResult, idx::Int) = Core.Compiler.getindex(m, idx)
2020

21-
function Core.Compiler.optimize(interp::YaoInterpreter, opt::OptimizationState, params::OptimizationParams, @nospecialize(result))
21+
function Core.Compiler.optimize(
22+
interp::YaoInterpreter,
23+
opt::OptimizationState,
24+
params::OptimizationParams,
25+
@nospecialize(result)
26+
)
2227
nargs = Int(opt.nargs) - 1
2328
@timeit "optimizer" ir = Core.Compiler.run_passes(opt.src, nargs, opt)
24-
29+
2530
# make sure all const are inlined
2631
# Julia itself may not inline all
2732
# the const values we want, e.g gates
@@ -204,31 +209,31 @@ function inline_const!(ir::IRCode)
204209
break
205210
end
206211
end
207-
212+
208213
if allconst &&
209214
isa(f, Core.IntrinsicFunction) &&
210215
is_pure_intrinsic_infer(f) &&
211216
intrinsic_nothrow(f, atypes[2:end])
212-
217+
213218
fargs = anymap(x::Const -> x.val, atypes[2:end])
214219
val = f(fargs...)
215220
ir.stmts[i][:inst] = quoted(val)
216221
ir.stmts[i][:type] = Const(val)
217-
elseif allconst && isa(f, Core.Builtin) &&
218-
(f === Core.tuple || f === Core.getfield)
222+
elseif allconst && isa(f, Core.Builtin) && (f === Core.tuple || f === Core.getfield)
219223
fargs = anymap(x::Const -> x.val, atypes[2:end])
220224
val = f(fargs...)
221225
ir.stmts[i][:inst] = quoted(val)
222226
ir.stmts[i][:type] = Const(val)
223227
end
224228
elseif stmt.head === :new
225229
exargs = stmt.args[2:end]
226-
allconst = all(arg->is_arg_allconst(ir, arg), exargs)
230+
allconst = all(arg -> is_arg_allconst(ir, arg), exargs)
227231
t = stmt.args[1]
228232
if allconst && isconcretetype(t) && !t.mutable
229-
args = anymap(arg->unwrap_arg(ir, arg), exargs)
230-
val = ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), t, args, length(args))
231-
233+
args = anymap(arg -> unwrap_arg(ir, arg), exargs)
234+
val =
235+
ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), t, args, length(args))
236+
232237
ir.stmts[i][:inst] = quoted(val)
233238
ir.stmts[i][:type] = Const(val)
234239
end
@@ -245,11 +250,11 @@ function elim_map_check!(ir::IRCode)
245250

246251
if stmt.head === :invoke && stmt.args[2] === GlobalRef(YaoLocations, :map_check)
247252
exargs = stmt.args[3:end]
248-
allconst = all(arg->is_arg_allconst(ir, arg), exargs)
253+
allconst = all(arg -> is_arg_allconst(ir, arg), exargs)
249254

250255

251256
if allconst
252-
args = anymap(arg->unwrap_arg(ir, arg), exargs)
257+
args = anymap(arg -> unwrap_arg(ir, arg), exargs)
253258
val = map_check_nothrow(args[1], args[2])
254259

255260
ir.stmts[i][:inst] = quoted(val)

src/runtime/intrinsics.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ function execute(stub::typeof(Semantic.barrier), r::TraceTape, loc::Locations)
109109
end
110110

111111
function execute(stub::typeof(Semantic.measure), r::TraceTape, locs::Locations)
112-
error("one should not trace programs contain @measure, since we cannot purify this hybrid program")
112+
error(
113+
"one should not trace programs contain @measure, since we cannot purify this hybrid program",
114+
)
113115
end
114116

115117
function trace_m(ex)

test/compiler/parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686
3 => post()
8787
end
8888
3 => rx(1.0)
89-
return (c=c, )
89+
return (c = c,)
9090
end
9191

9292
@testset "branches & const inline" begin

test/compiler/utils.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ end
3434
@testset "gate_count" begin
3535
@test gate_count(demo_circ_simp()) == Dict(
3636
:ctrl => IdDict(Z => 1, X => 4),
37-
:gate => IdDict(T => 2, H => 8, Rx/ 4) => 1, X => 2, S => 4, shift(7π/4) => 1, shift(3π/2)=>1),
37+
:gate => IdDict(
38+
T => 2,
39+
H => 8,
40+
Rx/ 4) => 1,
41+
X => 2,
42+
S => 4,
43+
shift(7π / 4) => 1,
44+
shift(3π / 2) => 1,
45+
),
3846
)
3947
end
4048

0 commit comments

Comments
 (0)