Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DerivableInterfaces"
uuid = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.3.15"
version = "0.3.16"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
32 changes: 19 additions & 13 deletions src/abstractinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
interface(x) = interface(typeof(x))
# TODO: Define as `DefaultInterface()`.
interface(::Type) = error("Interface unknown.")
interface(x1, x_rest...) = combine_interfaces(x1, x_rest...)
interface(x1, x_rest...) = combine_interfaces(interface(x1), interface.(x_rest)...)

abstract type AbstractInterface end

(interface::AbstractInterface)(f) = InterfaceFunction(interface, f)

# Adapted from `Base.Broadcast.combine_styles`.
# Get the combined interfaces of the input objects.
function combine_interfaces(x1, x2, x_rest...)
return combine_interfaces(combine_interfaces(x1, x2), x_rest...)
function combine_interfaces(
inter1::AbstractInterface, inter2::AbstractInterface, inter_rest::AbstractInterface...
)
return combine_interfaces(combine_interface_rule(inter1, inter2), inter_rest...)
end
function combine_interfaces(inter1::AbstractInterface, inter2::AbstractInterface)
return combine_interface_rule(inter1, inter2)
end
combine_interfaces(x1, x2) = combine_interface_rule(interface(x1), interface(x2))
combine_interfaces(x) = interface(x)
combine_interfaces(inter::AbstractInterface) = inter

# Rules for combining interfaces.
function combine_interface_rule(
interface1::Interface, interface2::Interface
) where {Interface}
return interface1
inter1::Interface, inter2::Interface
) where {Interface<:AbstractInterface}
return inter1
end
# TODO: Define as `UnknownInterface()`.
combine_interface_rule(interface1, interface2) = error("No rule for combining interfaces.")

abstract type AbstractInterface end

(interface::AbstractInterface)(f) = InterfaceFunction(interface, f)
function combine_interface_rule(inter1::AbstractInterface, inter2::AbstractInterface)
return error("No rule for combining interfaces.")
end
4 changes: 1 addition & 3 deletions src/derive_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ function derive_func_from_types(types::Expr, func::Expr)
end
return argname(i)
end
interface = globalref_derive(
:(DerivableInterfaces.combine_interfaces($(active_argnames...)))
)
interface = globalref_derive(:(DerivableInterfaces.interface($(active_argnames...))))
return derive_interface_func(interface, new_func)
end

Expand Down