Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference: simplify is_const_prop_profitable_arg #47857

Merged
merged 1 commit into from
Dec 11, 2022

Conversation

aviatesk
Copy link
Sponsor Member

We have actually forwarded PartialStruct always.

@aviatesk aviatesk requested a review from Keno December 10, 2022 03:00
Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a whole lot more aggressive now, since it now ignores the type of the fields?

@aviatesk
Copy link
Sponsor Member Author

We have this code that returns true for all PartialStructs anyway:

isa(arg, Const) || return true

@Keno
Copy link
Member

Keno commented Dec 10, 2022

Should that just have been return false? Ordinarily this function isn't called on things for which has_nontrivial_const_info is false.

@Keno
Copy link
Member

Keno commented Dec 10, 2022

I think the idea of the return true was to allow lattice elements that may be introduced by external abstract interpreters.

@aviatesk
Copy link
Sponsor Member Author

Should that just have been return false?

I tried the same on #47851 and found it causes some inference failures (e.g. https://buildkite.com/julialang/julia-master/builds/19102#0184f9d9-def9-4e65-8af2-6fd79714e996).

@aviatesk
Copy link
Sponsor Member Author

I think I can come up with the better heuristic though. So maybe we want to comment out these lines for now and try to enable it properly in a separate PR.

@aviatesk
Copy link
Sponsor Member Author

diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl
index 5b5aec520f..5c23068b42 100644
--- a/base/compiler/abstractinterpretation.jl
+++ b/base/compiler/abstractinterpretation.jl
@@ -1143,7 +1143,16 @@ end
 
 function is_const_prop_profitable_arg(@nospecialize(arg))
     # have new information from argtypes that wasn't available from the signature
-    isa(arg, PartialStruct) && return true
+    if isa(arg, PartialStruct)
+        for i = 1:length(arg.fields)
+            fld = arg.fields[i]
+            isconstType(fld) && return true
+            is_const_prop_profitable_arg(fld) && return true
+            fld ⊏ fieldtype(arg.typ, i) && return true
+        end
+        println("[is_const_prop_profitable_arg] ", arg)
+        return false
+    end
     isa(arg, PartialOpaque) && return true
     isa(arg, Const) || return true
     val = arg.val

This change is sufficient to pass the existing inference test cases, but it turns out that then we never hit the return false case during sysimg build and test runs.

If we exclude the fld ⊏ fieldtype(arg.typ, i) && return true check, then the following test cases would fail:

  • getf(a) = a.f
    @test Base.return_types((AliasableField,); interp=MustAliasInterpreter()) do a
    if isa(getf(a), Int)
    return getf(a)
    end
    return 0
    end |> only === Int
  • @test Base.return_types((Int,)) do a
    s1 = Some{Any}(a)
    s2 = Some{Any}(s1)
    s2.value.value
    end |> only == Int

We have actually forwarded `PartialStruct` always.
@aviatesk
Copy link
Sponsor Member Author

So I'd like to go with return true for now (it was at least as aggressive as we have been).

@brenhinkeller brenhinkeller added the compiler:inference Type inference label Dec 11, 2022
@aviatesk aviatesk merged commit 704e117 into master Dec 11, 2022
@aviatesk aviatesk deleted the avi/forward-partial-struct branch December 11, 2022 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants