-
Notifications
You must be signed in to change notification settings - Fork 38
apply_type_with_promotion #1681
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
base: main
Are you sure you want to change the base?
Conversation
src/Tracing.jl
Outdated
| # The field is constrained by a TypeVar directly, | ||
| # so we don't need to check. | ||
| # (The check below would fail if the typevar was promoted as | ||
| # we don't get the same result when calling traced_type_inner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we still need to check below that the subtype matches, even if constrained? just to confirm we did do the typevar solve correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure...
The reason I added this early return is for e.g.:
Foo{Float64, Bar{Float64}, ConcretePJRTArray{Float64, 1}}
Which, with ConcreteToTraced is now converted to:
Foo{TracedRNumber{Float64}, Bar{TracedRNumber{Float64}}, TracedRArray{Float64, 1}}
The field b of the original type is Bar{Float64}. When tracing this, it just returns Bar{Float64} because of lack of constraints. So what should we compare the fieldtype against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct T
d::Array
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct T{D<:Array}
d::D
end
struct T{D<:AbstractArray{Float64}}
d::D
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check can be skipped when an unconstrained typevar
- must be skipped when that typevar is itself a dependency of another type. If this is true in any case, we need the fancy make_tracer
- may be run when that typevar is itself not a dependency of another type. If this is true in all cases, we don't need the upgrade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case where need to skip checj
struct MyNewArray{FT, N, D <: AbstractArray{FT, N}}
data::D
off::FT
end
| This function tries to apply the param types to the wrapper type. | ||
| When there's a constraint conflict, it tries to resolve it by promoting the conflicting types. The new param type is then propagated in any param type that depends on it. | ||
| """ | ||
| function apply_type_with_promotion(wrapper, params, relevant_typevars=typevar_dict(wrapper)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add some tests?
src/Tracing.jl
Outdated
| function collect_tvars_in_type!(dependencies, @nospecialize(t)) | ||
| if t isa TypeVar | ||
| push!(dependencies, t) | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| return | |
| return nothing |
src/Tracing.jl
Outdated
| return T | ||
| end | ||
|
|
||
| @debug "traced_type_inner: Processing type with field changes" T=T subTys=subTys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| @debug "traced_type_inner: Processing type with field changes" T=T subTys=subTys | |
| @debug "traced_type_inner: Processing type with field changes" T = T subTys = subTys |
src/Tracing.jl
Outdated
| wrapped_cifrt_array = T <: AbstractArray && ancestor(T) <: ConcreteIFRTArray | ||
| wrapped_tracedarray = T <: AbstractArray && ancestor(T) <: TracedRArray | ||
|
|
||
| @debug "wrapped flags" wrapped_cpjrt_array=wrapped_cpjrt_array wrapped_cifrt_array=wrapped_cifrt_array wrapped_tracedarray=wrapped_tracedarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| @debug "wrapped flags" wrapped_cpjrt_array=wrapped_cpjrt_array wrapped_cifrt_array=wrapped_cifrt_array wrapped_tracedarray=wrapped_tracedarray | |
| @debug "wrapped flags" wrapped_cpjrt_array = wrapped_cpjrt_array wrapped_cifrt_array = | |
| wrapped_cifrt_array wrapped_tracedarray = wrapped_tracedarray |
src/Tracing.jl
Outdated
| @debug "wrapped flags" wrapped_cpjrt_array=wrapped_cpjrt_array wrapped_cifrt_array=wrapped_cifrt_array wrapped_tracedarray=wrapped_tracedarray | ||
|
|
||
| subParms = [] | ||
| @debug "Tracing type parameters" num_params=length(T.parameters) T_parameters=T.parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| @debug "Tracing type parameters" num_params=length(T.parameters) T_parameters=T.parameters | |
| @debug "Tracing type parameters" num_params = length(T.parameters) T_parameters = | |
| T.parameters |
src/Tracing.jl
Outdated
| end | ||
| end | ||
|
|
||
| @debug "Built subParms" subParms=subParms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| @debug "Built subParms" subParms=subParms | |
| @debug "Built subParms" subParms = subParms |
src/Tracing.jl
Outdated
| return TT2 | ||
| end | ||
| else | ||
| @debug "Field count mismatch" fieldcount_T=fieldcount(T) fieldcount_TT2=fieldcount(TT2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| @debug "Field count mismatch" fieldcount_T=fieldcount(T) fieldcount_TT2=fieldcount(TT2) | |
| @debug "Field count mismatch" fieldcount_T = fieldcount(T) fieldcount_TT2 = fieldcount( | |
| TT2 | |
| ) |
src/Tracing.jl
Outdated
| xi2 = Core.Typeof(xi2)((newpath,), xi2.mlir_data) | ||
| seen[xi2] = xi2 | ||
| changed = true | ||
| elseif !ismutabletype(FT) && !ismutabletype(Core.Typeof(xi2)) && fieldcount(FT) == fieldcount(Core.Typeof(xi2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| elseif !ismutabletype(FT) && !ismutabletype(Core.Typeof(xi2)) && fieldcount(FT) == fieldcount(Core.Typeof(xi2)) | |
| elseif !ismutabletype(FT) && | |
| !ismutabletype(Core.Typeof(xi2)) && | |
| fieldcount(FT) == fieldcount(Core.Typeof(xi2)) |
src/Tracing.jl
Outdated
| val_wrapped = ft_j(val_j) | ||
| # Correct the path for the wrapped scalar | ||
| sub_path = append_path(newpath, j) | ||
| val_wrapped = Core.Typeof(val_wrapped)((sub_path,), val_wrapped.mlir_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| val_wrapped = Core.Typeof(val_wrapped)((sub_path,), val_wrapped.mlir_data) | |
| val_wrapped = Core.Typeof(val_wrapped)( | |
| (sub_path,), val_wrapped.mlir_data | |
| ) |
src/Tracing.jl
Outdated
| end | ||
|
|
||
| if success | ||
| xi2 = ccall(:jl_new_structv, Any, (Any, Ptr{Any}, UInt32), FT, flds_sub, fieldcount(FT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| xi2 = ccall(:jl_new_structv, Any, (Any, Ptr{Any}, UInt32), FT, flds_sub, fieldcount(FT)) | |
| xi2 = ccall( | |
| :jl_new_structv, | |
| Any, | |
| (Any, Ptr{Any}, UInt32), | |
| FT, | |
| flds_sub, | |
| fieldcount(FT), | |
| ) |
test/tracing.jl
Outdated
| ) == (Foo{ | ||
| TracedRNumber{Float64}, | ||
| Bar{TracedRNumber{Float64}}, | ||
| Reactant.TracedRArray{Float64,1}, | ||
| }, [true, true, false]) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
I added a bunch of debug statements that seem handy to keep around. |
src/Tracing.jl
Outdated
| return T | ||
| end | ||
|
|
||
| @debug "traced_type_inner: Processing type with field changes" T = T subTys = subTys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably get rid of the debug statements here, if no longer necessary
|
@giordano adding you as a reviewer. this should remedy many of the custom type annotations weve historically needed for oceananigans and fixedsizearray |
|
Not sure how I should fix the CI docs failure. It's an internal method but still useful to have a docstring imo. |
While in my testing
traced_typenow does the typevar promotion we talked about, it doesn't yet work formake_traceras the result fromtraced_typesisn't used to guidemake_tracerAFAICT.