@@ -4056,27 +4056,6 @@ end
4056
4056
end |> only === Union{}
4057
4057
end
4058
4058
4059
- # Test that purity modeling doesn't accidentally introduce new world age issues
4060
- f_redefine_me (x) = x+ 1
4061
- f_call_redefine () = f_redefine_me (0 )
4062
- f_mk_opaque () = @Base . Experimental. opaque ()-> Base. inferencebarrier (f_call_redefine)()
4063
- const op_capture_world = f_mk_opaque ()
4064
- f_redefine_me (x) = x+ 2
4065
- @test op_capture_world () == 1
4066
- @test f_mk_opaque ()() == 2
4067
-
4068
- # Test that purity doesn't try to accidentally run unreachable code due to
4069
- # boundscheck elimination
4070
- function f_boundscheck_elim (n)
4071
- # Inbounds here assumes that this is only ever called with n==0, but of
4072
- # course the compiler has no way of knowing that, so it must not attempt
4073
- # to run the @inbounds `getfield(sin, 1)`` that ntuple generates.
4074
- ntuple (x-> (@inbounds getfield (sin, x)), n)
4075
- end
4076
- @test Tuple{} <: code_typed (f_boundscheck_elim, Tuple{Int})[1 ][2 ]
4077
-
4078
- @test ! Core. Compiler. builtin_nothrow (Core. get_binding_type, Any[Rational{Int}, Core. Const (:foo )], Any)
4079
-
4080
4059
# Test that max_methods works as expected
4081
4060
@Base . Experimental. max_methods 1 function f_max_methods end
4082
4061
f_max_methods (x:: Int ) = 1
@@ -4102,145 +4081,12 @@ end
4102
4081
Core. Compiler. return_type (+ , NTuple{2 , Rational})
4103
4082
end == Rational
4104
4083
4084
+ # vararg-tuple comparison within `PartialStruct`
4105
4085
# https://github.com/JuliaLang/julia/issues/44965
4106
4086
let t = Core. Compiler. tuple_tfunc (Any[Core. Const (42 ), Vararg{Any}])
4107
4087
@test Core. Compiler. issimplertype (t, t)
4108
4088
end
4109
4089
4110
- # https://github.com/JuliaLang/julia/issues/44763
4111
- global x44763:: Int = 0
4112
- increase_x44763! (n) = (global x44763; x44763 += n)
4113
- invoke44763 (x) = @invoke increase_x44763! (x)
4114
- @test Base. return_types () do
4115
- invoke44763 (42 )
4116
- end |> only === Int
4117
- @test x44763 == 0
4118
-
4119
- # backedge insertion for Any-typed, effect-free frame
4120
- const CONST_DICT = let d = Dict ()
4121
- for c in ' A' :' z'
4122
- push! (d, c => Int (c))
4123
- end
4124
- d
4125
- end
4126
- Base. @assume_effects :foldable getcharid (c) = CONST_DICT[c]
4127
- @noinline callf (f, args... ) = f (args... )
4128
- function entry_to_be_invalidated (c)
4129
- return callf (getcharid, c)
4130
- end
4131
- @test Base. infer_effects ((Char,)) do x
4132
- entry_to_be_invalidated (x)
4133
- end |> Core. Compiler. is_foldable
4134
- @test fully_eliminated (; retval= 97 ) do
4135
- entry_to_be_invalidated (' a' )
4136
- end
4137
- getcharid (c) = CONST_DICT[c] # now this is not eligible for concrete evaluation
4138
- @test Base. infer_effects ((Char,)) do x
4139
- entry_to_be_invalidated (x)
4140
- end |> ! Core. Compiler. is_foldable
4141
- @test ! fully_eliminated () do
4142
- entry_to_be_invalidated (' a' )
4143
- end
4144
-
4145
- # control flow backedge should taint `terminates`
4146
- @test Base. infer_effects ((Int,)) do n
4147
- for i = 1 : n; end
4148
- end |> ! Core. Compiler. is_terminates
4149
-
4150
- # Nothrow for assignment to globals
4151
- global glob_assign_int:: Int = 0
4152
- f_glob_assign_int () = global glob_assign_int += 1
4153
- let effects = Base. infer_effects (f_glob_assign_int, ())
4154
- @test ! Core. Compiler. is_effect_free (effects)
4155
- @test Core. Compiler. is_nothrow (effects)
4156
- end
4157
- # Nothrow for setglobal!
4158
- global SETGLOBAL!_NOTHROW:: Int = 0
4159
- let effects = Base. infer_effects () do
4160
- setglobal! (@__MODULE__ , :SETGLOBAL!_NOTHROW , 42 )
4161
- end
4162
- @test Core. Compiler. is_nothrow (effects)
4163
- end
4164
-
4165
- # we should taint `nothrow` if the binding doesn't exist and isn't fixed yet,
4166
- # as the cached effects can be easily wrong otherwise
4167
- # since the inference curently doesn't track "world-age" of global variables
4168
- @eval global_assignment_undefinedyet () = $ (GlobalRef (@__MODULE__ , :UNDEFINEDYET )) = 42
4169
- setglobal!_nothrow_undefinedyet () = setglobal! (@__MODULE__ , :UNDEFINEDYET , 42 )
4170
- let effects = Base. infer_effects () do
4171
- global_assignment_undefinedyet ()
4172
- end
4173
- @test ! Core. Compiler. is_nothrow (effects)
4174
- end
4175
- let effects = Base. infer_effects () do
4176
- setglobal!_nothrow_undefinedyet ()
4177
- end
4178
- @test ! Core. Compiler. is_nothrow (effects)
4179
- end
4180
- global UNDEFINEDYET:: String = " 0"
4181
- let effects = Base. infer_effects () do
4182
- global_assignment_undefinedyet ()
4183
- end
4184
- @test ! Core. Compiler. is_nothrow (effects)
4185
- end
4186
- let effects = Base. infer_effects () do
4187
- setglobal!_nothrow_undefinedyet ()
4188
- end
4189
- @test ! Core. Compiler. is_nothrow (effects)
4190
- end
4191
- @test_throws ErrorException setglobal!_nothrow_undefinedyet ()
4192
-
4193
- # Nothrow for setfield!
4194
- mutable struct SetfieldNothrow
4195
- x:: Int
4196
- end
4197
- f_setfield_nothrow () = SetfieldNothrow (0 ). x = 1
4198
- let effects = Base. infer_effects (f_setfield_nothrow, ())
4199
- # Technically effect free even though we use the heap, since the
4200
- # object doesn't escape, but the compiler doesn't know that.
4201
- # @test Core.Compiler.is_effect_free(effects)
4202
- @test Core. Compiler. is_nothrow (effects)
4203
- end
4204
-
4205
- # refine :consistent-cy effect inference using the return type information
4206
- @test Base. infer_effects ((Any,)) do x
4207
- taint = Ref {Any} (x) # taints :consistent-cy, but will be adjusted
4208
- throw (taint)
4209
- end |> Core. Compiler. is_consistent
4210
- @test Base. infer_effects ((Int,)) do x
4211
- if x < 0
4212
- taint = Ref (x) # taints :consistent-cy, but will be adjusted
4213
- throw (DomainError (x, taint))
4214
- end
4215
- return nothing
4216
- end |> Core. Compiler. is_consistent
4217
- @test Base. infer_effects ((Int,)) do x
4218
- if x < 0
4219
- taint = Ref (x) # taints :consistent-cy, but will be adjusted
4220
- throw (DomainError (x, taint))
4221
- end
4222
- return x == 0 ? nothing : x # should `Union` of isbitstype objects nicely
4223
- end |> Core. Compiler. is_consistent
4224
- @test Base. infer_effects ((Symbol,Any)) do s, x
4225
- if s === :throw
4226
- taint = Ref {Any} (" :throw option given" ) # taints :consistent-cy, but will be adjusted
4227
- throw (taint)
4228
- end
4229
- return s # should handle `Symbol` nicely
4230
- end |> Core. Compiler. is_consistent
4231
- @test Base. infer_effects ((Int,)) do x
4232
- return Ref (x)
4233
- end |> ! Core. Compiler. is_consistent
4234
- @test Base. infer_effects ((Int,)) do x
4235
- return x < 0 ? Ref (x) : nothing
4236
- end |> ! Core. Compiler. is_consistent
4237
- @test Base. infer_effects ((Int,)) do x
4238
- if x < 0
4239
- throw (DomainError (x, lazy " $x is negative" ))
4240
- end
4241
- return nothing
4242
- end |> Core. Compiler. is_foldable
4243
-
4244
4090
# check the inference convergence with an empty vartable:
4245
4091
# the inference state for the toplevel chunk below will have an empty vartable,
4246
4092
# and so we may fail to terminate (or optimize) it if we don't update vartables correctly
0 commit comments