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

fix partially_inline! with isdefined #40628

Merged
merged 3 commits into from
Jul 1, 2021
Merged

Conversation

simeonschaub
Copy link
Member

@vtjnash
Copy link
Member

vtjnash commented Apr 27, 2021

This is still not fully correct (since it first generates invalid IR, then tries to fix cases it can detect as such), but I think it may be valid for any cases that dynamically reach here?

@vtjnash vtjnash requested review from JeffBezanson and Keno and removed request for JeffBezanson April 27, 2021 14:45
@simeonschaub
Copy link
Member Author

We could assert that the isdefined expression contains one of either a slot number, global ref, symbol or static parameter before we do the replacements, but that means the IR was already invalid before. If the original IR and replacements are valid, I don't see any way this would produce anything invalid.

@vtjnash
Copy link
Member

vtjnash commented Apr 27, 2021

Typically if there is a replacement made (unless it is a renumbering), that implies that the value was defined, which is what generally makes this valid dynamically. But it might therefore depend on the given semantics of the inlining.

@simeonschaub
Copy link
Member Author

Ah, I see what you mean. I can't really think of any examples where this wouldn't be the case. The only packages using this function directly seem to be Cassette and IRTools (https://juliahub.com/ui/CodeSearch?q=partially_inline%21&u=all&t=all), so this is probably fine.

@JeffBezanson
Copy link
Member

Just as a matter of style, I think it would be better to implement this by adding a case for isdefined expressions just like all other forms that need to be handled. That might seem like it repeats some logic for SlotNumber, but overall I think it's a better structure.

end
end
return Expr(:isdefined, Core.SlotNumber(id + slot_offset))
elseif isexpr(arg, :static_parameter)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if applicable

julia> f() where T = @isdefined(T)
f (generic function with 1 method)

julia> f()
false
julia> @code_typed f()
CodeInfo(
1 ─ %1 = $(Expr(:isdefined, :($(Expr(:static_parameter, 1)))))::Bool
└──      return %1
) => Bool

So you can have a not defined static_parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, but for partially_inline! to work, you would still need to provide a value for the static parameter. Perhaps we should allow the sparam replacements to have undefined entries and only replace with true if the replacement is defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this look good to you?

Copy link
Member

Choose a reason for hiding this comment

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

We typically use TypeVars to indicate an unknown static parameter, but this function doesn't seem to support that (yet) so we can leave that for now, and this looks good.

@simeonschaub
Copy link
Member Author

Bump.

@simeonschaub
Copy link
Member Author

Friendly bump :)

@JeffBezanson JeffBezanson reopened this Jul 1, 2021
@JeffBezanson
Copy link
Member

Needs rebase

@simeonschaub simeonschaub merged commit 10b010f into master Jul 1, 2021
@simeonschaub simeonschaub deleted the sds/inline_isdefined branch July 1, 2021 23:59
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
KristofferC pushed a commit that referenced this pull request Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants