From ba26e82d38e287511d97444d8fa31ff50f6e6319 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 12 Feb 2022 01:58:52 -0500 Subject: [PATCH 1/2] Use opaque closure for tasks --- base/task.jl | 7 +++++-- base/threadingconstructs.jl | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base/task.jl b/base/task.jl index 90dea508383b1..a7d1288fe6eb8 100644 --- a/base/task.jl +++ b/base/task.jl @@ -131,7 +131,9 @@ true ``` """ macro task(ex) - :(Task(()->$(esc(ex)))) + # Avoid using `@opaque` to make bootstrap easier + thunk = esc(Expr(:opaque_closure, :(()->($ex)))) + :(Task($thunk)) end """ @@ -473,7 +475,8 @@ isolating the asynchronous code from changes to the variable's value in the curr macro async(expr) letargs = Base._lift_one_interp!(expr) - thunk = esc(:(()->($expr))) + # Avoid using `@opaque` to make bootstrap easier + thunk = esc(Expr(:opaque_closure, :(()->($expr)))) var = esc(sync_varname) quote let $(letargs...) diff --git a/base/threadingconstructs.jl b/base/threadingconstructs.jl index 9ed416caec2a6..4412bbf922585 100644 --- a/base/threadingconstructs.jl +++ b/base/threadingconstructs.jl @@ -223,7 +223,8 @@ isolating the asynchronous code from changes to the variable's value in the curr macro spawn(expr) letargs = Base._lift_one_interp!(expr) - thunk = esc(:(()->($expr))) + # Avoid using `@opaque` to make bootstrap easier + thunk = esc(Expr(:opaque_closure, :(()->($expr)))) var = esc(Base.sync_varname) quote let $(letargs...) From d30e90afc7f9ef0a65d29b162d185c013d5f3071 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 17 Feb 2022 05:19:45 -0500 Subject: [PATCH 2/2] Trying to fix invalid globals in codegen --- src/cgutils.cpp | 1 + src/codegen.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index b219498315905..9963f784c8194 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -221,6 +221,7 @@ static Value *julia_pgv(jl_codectx_t &ctx, const char *cname, void *addr) if (gv->getParent() != M) gv = cast_or_null(M->getNamedValue(localname)); } + assert(localname != ""); if (gv == nullptr) gv = new GlobalVariable(*M, ctx.types().T_pjlvalue, false, GlobalVariable::PrivateLinkage, diff --git a/src/codegen.cpp b/src/codegen.cpp index 60dc7ede6af5a..cb54d2a1a3e95 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7735,9 +7735,30 @@ static std::pair, jl_llvm_functions_t> for (const auto &F: Mod->functions()) if (!F.isDeclaration()) Exports.push_back(F.getName().str()); + SmallVector> Globals; + for (auto pair : ctx.global_targets) + if (pair.second->getParent() == &*Mod) + Globals.push_back({std::string(pair.second->getName()), pair.second}); jl_merge_module(jl_Module, std::move(Mod)); for (auto FN: Exports) jl_Module->getFunction(FN)->setLinkage(GlobalVariable::InternalLinkage); + // Remove or refresh globals defined in `Mod` + auto &globals = ctx.global_targets; + for (auto it = globals.begin(); it != globals.end();) { + bool remove = false; + for (auto pair: Globals) + if (pair.second == it->second) { + if (auto G = jl_Module->getNamedValue(pair.first)) + it->second = cast(G); + else + remove = true; + break; + } + if (remove) + it = globals.erase(it); + else + ++it; + } } JL_GC_POP();