-
Notifications
You must be signed in to change notification settings - Fork 30
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
# 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?
test/tracing.jl
Outdated
struct Bar{T} | ||
b::T | ||
end | ||
struct Foo{T, B<:Bar{T}, AT<:AbstractArray{T}} |
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 🐶
struct Foo{T, B<:Bar{T}, AT<:AbstractArray{T}} | |
struct Foo{T,B<:Bar{T},AT<:AbstractArray{T}} |
test/tracing.jl
Outdated
a::AT | ||
b::B | ||
end | ||
@test Reactant.apply_type_with_promotion(Foo, [Float64, Bar{Float64}, Reactant.TracedRArray{Float64, 1}]) == Foo{ |
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 🐶
@test Reactant.apply_type_with_promotion(Foo, [Float64, Bar{Float64}, Reactant.TracedRArray{Float64, 1}]) == Foo{ | |
@test Reactant.apply_type_with_promotion( | |
Foo, [Float64, Bar{Float64}, Reactant.TracedRArray{Float64,1}] | |
) == Foo{ |
test/tracing.jl
Outdated
@test Reactant.apply_type_with_promotion(Foo, [Float64, Bar{Float64}, Reactant.TracedRArray{Float64, 1}]) == Foo{ | ||
TracedRNumber{Float64}, | ||
Bar{TracedRNumber{Float64}}, | ||
Reactant.TracedRArray{Float64, 1}, |
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 🐶
Reactant.TracedRArray{Float64, 1}, | |
Reactant.TracedRArray{Float64,1}, |
While in my testing
traced_type
now does the typevar promotion we talked about, it doesn't yet work formake_tracer
as the result fromtraced_types
isn't used to guidemake_tracer
AFAICT.