Skip to content
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

julia nightly build throws TypeError in the implementation of Base.methods() #49982

Closed
gafter opened this issue May 29, 2023 · 4 comments · Fixed by #51134
Closed

julia nightly build throws TypeError in the implementation of Base.methods() #49982

gafter opened this issue May 29, 2023 · 4 comments · Fixed by #51134
Labels
error messages Better, more actionable error messages
Milestone

Comments

@gafter
Copy link
Contributor

gafter commented May 29, 2023

Testing my code passes my tests on 1.6.2, 1.8, 1.8.2, and 1.9. However, it fails on nightly with an exception.

  TypeError: in typeassert, expected Vector, got a value of type Nothing
  Stacktrace:
    [1] methods(f::Any, t::Any, mod::Nothing)
      @ Base ./reflection.jl:1060
    [2] methods (repeats 2 times)
      @ Base ./reflection.jl:1082 [inlined]
    [3] enumerate_children_names(node_type::Type{Sub})
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:221

versioninfo() reports

Julia Version 1.10.0-DEV.1392
Commit 248ceda3c49 (2023-05-27 13:39 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_SSL_CA_ROOTS_PATH = 
  JULIA_EDITOR = code

I installed the nightly by downloading the Apple silicon nightly build, mounting it, and dragging the app into my Applications folder.

You can reproduce the failure as follows (my repo is only a couple of hundred lines of code):

git clone https://github.com/RelationalAI/TreeTransform.jl
cd TreeTransform.jl
git checkout julia-nightly-issue
/Applications/Julia-1.10.app/Contents/Resources/julia/bin/julia
] # enter package mode
activate .
instantiate
# exit package mode
include("test/runtests.jl")

This will result, in short order, in

Check some simple cases: Error During Test at /Users/nealgafter/Repos/TreeTransform.jl/test/treetransform.jl:80
  Test threw exception
  Expression: simplify(Sub(x, Neg(y))) == Add(x, y)
  TypeError: in typeassert, expected Vector, got a value of type Nothing
  Stacktrace:
    [1] methods(f::Any, t::Any, mod::Nothing)
      @ Base ./reflection.jl:1060
    [2] methods (repeats 2 times)
      @ Base ./reflection.jl:1082 [inlined]
    [3] enumerate_children_names(node_type::Type{Sub})
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:220
    [4] #s7#16
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:266 [inlined]
    [5] var"#s7#16"(T::Any, ::Any, ctx::Any, node::Any)
      @ TreeTransform ./none:0
    [6] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
      @ Core ./boot.jl:598
    [7] fixed_point(ctx::TreeTransform.RewriteContext, node::Sub, rebuild::Bool)
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:336
    [8] bottom_up_rewrite(xform::Function, data::Sub; detect_cycles::Bool, max_transformations_per_node::Int64, recursive::Bool)
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:152
    [9] bottom_up_rewrite(xform::typeof(xform), data::Sub)
      @ TreeTransform ~/Repos/TreeTransform.jl/src/TreeTransform.jl:137 [inlined]
   [10] simplify(node::Sub)
      @ Main ~/Repos/TreeTransform.jl/test/treetransform.jl:73
   [11] macro expansion
      @ /Applications/Julia-1.10.app/Contents/Resources/julia/share/julia/stdlib/v1.10/Test/src/Test.jl:669 [inlined]
   [12] macro expansion
      @ ~/Repos/TreeTransform.jl/test/treetransform.jl:80 [inlined]
   [13] macro expansion
      @ /Applications/Julia-1.10.app/Contents/Resources/julia/share/julia/stdlib/v1.10/Test/src/Test.jl:1547 [inlined]
   [14] top-level scope
      @ ~/Repos/TreeTransform.jl/test/treetransform.jl:77
@vtjnash
Copy link
Sponsor Member

vtjnash commented May 29, 2023

It looks like you are trying to call methods from a generated function, and that is not supposed to work since the answer is not something legal for a generated function to inspect typically. The runtime now does a better job validating code for some errors.

@gafter
Copy link
Contributor Author

gafter commented May 29, 2023

I'm not sure why it would not be a good idea for a generated method to inspect the methods (in my case, constructors of a type).

Should I build a data structure that caches the information needed by the generated method before invoking it, and have the method pull the data from that data structure?

@gafter
Copy link
Contributor Author

gafter commented May 30, 2023

@vtnash Are you saying it is expected/intentional that Base.methods sometimes throws TypeError?

@KristofferC KristofferC added this to the 1.10 milestone May 30, 2023
@vtjnash
Copy link
Sponsor Member

vtjnash commented May 30, 2023

We should probably make that error message clearer, though it is not unexpected

@oscardssmith oscardssmith added the error messages Better, more actionable error messages label Aug 17, 2023
vtjnash added a commit that referenced this issue Sep 1, 2023
Not really a functional change, but just improving the error message
here to be consistent with other code reflection calls here. Closes
#49982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants