Skip to content

Commit

Permalink
Adding @sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bergel committed Mar 4, 2024
1 parent c241f9d commit 541cc25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct Ptr_Extension <: ExtendedRule end
struct ArrayWithNoType_Extension <: ExtendedRule end
struct Threads_Extension <: ExtendedRule end
struct Generated_Extension <: ExtendedRule end
struct Sync_Extension <: ExtendedRule end

const all_extended_rule_types = Ref{Any}(InteractiveUtils.subtypes(ExtendedRule))

Expand Down Expand Up @@ -187,3 +188,8 @@ end

check(::Generated_Extension, x::EXPR) = generic_check(x, "@generated hole_variable")

function check(::Sync_Extension, x::EXPR)
msg = "`@sync` should be used with extreme caution."
generic_check(x, "@sync hole_variable", msg)
generic_check(x, "Threads.@sync hole_variable", msg)
end
21 changes: 18 additions & 3 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ end
vec = T[]
return vec
end
try
@sync begin
@spawn_pager_bg_task RAI_PagerCore.add_to_cache!(conf, page)
@span_no_threshold "eot_rootmarker_write_to_blob" write_marker_to_cloud(
conf, page, rootinfo
)
end
catch
Threads.@sync begin
1 + 2
end
nothing
end
"""
@test lint_has_error_test(source)
@test lint_test(source,
Expand All @@ -91,10 +105,11 @@ end
"Line 7, column 5: `@threads` should be used with extreme caution.")
@test lint_test(source,
"Line 14, column 1: `@generated` should be used with extreme caution.")
@test lint_test(source,
"Line 20, column 5: `@sync` should be used with extreme caution.")
@test lint_test(source,
"Line 27, column 5: `@sync` should be used with extreme caution.")
end



end

@testset "forbidden functions" begin
Expand Down

0 comments on commit 541cc25

Please sign in to comment.