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

Erroneous warning when using types in keyword argument function declaration #49275

Open
mmiller-max opened this issue Apr 6, 2023 · 4 comments
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@mmiller-max
Copy link
Contributor

mmiller-max commented Apr 6, 2023

If I have a function with a nested type delegation (two wheres), I get the following incorrect warning

julia> foo(;a::T) where {T<:AbstractVector{N}} where {N} = zero(N)
WARNING: method definition for foo at REPL[5]:1 declares type variable N but does not use it.
WARNING: method definition for foo##kw at REPL[5]:1 declares type variable N but does not use it.
foo (generic function with 1 method)

It is being used, as can be seen by these two executions of the function

julia> foo(a=[1.0])
0.0

julia> foo(a=[1])
0

If I do something similar without nesting the type, it works fine with no warning

julia> bar(;a::N) where {N} = zero(N)
bar (generic function with 1 methods)

Ran on 1.8.5 and latest 1.9 RC

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 4 virtual cores
julia> versioninfo()
Julia Version 1.9.0-rc2
Commit 72aec423c2a (2023-04-01 10:41 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 1 on 4 virtual cores
Environment:
  JULIA_IMAGE_THREADS = 1
@vtjnash
Copy link
Member

vtjnash commented Apr 6, 2023

It seems to be an issue with the way lowering decided if a variable gets used (not checking recursively). If we try some other combinations, we can see it handles it correctly if it is entirely unused:

julia> foo(;a::N,b::N) where {M, N, T<:AbstractVector{N}} = zero(N)
WARNING: method definition for #foo#11 at REPL[12]:1 declares type variable T but does not use it.
WARNING: method definition for #foo#11 at REPL[12]:1 declares type variable M but does not use it.
WARNING: method definition for foo at REPL[12]:1 declares type variable N but does not use it.
WARNING: method definition for foo at REPL[12]:1 declares type variable N but does not use it.
foo (generic function with 1 method)

@fredrikekre
Copy link
Member

This issue seem to apply also to optional positional arguments, not just keyword arguments:

julia> f(a::T = Int[]) where {N, T <: AbstractVector{N}} = zero(N)
WARNING: method definition for f at REPL[1]:1 declares type variable N but does not use it.
f (generic function with 2 methods)

@eford
Copy link

eford commented Jun 30, 2023

FWIW, I also encountered this issue.

@c42f
Copy link
Member

c42f commented Nov 22, 2024

This issue seem to apply also to optional positional arguments

I just noticed this bug while porting the code to JuliaLowering.jl and set out to prove it ... and landed here :)

This is fixed in the JuliaLowering.jl implementation - the fix, conceptually, is to traverse the graph of symbolic dependencies between type variables, only picking up type variables which are used directly in the function arguments, or transitive dependencies of such.

The broken flisp lowering code for default args case is here:

(define (filter-sparams expr sparams)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

No branches or pull requests

5 participants