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
Raw File
exports.jl
# This file is a part of Julia. License is MIT: https://julialang.org/license

export
# Modules
    Meta,
    StackTraces,
    Sys,
    Libc,
    Docs,
    Threads,
    Iterators,
    Broadcast,
    MathConstants,

# Types
    AbstractChannel,
    AbstractIrrational,
    AbstractMatrix,
    AbstractRange,
    AbstractSet,
    AbstractUnitRange,
    AbstractVector,
    AbstractVecOrMat,
    Array,
    AbstractMatch,
    AbstractPattern,
    AbstractDict,
    BigFloat,
    BigInt,
    BitArray,
    BitMatrix,
    BitVector,
    CartesianIndex,
    CartesianIndices,
    LinearIndices,
    Channel,
    Cmd,
    Colon,
    Complex,
    ComplexF64,
    ComplexF32,
    ComplexF16,
    ComposedFunction,
    DenseMatrix,
    DenseVecOrMat,
    DenseVector,
    Dict,
    Dims,
    Enum,
    ExponentialBackOff,
    IndexCartesian,
    IndexLinear,
    IndexStyle,
    InsertionSort,
    BitSet,
    IOBuffer,
    IOStream,
    LinRange,
    Irrational,
    Matrix,
    MergeSort,
    Missing,
    NTuple,
    IdDict,
    OrdinalRange,
    Pair,
    PartialQuickSort,
    PermutedDimsArray,
    QuickSort,
    Rational,
    Regex,
    RegexMatch,
    Returns,
    RoundFromZero,
    RoundDown,
    RoundingMode,
    RoundNearest,
    RoundNearestTiesAway,
    RoundNearestTiesUp,
    RoundToZero,
    RoundUp,
    Set,
    Some,
    StepRange,
    StepRangeLen,
    StridedArray,
    StridedMatrix,
    StridedVecOrMat,
    StridedVector,
    SubArray,
    SubString,
    SubstitutionString,
    Timer,
    UnitRange,
    Val,
    VecOrMat,
    Vector,
    VersionNumber,
    WeakKeyDict,

# Ccall types
    Cchar,
    Cdouble,
    Cfloat,
    Cint,
    Cintmax_t,
    Clong,
    Clonglong,
    Cptrdiff_t,
    Cshort,
    Csize_t,
    Cssize_t,
    Cuchar,
    Cuint,
    Cuintmax_t,
    Culong,
    Culonglong,
    Cushort,
    Cwchar_t,
    Cstring,
    Cwstring,

# Exceptions
    CapturedException,
    CompositeException,
    DimensionMismatch,
    EOFError,
    InvalidStateException,
    KeyError,
    MissingException,
    ProcessFailedException,
    TaskFailedException,
    SystemError,
    StringIndexError,

# Global constants and variables
    ARGS,
    C_NULL,
    DEPOT_PATH,
    ENDIAN_BOM,
    ENV,
    LOAD_PATH,
    PROGRAM_FILE,
    stderr,
    stdin,
    stdout,
    VERSION,
    devnull,

# Mathematical constants
    Inf,
    Inf16,
    Inf32,
    Inf64,
    NaN,
    NaN16,
    NaN32,
    NaN64,
    im,
    π, pi,
    ℯ,

# Operators
    !,
    !=,
    ≠,
    !==,
    ≡,
    ≢,
    xor,
    ⊻,
    nand,
    nor,
    ⊼,
    ⊽,
    %,
    ÷,
    &,
    *,
    +,
    -,
    /,
    //,
    <,
    <:,
    <<,
    <=,
    ≤,
    ==,
    >,
    >:,
    >=,
    ≥,
    >>,
    >>>,
    \,
    ^,
    |,
    |>,
    ~,
    :,
    =>,
    ∘,

# scalar math
    @evalpoly,
    evalpoly,
    abs,
    abs2,
    acos,
    acosd,
    acosh,
    acot,
    acotd,
    acoth,
    acsc,
    acscd,
    acsch,
    angle,
    asec,
    asecd,
    asech,
    asin,
    asind,
    asinh,
    atan,
    atand,
    atanh,
    big,
    binomial,
    bitreverse,
    bitrotate,
    bswap,
    cbrt,
    ceil,
    cis,
    cispi,
    clamp,
    cld,
    cmp,
    complex,
    conj,
    copysign,
    cos,
    cosc,
    cosd,
    cosh,
    cospi,
    cot,
    cotd,
    coth,
    count_ones,
    count_zeros,
    csc,
    cscd,
    csch,
    deg2rad,
    denominator,
    div,
    divrem,
    eps,
    exp,
    exp10,
    exp2,
    expm1,
    exponent,
    factorial,
    fld,
    fld1,
    fldmod,
    fldmod1,
    flipsign,
    float,
    tryparse,
    floor,
    fma,
    frexp,
    gcd,
    gcdx,
    hypot,
    imag,
    inv,
    invmod,
    isapprox,
    iseven,
    isfinite,
    isinf,
    isinteger,
    isnan,
    isodd,
    ispow2,
    isqrt,
    isreal,
    issubnormal,
    iszero,
    isone,
    lcm,
    ldexp,
    leading_ones,
    leading_zeros,
    log,
    log10,
    log1p,
    log2,
    maxintfloat,
    mod,
    mod1,
    modf,
    mod2pi,
    muladd,
    nextfloat,
    nextpow,
    nextprod,
    numerator,
    one,
    oneunit,
    powermod,
    prevfloat,
    prevpow,
    rad2deg,
    rationalize,
    real,
    floatmax,
    floatmin,
    reim,
    reinterpret,
    rem,
    rem2pi,
    round,
    sec,
    secd,
    sech,
    sign,
    signbit,
    signed,
    significand,
    sin,
    sinc,
    sincos,
    sincosd,
    sincospi,
    sind,
    sinh,
    sinpi,
    sqrt,
    tan,
    tand,
    tanh,
    trailing_ones,
    trailing_zeros,
    trunc,
    unsafe_trunc,
    typemax,
    typemin,
    unsigned,
    widemul,
    zero,
    √,
    ∛,
    ≈,
    ≉,

# arrays
    axes,
    broadcast!,
    broadcast,
    cat,
    checkbounds,
    checkindex,
    circcopy!,
    circshift,
    circshift!,
    clamp!,
    conj!,
    copy!,
    copyto!,
    diff,
    cumprod,
    cumprod!,
    cumsum,
    cumsum!,
    accumulate,
    accumulate!,
    eachcol,
    eachindex,
    eachrow,
    eachslice,
    extrema,
    fill!,
    fill,
    first,
    hcat,
    hvcat,
    hvncat,
    indexin,
    argmax,
    argmin,
    invperm,
    invpermute!,
    isassigned,
    isperm,
    issorted,
    last,
    mapslices,
    max,
    maximum!,
    maximum,
    min,
    minimum!,
    minimum,
    minmax,
    ndims,
    ones,
    parent,
    parentindices,
    partialsort,
    partialsort!,
    partialsortperm,
    partialsortperm!,
    permute!,
    permutedims,
    permutedims!,
    prod!,
    prod,
    promote_shape,
    range,
    reshape,
    reverse!,
    reverse,
    rot180,
    rotl90,
    rotr90,
    size,
    selectdim,
    sort!,
    sort,
    sortperm,
    sortperm!,
    sortslices,
    dropdims,
    step,
    stride,
    strides,
    sum!,
    sum,
    to_indices,
    vcat,
    vec,
    view,
    zeros,

# search, find, match and related functions
    contains,
    eachmatch,
    endswith,
    findall,
    findfirst,
    findlast,
    findmax,
    findmin,
    findmin!,
    findmax!,
    findnext,
    findprev,
    match,
    occursin,
    searchsorted,
    searchsortedfirst,
    searchsortedlast,
    insorted,
    startswith,

# linear algebra
    var"'", # to enable syntax a' for adjoint
    adjoint,
    transpose,
    kron,
    kron!,

# bitarrays
    falses,
    trues,

# dequeues
    append!,
    insert!,
    pop!,
    popat!,
    prepend!,
    push!,
    resize!,
    popfirst!,
    pushfirst!,

# collections
    all!,
    all,
    allunique,
    any!,
    any,
    firstindex,
    collect,
    count!,
    count,
    delete!,
    deleteat!,
    keepat!,
    eltype,
    empty!,
    empty,
    lastindex,
    filter!,
    filter,
    foldl,
    foldr,
    foreach,
    get,
    get!,
    getindex,
    getkey,
    haskey,
    in,
    intersect!,
    intersect,
    isdisjoint,
    isempty,
    issubset,
    issetequal,
    keys,
    keytype,
    length,
    map!,
    map,
    mapfoldl,
    mapfoldr,
    mapreduce,
    merge!,
    mergewith!,
    merge,
    mergewith,
    pairs,
    reduce,
    setdiff!,
    setdiff,
    setindex!,
    similar,
    sizehint!,
    splice!,
    symdiff!,
    symdiff,
    union!,
    union,
    unique!,
    unique,
    values,
    valtype,
    ∈,
    ∉,
    ∋,
    ∌,
    ⊆,
    ⊈,
    ⊊,
    ⊇,
    ⊉,
    ⊋,
    ∩,
    ∪,

# strings
    ascii,
    bitstring,
    bytes2hex,
    chomp,
    chop,
    codepoint,
    codeunit,
    codeunits,
    digits,
    digits!,
    eachsplit,
    escape_string,
    hex2bytes,
    hex2bytes!,
    isascii,
    iscntrl,
    isdigit,
    isletter,
    islowercase,
    isnumeric,
    isprint,
    ispunct,
    isspace,
    isuppercase,
    isxdigit,
    lowercase,
    lowercasefirst,
    isvalid,
    join,
    lpad,
    lstrip,
    ncodeunits,
    ndigits,
    nextind,
    prevind,
    repeat,
    replace,
    replace!,
    repr,
    reverseind,
    rpad,
    rsplit,
    rstrip,
    split,
    string,
    strip,
    textwidth,
    thisind,
    titlecase,
    transcode,
    unescape_string,
    uppercase,
    uppercasefirst,

# text output
    IOContext,
    displaysize,
    dump,
    print,
    println,
    printstyled,
    show,
    showerror,
    sprint,
    summary,

# logging
    @debug,
    @info,
    @warn,
    @error,

# bigfloat & precision
    precision,
    rounding,
    setprecision,
    setrounding,
    get_zero_subnormals,
    set_zero_subnormals,

# iteration
    iterate,

    enumerate,  # re-exported from Iterators
    zip,
    only,

# object identity and equality
    copy,
    deepcopy,
    hash,
    identity,
    isbits,
    isequal,
    ismutable,
    ismutabletype,
    isless,
    isunordered,
    ifelse,
    objectid,
    sizeof,

# tasks and conditions
    Condition,
    current_task,
    islocked,
    istaskdone,
    istaskstarted,
    istaskfailed,
    lock,
    @lock,
    notify,
    ReentrantLock,
    schedule,
    task_local_storage,
    trylock,
    unlock,
    yield,
    yieldto,
    wait,
    timedwait,
    asyncmap,
    asyncmap!,
    errormonitor,

# channels
    take!,
    put!,
    isready,
    fetch,
    bind,

# missing values
    coalesce,
    @coalesce,
    ismissing,
    missing,
    skipmissing,
    @something,
    something,
    isnothing,
    nonmissingtype,

# time
    sleep,
    time,
    time_ns,

# errors
    backtrace,
    catch_backtrace,
    current_exceptions,
    error,
    rethrow,
    retry,
    systemerror,

# stack traces
    stacktrace,

# types
    convert,
    getproperty,
    setproperty!,
    swapproperty!,
    modifyproperty!,
    replaceproperty!,
    fieldoffset,
    fieldname,
    fieldnames,
    fieldcount,
    fieldtypes,
    hasfield,
    propertynames,
    hasproperty,
    isabstracttype,
    isbitstype,
    isprimitivetype,
    isstructtype,
    isconcretetype,
    isdispatchtuple,
    oftype,
    promote,
    promote_rule,
    promote_type,
    instances,
    supertype,
    typeintersect,
    typejoin,
    widen,

# syntax
    esc,
    gensym,
    macroexpand,
    @macroexpand1,
    @macroexpand,
    parse,

# help and reflection
    code_typed,
    code_lowered,
    fullname,
    functionloc,
    isconst,
    isinteractive,
    hasmethod,
    methods,
    nameof,
    parentmodule,
    pathof,
    pkgdir,
    names,
    which,
    @isdefined,

# loading source files
    __precompile__,
    evalfile,
    include_string,
    include_dependency,

# RTS internals
    GC,
    finalizer,
    finalize,
    precompile,

# misc
    atexit,
    atreplinit,
    exit,
    ntuple,

# I/O and events
    close,
    closewrite,
    countlines,
    eachline,
    readeach,
    eof,
    fd,
    fdio,
    flush,
    gethostname,
    htol,
    hton,
    ismarked,
    isopen,
    isreadonly,
    ltoh,
    mark,
    bytesavailable,
    ntoh,
    open,
    peek,
    pipeline,
    Pipe,
    PipeBuffer,
    position,
    RawFD,
    read,
    read!,
    readavailable,
    readbytes!,
    readchomp,
    readdir,
    readline,
    readlines,
    readuntil,
    redirect_stdio,
    redirect_stderr,
    redirect_stdin,
    redirect_stdout,
    reset,
    seek,
    seekend,
    seekstart,
    skip,
    skipchars,
    take!,
    truncate,
    unmark,
    unsafe_read,
    unsafe_write,
    write,

# multimedia I/O
    AbstractDisplay,
    display,
    displayable,
    TextDisplay,
    istextmime,
    MIME,
    @MIME_str,
    popdisplay,
    pushdisplay,
    redisplay,
    showable,
    HTML,
    Text,

# paths and file names
    abspath,
    basename,
    dirname,
    expanduser,
    homedir,
    isabspath,
    isdirpath,
    joinpath,
    normpath,
    realpath,
    relpath,
    splitdir,
    splitdrive,
    splitext,
    splitpath,

# filesystem operations
    cd,
    chmod,
    chown,
    cp,
    ctime,
    diskstat,
    download,
    filemode,
    filesize,
    gperm,
    hardlink,
    isblockdev,
    ischardev,
    isdir,
    isfifo,
    isfile,
    islink,
    ismount,
    ispath,
    isreadable,
    issetgid,
    issetuid,
    issocket,
    issticky,
    iswritable,
    lstat,
    mkdir,
    mkpath,
    mktemp,
    mktempdir,
    mtime,
    mv,
    operm,
    pwd,
    readlink,
    rm,
    stat,
    symlink,
    tempdir,
    tempname,
    touch,
    uperm,
    walkdir,

# external processes
    detach,
    getpid,
    ignorestatus,
    kill,
    process_exited,
    process_running,
    run,
    setenv,
    addenv,
    success,
    withenv,

# C interface
    @cfunction,
    @ccall,
    cglobal,
    disable_sigint,
    pointer,
    pointer_from_objref,
    unsafe_wrap,
    unsafe_string,
    reenable_sigint,
    unsafe_copyto!,
    unsafe_load,
    unsafe_pointer_to_objref,
    unsafe_store!,

# implemented in Random module
    rand,
    randn,

# Macros
    # parser internal
    @__FILE__,
    @__DIR__,
    @__LINE__,
    @__MODULE__,
    @int128_str,
    @uint128_str,
    @big_str,
    @cmd,    # `commands`

    # notation for certain types
    @b_str,    # byte vector
    @r_str,    # regex
    @s_str,    # regex substitution string
    @v_str,    # version number
    @raw_str,  # raw string with no interpolation/unescaping
    @NamedTuple,

    # documentation
    @text_str,
    @html_str,
    @doc,

    # output
    @show,

    # profiling
    @time,
    @showtime,
    @timed,
    @timev,
    @elapsed,
    @allocated,

    # tasks
    @sync,
    @async,
    @task,
    @threadcall,

    # metaprogramming utilities
    @generated,
    @gensym,
    @eval,
    @deprecate,

    # performance annotations
    @boundscheck,
    @inbounds,
    @fastmath,
    @simd,
    @inline,
    @noinline,
    @nospecialize,
    @specialize,
    @polly,

    @assert,
    @atomic,
    @atomicswap,
    @atomicreplace,
    @__dot__,
    @enum,
    @label,
    @goto,
    @view,
    @views,
    @static
back to top