Skip to content

Commit ca5a8ea

Browse files
committed
Some extra backports
1 parent 898353c commit ca5a8ea

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ function const_prop_profitable(@nospecialize(arg))
203203
isconstType(b) && return true
204204
const_prop_profitable(b) && return true
205205
end
206+
elseif isa(arg, PartialOpaque)
207+
return true
206208
elseif !isa(arg, Const) || (isa(arg.val, Symbol) || isa(arg.val, Type) || (!isa(arg.val, String) && !ismutable(arg.val)))
207209
# don't consider mutable values or Strings useful constants
208210
return true
@@ -1036,7 +1038,13 @@ function abstract_call_opaque_closure(interp::AbstractInterpreter, clos::Partial
10361038
nargtypes = argtypes[2:end]
10371039
pushfirst!(nargtypes, clos.env)
10381040
sig = argtypes_to_type(nargtypes)
1039-
rt, edge = abstract_call_method(interp, clos.ci::Method, sig, Core.svec(), false, sv)
1041+
rt, edgecycle, edge = abstract_call_method(interp, clos.ci::Method, sig, Core.svec(), false, sv)
1042+
if !edgecycle
1043+
const_rettype = abstract_call_method_with_const_args(interp, rt, argtypes[1], nargtypes, MethodMatch(sig, Core.svec(), clos.ci::Method, false), sv, edgecycle)
1044+
if const_rettype rt
1045+
rt = const_rettype
1046+
end
1047+
end
10401048
return CallMeta(rt, edge)
10411049
end
10421050
end

base/compiler/inferenceresult.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function is_argtype_match(@nospecialize(given_argtype),
44
@nospecialize(cache_argtype),
55
overridden_by_const::Bool)
6-
if isa(given_argtype, Const) || isa(given_argtype, PartialStruct)
6+
if isa(given_argtype, Const) || isa(given_argtype, PartialStruct) || isa(given_argtype, PartialOpaque)
77
return is_lattice_equal(given_argtype, cache_argtype)
88
end
99
return !overridden_by_const

base/compiler/ssair/passes.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,14 @@ function getfield_elim_pass!(ir::IRCode)
690690

691691
isempty(leaves) && continue
692692

693-
field = try_compute_fieldidx_expr(struct_typ, stmt)
694-
field === nothing && continue
693+
if is_getfield_opaque
694+
field = stmt.args[3]
695+
isa(field, QuoteNode) && (field = field.value)
696+
isa(field, Int) || continue
697+
else
698+
field = try_compute_fieldidx_expr(struct_typ, stmt)
699+
field === nothing && continue
700+
end
695701

696702
r = lift_leaves(compact, stmt, result_t, field, leaves, is_getfield_opaque)
697703
r === nothing && continue

base/compiler/typeutils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ end
3434

3535
function has_nontrivial_const_info(@nospecialize t)
3636
isa(t, PartialStruct) && return true
37+
isa(t, PartialOpaque) && return true
3738
return isa(t, Const) && !isdefined(typeof(t.val), :instance) && !(isa(t.val, Type) && hasuniquerep(t.val))
3839
end
3940

0 commit comments

Comments
 (0)