Skip to content

Commit

Permalink
fix: add lineinfo to compact (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Nov 17, 2024
1 parent 2331c99 commit dab3916
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lux"
uuid = "b2108857-7c20-44ae-9111-449ecde12c47"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "1.3.2"
version = "1.3.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
18 changes: 12 additions & 6 deletions src/helpers/compact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ used inside a `Chain`.
account for the total number of parameters printed at the bottom.
"""
macro compact(_exs...)
return CompactMacroImpl.compact_macro_impl(_exs...)
return CompactMacroImpl.compact_macro_impl(__source__, __module__, _exs...)
end

"""
Expand Down Expand Up @@ -434,7 +434,7 @@ using LuxCore: LuxCore, AbstractLuxLayer
using ..Lux: Lux, CompactLuxLayer, LuxCompactModelParsingException, StatefulLuxLayer,
safe_getproperty

function compact_macro_impl(_exs...)
function compact_macro_impl(__source__, __module__, _exs...)
# check inputs, extracting function expression fex and unprocessed keyword arguments _kwexs
if isempty(_exs)
msg = "expects at least two expressions: a function and at least one keyword"
Expand Down Expand Up @@ -499,15 +499,16 @@ function compact_macro_impl(_exs...)

# edit expressions
vars = map(first Base.Fix2(getproperty, :args), kwexs)
fex = supportself(fex, vars, splatted_kwargs)
fex = supportself(fex, vars, splatted_kwargs, __source__)

# assemble
return esc(:($CompactLuxLayer(
$(static)($(dispatch)), $fex, $name, ($layer, $input, $block),
(($(Meta.quot.(splatted_kwargs)...),), ($(splatted_kwargs...),)); $(kwexs...))))
$(static)($(dispatch)), $(fex), $(name), ($layer, $input, $block),
(($(Meta.quot.(splatted_kwargs)...),), ($(splatted_kwargs...),)); $(kwexs...))
))
end

function supportself(fex::Expr, vars, splatted_kwargs)
function supportself(fex::Expr, vars, splatted_kwargs, __source__)
@gensym self ps st curried_f res
# To avoid having to manipulate fex's arguments and body explicitly, we split the input
# function body and add the required arguments to the function definition.
Expand Down Expand Up @@ -562,6 +563,11 @@ function supportself(fex::Expr, vars, splatted_kwargs)
else
modified_body = flattened_expr
end

modified_body = MacroTools.to_line(
__source__, MacroTools.to_flag(modified_body)
)

sdef[:body] = Expr(:let, Expr(:block, calls...), modified_body)
sdef[:args] = args
return combinedef(sdef)
Expand Down

2 comments on commit dab3916

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/119643

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.3 -m "<description of version>" dab3916a3804d56c3fb4829fb78e9d541b4f99f7
git push origin v1.3.3

Please sign in to comment.