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

feat: runtime linking #300

Merged
merged 10 commits into from
Mar 9, 2021
Merged

Conversation

baszalmstra
Copy link
Collaborator

@baszalmstra baszalmstra commented Jan 16, 2021

This PR adds the possibility to use multiple Mun files from a compiler and runtime perspective.

It adds the concept of a ModuleGroup. This is a struct that contains a grouping of modules that should be compiled together into an assembly. It provides some useful functions with respect to querying which functions should be included in the dispatch table or be exported from the assembly for external consumption or by another assembly. A ModuleGroup can be constructed from a single module or a set of modules. The ModuleGroup also defines a name. From the name a relative path is derived. Instead of iterating over the functions and structs of a single module, we iterate over the definitions from all modules.

Furthermore, all type and function names that are exported now have their module path prepended to them. So a function hello_world in foo.mun is exported as foo::hello_world. The same goes for structs.

The CodeGenDatabase contains a new query: module_partition. This returns a ModulePartition which is a grouping of groupings. Currently, the implementation creates a ModuleGroup for every individual module. The Driver uses this information to compile to correct ModuleGroups. It also allows the code to query to which ModuleGroup a specific hir::Function belongs. This allows us to correctly determine references from one ModuleGroup to other groups. During symbol generation this information is stored in the assembly. A dependency is stored as the relative path of the referenced ModuleGroup without an extension.

What's currently missing from this PR is:

  • Dependencies are not yet added to the assembly. This requires knowledge about the name of the ModuleGroup that contains a Module that is being referenced.
  • We are still missing tests in the codegen for a multifile project.
  • The runtime is not actually loading dependencies yet. Running a munlib that refers to a function from another module will always result in a linker error like: Failed to link: function foo::fibonacci is missing.

Lots of tests changed!?

Yes, this is due to two reasons:

  • Previously the logic for adding functions to the dispatch table was incorrect. This added more functions than were really required. All of this logic is now handled by the ModuleGroup.
  • Since we can now group modules together, the name of an LLVM module changed this changed almost all snapshots for the code generation.

@codecov
Copy link

codecov bot commented Jan 16, 2021

Codecov Report

Merging #300 (328392e) into master (4ca2f58) will decrease coverage by 0.00%.
The diff coverage is 83.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #300      +/-   ##
==========================================
- Coverage   80.89%   80.89%   -0.01%     
==========================================
  Files         242      244       +2     
  Lines       14689    14952     +263     
==========================================
+ Hits        11883    12095     +212     
- Misses       2806     2857      +51     
Impacted Files Coverage Δ
crates/mun/src/ops/start.rs 0.00% <ø> (ø)
crates/mun_codegen/src/code_gen.rs 100.00% <ø> (ø)
crates/mun_codegen/src/ir.rs 43.24% <ø> (ø)
crates/mun_compiler/src/driver/display_color.rs 83.33% <ø> (ø)
crates/mun_hir/src/arena.rs 78.43% <0.00%> (-6.68%) ⬇️
crates/mun_hir/src/expr/validator/tests.rs 100.00% <ø> (ø)
crates/mun_hir/src/ids.rs 82.35% <ø> (ø)
crates/mun_hir/src/item_tree/tests.rs 93.54% <ø> (ø)
crates/mun_hir/src/module_tree.rs 86.73% <ø> (ø)
crates/mun_hir/src/package_defs/tests.rs 86.58% <ø> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ca2f58...8d65f0c. Read the comment docs.

@baszalmstra baszalmstra self-assigned this Jan 16, 2021
@baszalmstra baszalmstra added the type: feat New feature or request label Jan 16, 2021
@Wodann Wodann force-pushed the feat/runtime_linking branch 2 times, most recently from 41cac2e to 63db093 Compare March 7, 2021 16:51
@Wodann Wodann marked this pull request as ready for review March 7, 2021 16:52
@Wodann Wodann force-pushed the feat/runtime_linking branch 2 times, most recently from beb0f2d to e461867 Compare March 7, 2021 19:32
crates/mun_codegen/src/ir/dispatch_table.rs Show resolved Hide resolved
crates/mun_codegen/src/ir/dispatch_table.rs Outdated Show resolved Hide resolved
crates/mun_codegen/src/ir/type_table.rs Outdated Show resolved Hide resolved
crates/mun_codegen/src/module_group.rs Outdated Show resolved Hide resolved
crates/mun_codegen/src/module_group.rs Outdated Show resolved Hide resolved
crates/mun_codegen/src/module_group.rs Outdated Show resolved Hide resolved
crates/mun_codegen/src/module_partition.rs Outdated Show resolved Hide resolved
@Wodann Wodann force-pushed the feat/runtime_linking branch 3 times, most recently from 10ef2ff to 57954ec Compare March 7, 2021 21:11
@Wodann Wodann changed the title feature: runtime linking feat: runtime linking Mar 9, 2021
@Wodann Wodann merged commit 1663f99 into mun-lang:master Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants