Skip to content

Commit

Permalink
Adding threads
Browse files Browse the repository at this point in the history
  • Loading branch information
bergel committed Mar 4, 2024
1 parent 9ffd483 commit 4291e80
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 86 deletions.
9 changes: 7 additions & 2 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ struct Inbounds_Extension <: ExtendedRule end
struct Atomic_Extension <: ExtendedRule end
struct Ptr_Extension <: ExtendedRule end
struct ArrayWithNoType_Extension <: ExtendedRule end


struct Threads_Extension <: ExtendedRule end

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

Expand Down Expand Up @@ -178,3 +177,9 @@ function check(::ArrayWithNoType_Extension, x::EXPR, markers::Dict{Symbol,String
contains(markers[:filename], "src/Compiler") || return
generic_check(x, "[]", "Need a specific Array type to be provided.")
end

function check(::Threads_Extension, x::EXPR)
msg = "`@threads` should be used with extreme caution."
generic_check(x, "Threads.@threads hole_variable", msg)
generic_check(x, "@threads hole_variable", msg)
end
178 changes: 94 additions & 84 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,105 +64,30 @@ end
"Line 2, column 5: Macro `@cfunction` should not be used.")
end

@testset "@lock" begin
@testset "@lock ,@threads" begin
source = """
function mark_transaction_as_database_creation!(kv::SpcsKV, transaction_id::String)
@lock kv.latch begin
push!(kv.create_database_transactions, transaction_id)
end
Threads.@threads for (e, v) in slots
@test e[] == v
free_slot!(pool, Blob{Nothing}(e))
end
return nothing
end
"""
@test lint_has_error_test(source)
@test lint_test(source,
"Line 2, column 5: `@lock` should be used with extreme caution")
@test lint_test(source,
"Line 7, column 5: `@threads` should be used with extreme caution.")
end


@testset "Locally disabling lint" begin
@testset "lint-disable-lint" begin
@test !lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
end
""")
@test !lint_has_error_test("""
function f()
@async 1 + 2 #lint-disable-line
end
""")

@test !lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
end
""")

@test lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
@async 1 + 3
end
""")
end
@testset "lint-disable-next-line" begin
@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")
@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")

@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")

@test lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
@async 1 + 3
end
""")
@test lint_has_error_test("""
function f()
@async 1 + 2
# lint-disable-next-line
@async 1 + 3
end
""")
@test lint_has_error_test("""
function f()
@async 1 + 2
# lint-disable-next-line
@async 1 + 3
end
""")

source = """
function f()
# lint-disable-next-line
@async 1 + 2

@async 1 + 3
end
"""
source_lines = split(source, "\n")
@test convert_offset_to_line_from_lines(46, source_lines) == (3, 4, Symbol("lint-disable-line"))
@test convert_offset_to_line_from_lines(64, source_lines) == (5, 4, nothing)
end
end
end

@testset "forbidden functions" begin
Expand Down Expand Up @@ -875,4 +800,89 @@ end
@test iszero(StaticLint.run_lint(dir))
end
end
end

@testset "Locally disabling lint" begin
@testset "lint-disable-lint" begin
@test !lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
end
""")
@test !lint_has_error_test("""
function f()
@async 1 + 2 #lint-disable-line
end
""")

@test !lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
end
""")

@test lint_has_error_test("""
function f()
@async 1 + 2 # lint-disable-line
@async 1 + 3
end
""")
end
@testset "lint-disable-next-line" begin
@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")
@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")

@test !lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
end
""")

@test lint_has_error_test("""
function f()
# lint-disable-next-line
@async 1 + 2
@async 1 + 3
end
""")
@test lint_has_error_test("""
function f()
@async 1 + 2
# lint-disable-next-line
@async 1 + 3
end
""")
@test lint_has_error_test("""
function f()
@async 1 + 2
# lint-disable-next-line
@async 1 + 3
end
""")

source = """
function f()
# lint-disable-next-line
@async 1 + 2
@async 1 + 3
end
"""
source_lines = split(source, "\n")
@test convert_offset_to_line_from_lines(46, source_lines) == (3, 4, Symbol("lint-disable-line"))
@test convert_offset_to_line_from_lines(64, source_lines) == (5, 4, nothing)
end
end

0 comments on commit 4291e80

Please sign in to comment.