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

Include macro for building sysimgs #85

Merged
merged 4 commits into from
Sep 28, 2020
Merged

Include macro for building sysimgs #85

merged 4 commits into from
Sep 28, 2020

Conversation

MikeInnes
Copy link
Collaborator

This PR adds an @include macro which behaves like include, but is more compatible with compiling a sysimg.

Separately, it also adds a hook to replace include statements in @require block with @include. This risks being a bit magical but shouldn't affect normal usage at all, only sysimg usage. The main edge case is recursive include during sysimg compilation (e.g. file included by Requires has another include in it). Since this is pretty uncommon, it should make most Requires usage just work with sysimg building.

@MikeInnes
Copy link
Collaborator Author

Forgot that var"..." won't work on 1.0, but we can fix that if we're happy to merge this.

@MikeInnes
Copy link
Collaborator Author

Second commit runs macros inside @require at load time, rather than when the required package is loaded. Otherwise @include was effectively the same as include. I don't think this should have adverse affects for other macros, and might even be useful in cases similar to this one.

Third commit fixes the 1.0 issue.

@timholy
Copy link
Member

timholy commented Jun 25, 2020

Mostly this needs a test, otherwise looks good.

@ViralBShah
Copy link
Member

Bump. We should get this tagged and released.

@andreasnoack
Copy link

Mostly this needs a test

Won't this code get exercised by the existing tests because of the rewrite part? Any idea of how to tests the part that helps system image building?

@ViralBShah
Copy link
Member

Maybe if it works, let's get it merged?

@andreasnoack
Copy link

@timholy Could you provide a hint to the kind of testing that would be useful here. If any. I can try to write such tests but I haven't done any work here before so I'd need some directions.

@timholy
Copy link
Member

timholy commented Sep 15, 2020

I'm not exactly sure what the use-case really is here, but looking again it seems the existing tests already cover this. Sorry for the confusion. This will break Revise, but it should be fixable.

@andreasnoack
Copy link

Currently, things like https://github.com/FluxML/Zygote.jl/blob/ed366f32c0f520567526040d9f8acaf0d83613c3/src/Zygote.jl#L42-L43 aren't compatible with creating system images since the included file might not be available when using the system image. This PR is an attempt to make such usage compatible with system image building.

@timholy
Copy link
Member

timholy commented Sep 15, 2020

I see. And one cannot just use Base.include_dependency?

@KristofferC
Copy link
Member

KristofferC commented Sep 15, 2020

Base.include_dependency will cause the module to recompile if the file is changed but I don't see how that helps. The content of the file is still not serialized to the .ji file (or the sysimage), right? When we create a sysimage and send it to another machine, the only code we have available is that which got serialized, if there is an external file that is included at runtime, it will not be found. This PR causes the source of that file to be included in the serialization and can be executed whenever.

@timholy
Copy link
Member

timholy commented Sep 15, 2020

Sounds good. I guess I was wondering if we could keep it separate from the source code proper. If the file is quite long then this is a big string. But I guess this isn't a huge deal, and if people are worried about that then they should just make it using GluePkg instead.

@andreasnoack
Copy link

@timholy I think you are the only one here that can merge the PR and make the release.

@timholy
Copy link
Member

timholy commented Sep 15, 2020

That said, if there's a way to do this conditionally on building a sysimg, Revise will thank you. (Currently, @require Pkg=uuid include("extrafile.jl") adds extrafile.jl to the list of files tracked by Revise, and you can edit it and get updates. This will break that. I just spent a day and a half improving Revise's performance in this situation.)

Is there a way to detect that you're buidling a sysimg and not just ordinary precompiling? For example, could Requires define const building_sysimg = Ref(false) and then PkgCompiler does using Requires; building_sysimg[] = true?

@timholy
Copy link
Member

timholy commented Sep 15, 2020

Oh, that's crazy. I just added @KristofferC and @DilumAluthge. Any others I should invite?

@ViralBShah
Copy link
Member

I have the permissions to merge.

@timholy
Copy link
Member

timholy commented Sep 15, 2020

OK, but let's see if anyone is willing to tackle #85 (comment).

@KristofferC
Copy link
Member

How about we fall back to the serialized string in case the file doesn't exist anymore but otherwise use the current mechanism?

@andreasnoack
Copy link

@KristofferC Would you be able to add a commit with that proposal?

@KristofferC
Copy link
Member

Yeah, I'll try.

@c42f
Copy link
Contributor

c42f commented Sep 25, 2020

I went ahead and implemented the approach suggested by @KristofferC in #85 (comment).

See #92

I also added a test to cover the new behavior.

This reverts to using the normal include() mechanism in @-require, and
only falling back to the macro expansion-time include_string if the file
doesn't exist at runtime.
@timholy
Copy link
Member

timholy commented Sep 25, 2020

Superseded by #92

@timholy timholy closed this Sep 25, 2020
@c42f
Copy link
Contributor

c42f commented Sep 25, 2020

@timholy I made #92 against this branch, so you'll also need to merge this PR. Sorry for the confusion!

@KristofferC KristofferC reopened this Sep 28, 2020
@timholy timholy merged commit 787625d into master Sep 28, 2020
@timholy timholy deleted the replace-include branch September 28, 2020 22:19
@timholy
Copy link
Member

timholy commented Oct 4, 2020

Hmm, this still seems to have broken Revise on Windows. Can others see https://ci.appveyor.com/project/timholy/revise-jl/history? Ignoring nightly (which was broken for other reasons), between "Document Revise's latency costs" and "revise should throw when throw=true" the only thing that seems like it could be related is the switch from Requires 1.0.3 to 1.1.0.

EDIT: not just Windows, it turns out I was still using Requires 1.0.3 locally. See https://travis-ci.org/github/timholy/Revise.jl/builds/732701350. I don't have time to dig into this right now myself, and won't for several days, so I'd appreciate help.

@timholy
Copy link
Member

timholy commented Oct 5, 2020

Filed as a separate bug report, see #94.

KristofferC pushed a commit that referenced this pull request Oct 28, 2021
This reverts to using the normal include() mechanism in @-require, and
only falling back to the macro expansion-time include_string if the file
doesn't exist at runtime.

Co-authored-by: Chris Foster <[email protected]>
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.

6 participants