Skip to content

Commit

Permalink
Correctly handle PartialTypeVars in inference (#305)
Browse files Browse the repository at this point in the history
* Fix up _type

* Bump patch version

* Bump patch version
  • Loading branch information
willtebbutt authored Oct 22, 2024
1 parent 77f8861 commit c58457f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Mooncake"
uuid = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.4.19"
version = "0.4.20"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
3 changes: 2 additions & 1 deletion src/interpreter/abstract_interpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ else
get_inference_world(interp::CC.AbstractInterpreter) = CC.get_inference_world(interp)
end

_type(x) = x
_type(x::Type) = x
_type(x::CC.Const) = _typeof(x.val)
_type(x::CC.PartialStruct) = x.typ
_type(x::CC.Conditional) = Union{_type(x.thentype), _type(x.elsetype)}
_type(::CC.PartialTypeVar) = TypeVar

struct NoInlineCallInfo <: CC.CallInfo
info::CC.CallInfo # wrapped call
Expand Down
3 changes: 2 additions & 1 deletion test/front_matter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ using Mooncake:
verify_rdata_value,
is_primitive,
MinimalCtx,
stmt
stmt,
_type

using .TestUtils:
test_rule,
Expand Down
4 changes: 4 additions & 0 deletions test/interpreter/abstract_interpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ contains_primitive_behind_call(x) = @inline contains_primitive(x)
@test stmt(ad_ir.stmts)[invoke_line].args[2] == GlobalRef(Main, :a_primitive)
end
end
@testset "_type" begin
@test _type(CC.Const(5.0)) === Float64
@test _type(CC.PartialTypeVar(TypeVar(:a, Union{}, Any), true, true)) === TypeVar
end
end

2 comments on commit c58457f

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/117805

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.20 -m "<description of version>" c58457f45270b86fe827a63fc7b6def00523afb3
git push origin v0.4.20

Please sign in to comment.