Skip to content

v2 API: Redefining an input with a new type? #22

@ghost

Description

What should happen if you re-declare a salsa input with a new type? Currently, it succeeds, and the old setter remains, but the getter is replaced, so setting and getting the old type throws an error during the getter:

julia> @declare_input x(rt)::Int
(x, set_x!, delete_x!)

julia> @declare_input x(rt)::Vector{Int}
(x, set_x!, delete_x!)

julia> rt = Runtime()
Salsa.Runtime(Salsa.DefaultStorage(0, ...))

julia> set_x!(rt, 2)

julia> set_x!(rt, Int[])

julia> x(rt)
0-element Array{Int64,1}

julia> set_x!(rt, 2)

julia> x(rt)
ERROR: TypeError: in typeassert, expected Array{Int64,1}, got Int64
Stacktrace:
 [1] x(::Salsa._TopLevelRuntime{Salsa.EmptyContext,Salsa._DefaultSalsaStorage.DefaultStorage}) at /Users/nathandaly/.julia/dev/Salsa/src/Salsa.jl:769
 [2] top-level scope at REPL[51]:1

julia> 

What should this do? If you declare a new input with a different signature, that's fine. But if it has the same signature with different output type? What should that do?

  • Throw an error when declaring x with a new type?
  • Automatically erase the old setter method for x? (And maybe print a warning, just like redefining a method throws a warning in julia? -- though i guess we'll already get the warnings automatically from julia if this is done in a module, so maybe no need for the warning...)

I think I'm leaning towards automatically, silently, erasing the old setter method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions