diff --git a/base/sysimg.jl b/base/sysimg.jl index 16874fadcb50a..2398b334fd855 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -373,6 +373,9 @@ importall .StackTraces # misc useful functions & macros include("util.jl") +# limited compile-time arithmetic on Val types +include("valmath.jl") + # dense linear algebra include("linalg/linalg.jl") importall .LinAlg diff --git a/base/valmath.jl b/base/valmath.jl new file mode 100644 index 0000000000000..64c38c9317833 --- /dev/null +++ b/base/valmath.jl @@ -0,0 +1,3 @@ +@generated (+)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X + Y)}) +@generated (-)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X - Y)}) +@generated (*)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X * Y)}) diff --git a/test/choosetests.jl b/test/choosetests.jl index 7558b74179bc4..1283f59bf99c6 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -35,7 +35,7 @@ function choosetests(choices = []) "enums", "cmdlineargs", "i18n", "workspace", "libdl", "int", "checked", "intset", "floatfuncs", "compile", "distributed", "inline", "boundscheck", "error", "ambiguous", "cartesian", "asmvariant", "osutils", - "channels", "iostream", "specificity", "codegen" + "channels", "iostream", "specificity", "codegen", "valmath" ] profile_skipped = false if startswith(string(Sys.ARCH), "arm") diff --git a/test/valmath.jl b/test/valmath.jl new file mode 100644 index 0000000000000..14c5f9d13ba0c --- /dev/null +++ b/test/valmath.jl @@ -0,0 +1,19 @@ +@testset "Val math" begin + @testset "Val +" begin + @testset for x in -10:1:10, y in -10:1:10 + @test Val{x} + Val{y} == Val{x + y} + end + end + + @testset "Val -" begin + @testset for x in -10:1:10, y in -10:1:10 + @test Val{x} - Val{y} == Val{x - y} + end + end + + @testset "Val *" begin + @testset for x in -10:1:10, y in -10:1:10 + @test Val{x} * Val{y} == Val{x * y} + end + end +end