-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Claro's Dep Module Monomorphization Codegen Strategy
This addresses an extremely subtle bug in the previous approach. To summarize, previously dep module monomorphization codegen was placed in an "extra" top-level class, always named $DepModuleMonomorphization. This was intended to ensure that transitive calls from dep module generic procs would naturally produce codegen that was applicable in whichever file it's codegen appeared in. This had the unintended side-effect, however, of having the class generated by different modules conflicting. The underlying java_libary() and java_binary() rule implementations ended up "deduplicating" the $DepModuleMonomorphization classes and while compilation would succeed, interestingly, at runtime the deploy Jar's $DepModuleMonomorphization class would just include some (not quite) random subset of the programs overall monomorphizations, and so there would actually be surprising java.lang.NoSuchFieldError's thrown at runtime when trying to call those procedures. Very interesting! But very problematic. This new approach leverages knowledge of this esoteric behavior to solve the runtime error issues. Now, monomorphizations are no longer wrapped in an intermediary $DepModuleMonomorphizations class, and instead each monomorphization is generated inside its own custom class named `$MONOMORPHIZATION$<defining module unique name>$<hashed monomorphization name>`. This results in the final deploy jar containing a single class for each monomorphization needed in the entire program actually leveraging this Jar level class deduplication for my advantage such that each compilation unit can just codegen as necessary and the final Jar won't have any duplicates. The following CL(s) will further leverage (abuse) this knowledge to actually start including the set of monomorphizations produced by the dependency sub-graph beneath each .claro_module so that any of its deps can actually completely skip codegen on any monomorphizations that any of it's direct or transitive dependencies have already generated.
- Loading branch information
1 parent
caf73bd
commit ca46f48
Showing
15 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
examples/claro_programs/module_system/dep_module_monomorphization_test/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
load("//:rules.bzl", "claro_module", "claro_binary") | ||
|
||
# TODO(steving) TESTING!!! Currently due to the way that Bazel has implemented the builtin java_library() and | ||
# TODO(steving) java_binary() rules, Claro's use of a common "extra" top-level `$DepModuleMonomorphizations` | ||
# TODO(steving) non-public class in every module that calls generic procedures from its deps is broken as | ||
# TODO(steving) the *_deploy.jar finally produced by the top-level java_binary() will actually dedupe the | ||
# TODO(steving) `$DepModuleMonomorphizations` class from each of the java_library()'s below it and only accept | ||
# TODO(steving) the last one generated. | ||
# TODO(steving) While this is currently causing a bug in the functionality of monomorphization, this actually | ||
# TODO(steving) represents a big code-size optimization opportunity. If each .claro_module can encode the complete set | ||
# TODO(steving) of monomorphizations that it generated in its $DepModuleMonomorphization class (which is still | ||
# TODO(steving) necessary for it's corresponding java_library() target to successfully build), then all of that | ||
# TODO(steving) codegen can be blindly copied into any consuming Claro targets that depend on it. This will have a | ||
# TODO(steving) two-fold optimization improvement. First, it will potentially allow downstream consumer targets to | ||
# TODO(steving) actually completely skip dep module monomorphizations that it happened to already recieve from its | ||
# TODO(steving) deps which should have the potential to improve compile times! Second, it will result in all of the | ||
# TODO(steving) duplicated $DepModuleMonomorphization classes generated below the root claro_binary() node to get | ||
# TODO(steving) completely overwritten by the single class at the root of the dep graph that will have accumulated ALL | ||
# TODO(steving) of the monomorphizations necessary for the entire program! | ||
claro_binary( | ||
name = "top", | ||
main_file = "top.claro", | ||
deps = { | ||
"Bottom": ":bottom", | ||
"MidA": ":MidA", | ||
"MidB": ":MidB", | ||
} | ||
) | ||
|
||
claro_module( | ||
name = "MidA", | ||
module_api_file = "MidA.claro_module_api", | ||
srcs = ["MidA.claro"], | ||
deps = { | ||
"Bottom": ":bottom", | ||
}, | ||
) | ||
|
||
claro_module( | ||
name = "MidB", | ||
module_api_file = "MidB.claro_module_api", | ||
srcs = ["MidB.claro"], | ||
deps = { | ||
"Bottom": ":bottom", | ||
}, | ||
) | ||
|
||
claro_module( | ||
name = "bottom", | ||
module_api_file = "bottom.claro_module_api", | ||
srcs = ["bottom.claro"], | ||
) |
5 changes: 5 additions & 0 deletions
5
examples/claro_programs/module_system/dep_module_monomorphization_test/MidA.claro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
function asList(a: string, b: int) -> [oneof<string, int>] { | ||
return Bottom::asList(a,b); | ||
} | ||
print(Bottom::asList(1, "one")); |
2 changes: 2 additions & 0 deletions
2
examples/claro_programs/module_system/dep_module_monomorphization_test/MidA.claro_module_api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
function asList(a: string, b: int) -> [oneof<string, int>]; |
5 changes: 5 additions & 0 deletions
5
examples/claro_programs/module_system/dep_module_monomorphization_test/MidB.claro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
function asList(a: string, b: float) -> [oneof<string, float>] { | ||
return Bottom::asList(a,b); | ||
} | ||
print(Bottom::asList(1, "one")); |
2 changes: 2 additions & 0 deletions
2
examples/claro_programs/module_system/dep_module_monomorphization_test/MidB.claro_module_api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
function asList(a: string, b: float) -> [oneof<string, float>]; |
4 changes: 4 additions & 0 deletions
4
examples/claro_programs/module_system/dep_module_monomorphization_test/bottom.claro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
function asList<A,B>(a: A, b: B) -> [oneof<A,B>] { | ||
return [a, b]; | ||
} |
2 changes: 2 additions & 0 deletions
2
...les/claro_programs/module_system/dep_module_monomorphization_test/bottom.claro_module_api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
function asList<A,B>(a: A, b: B) -> [oneof<A,B>]; |
4 changes: 4 additions & 0 deletions
4
examples/claro_programs/module_system/dep_module_monomorphization_test/top.claro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
print(Bottom::asList(1, "one")); | ||
print(MidA::asList("two", 2)); | ||
print(MidB::asList("two", 2.0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters