Skip to content

Fix combining interfaces #29

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

Merged
merged 3 commits into from
Feb 28, 2025
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 <[email protected]> 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)

Check warning on line 9 in src/abstractinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterface.jl#L9

Added line #L9 was not covered by tests

# 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(

Check warning on line 13 in src/abstractinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterface.jl#L13

Added line #L13 was not covered by tests
inter1::AbstractInterface, inter2::AbstractInterface, inter_rest::AbstractInterface...
)
return combine_interfaces(combine_interface_rule(inter1, inter2), inter_rest...)

Check warning on line 16 in src/abstractinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterface.jl#L16

Added line #L16 was not covered by tests
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

Check warning on line 21 in src/abstractinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterface.jl#L21

Added line #L21 was not covered by tests

# 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.")

Check warning on line 31 in src/abstractinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterface.jl#L30-L31

Added lines #L30 - L31 were not covered by tests
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
Loading