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

traced loop conflicts: Better error message #1038

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Reactant"
uuid = "3c362404-f566-11ee-1572-e11a4b42c853"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>", "Sergio Sánchez Ramírez <[email protected]>", "Paul Berg <[email protected]>", "Avik Pal <[email protected]>", "Mosè Giordano <[email protected]>"]
version = "0.2.54"
version = "0.2.55"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down Expand Up @@ -85,7 +85,7 @@ Preferences = "1.4"
PythonCall = "0.9"
Random = "1.10"
Random123 = "1.7"
ReactantCore = "0.1.7"
ReactantCore = "0.1.8"
Reactant_jll = "0.0.101"
Scratch = "1.2"
Sockets = "1.10"
Expand Down
2 changes: 1 addition & 1 deletion lib/ReactantCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ReactantCore"
uuid = "a3311ec8-5e00-46d5-b541-4f83e724a433"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>", "Sergio Sánchez Ramírez <[email protected]>", "Paul Berg <[email protected]>", "Avik Pal <[email protected]>"]
version = "0.1.7"
version = "0.1.8"

[deps]
ExpressionExplorer = "21656369-7473-754a-2065-74616d696c43"
Expand Down
1 change: 0 additions & 1 deletion src/ControlFlow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ end
function ReactantCore.traced_while(
cond_fn::CFn, body_fn::BFn, args; track_numbers=Number, verify_arg_names=nothing
) where {CFn,BFn}
@warn verify_arg_names
return Ops.while_loop(cond_fn, body_fn, args...; track_numbers, verify_arg_names)
end
25 changes: 21 additions & 4 deletions src/TracedUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,32 @@ function make_mlir_fn(
append!(linear_results, linear_args[mutated_args])
end
if !isnothing(verify_arg_names) && typeof.(linear_args) != typeof.(linear_results)
@assert length(linear_args) <= length(linear_results)
argis = first.(get_argidx.(linear_args))
resis = Set(getindex.(get_residx.(linear_results), Ref(2)))
@assert length(linear_args) <= length(linear_results) "Expected to have missing traced arguments, but it seems like results are missing."
argis = map(get_argidx.(linear_args)) do (_, path)
path[2:end]
end
resis = Set(map(get_residx.(linear_results)) do path
path[2:end]
end)
Comment on lines +356 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
resis = Set(map(get_residx.(linear_results)) do path
path[2:end]
end)
resis = Set(
map(get_residx.(linear_results)) do path
path[2:end]
end,
)

# this can be more efficient
conflicts = setdiff(resis, argis)
if isempty(conflicts)
Core.println("linear_args: $linear_args")
Core.println("linear_results: $linear_results")
end
@assert !isempty(conflicts) "Expected to have some conflicts, but none were found."

conflicts = collect(conflicts)
diagnostics = map(conflicts) do conflict
i = first(conflict)
remaining_path = conflict[2:end]
name = verify_arg_names.args[i]
"$name -> [$(join(remaining_path, ", "))]"
end

error("""Types do not match between function arguments and results.
The following arguments should be traced: $(join(verify_arg_names.args[collect(conflicts)], ", "))
The following arguments should be traced:
$(join(diagnostics, "\n"))
""")
end

Expand Down
Loading