Revision a121721f975fc4105ed24ebd0ad1020d08d07a38 authored by Shuhei Kadowaki on 01 November 2021, 10:49:07 UTC, committed by GitHub on 01 November 2021, 10:49:07 UTC
* inference: form `PartialStruct` for extra type information propagation This commit forms `PartialStruct` whenever there is any type-level refinement available about a field, even if it's not "constant" information. In Julia "definitions" are allowed to be abstract whereas "usages" (i.e. callsites) are often concrete. The basic idea is to allow inference to make more use of such precise callsite type information by encoding it as `PartialStruct`. This may increase optimization possibilities of "unidiomatic" Julia code, which may contain poorly-typed definitions, like this very contrived example: ```julia struct Problem n; s; c; t end function main(args...) prob = Problem(args...) s = 0 for i in 1:prob.n m = mod(i, 3) s += m == 0 ? sin(prob.s) : m == 1 ? cos(prob.c) : tan(prob.t) end return prob, s end main(10000, 1, 2, 3) ``` One of the obvious limitation is that this extra type information can be propagated inter-procedurally only as a const-propagation. I'm not sure this kind of "just a type-level" refinement can often make constant-prop' successful (i.e. shape-up a method body and allow it to be inlined, encoding the extra type information into the generated code), thus I didn't not modify any part of const-prop' heuristics. So the improvements from this change might not be very useful for general inter-procedural analysis currently, but they should definitely improve the accuracy of local analysis and very simple inter-procedural analysis.
1 parent 6c274ed
ctypes.jl
# This file is a part of Julia. License is MIT: https://julialang.org/license
# essential type definitions for interacting with C code
# (platform- or OS-dependent types are defined in c.jl)
"""
Cuchar
Equivalent to the native `unsigned char` c-type ([`UInt8`](@ref)).
"""
const Cuchar = UInt8
"""
Cshort
Equivalent to the native `signed short` c-type ([`Int16`](@ref)).
"""
const Cshort = Int16
"""
Cushort
Equivalent to the native `unsigned short` c-type ([`UInt16`](@ref)).
"""
const Cushort = UInt16
"""
Cint
Equivalent to the native `signed int` c-type ([`Int32`](@ref)).
"""
const Cint = Int32
"""
Cuint
Equivalent to the native `unsigned int` c-type ([`UInt32`](@ref)).
"""
const Cuint = UInt32
"""
Cptrdiff_t
Equivalent to the native `ptrdiff_t` c-type (`Int`).
"""
const Cptrdiff_t = Int
"""
Csize_t
Equivalent to the native `size_t` c-type (`UInt`).
"""
const Csize_t = UInt
"""
Cssize_t
Equivalent to the native `ssize_t` c-type.
"""
const Cssize_t = Int
"""
Cintmax_t
Equivalent to the native `intmax_t` c-type ([`Int64`](@ref)).
"""
const Cintmax_t = Int64
"""
Cuintmax_t
Equivalent to the native `uintmax_t` c-type ([`UInt64`](@ref)).
"""
const Cuintmax_t = UInt64
"""
Clonglong
Equivalent to the native `signed long long` c-type ([`Int64`](@ref)).
"""
const Clonglong = Int64
"""
Culonglong
Equivalent to the native `unsigned long long` c-type ([`UInt64`](@ref)).
"""
const Culonglong = UInt64
"""
Cfloat
Equivalent to the native `float` c-type ([`Float32`](@ref)).
"""
const Cfloat = Float32
"""
Cdouble
Equivalent to the native `double` c-type ([`Float64`](@ref)).
"""
const Cdouble = Float64
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...