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

Introduce the basic skeleton for the compiler #74

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

iamrecursion
Copy link
Collaborator

@iamrecursion iamrecursion commented Oct 18, 2024

Summary

This PR consists of two commits:

  1. The first commit implements the skeleton of a pass infrastructure that is intentionally incomplete. This skeleton exists to avoid us painting ourselves into a corner when it comes to actually implement pass management later (Implement a Rust Pass Manager #56).
  2. The second commit implements the module mapping pass. This pass is responsible for discovering top-level information about the module to enable consistency checking during compilation. It comes with an implementation of the parts of the LLVM type system we care about, as well as a parser for DataLayout strings as Inkwell exposes no such facility to rust.

Details

The code is functional, if under-tested at the moment. This is intentional as the missing tests are likely to undergo significant change in the future and it is not worth the churn.

Please pay attention to:

  • Whether the code is structured cleanly and is easy to understand.
  • Whether the documentation answers all of the questions you might have about the APIs that have been introduced.

In terms of how to review, I would honestly start from lib.rs and step through each of the modules. They should be relatively self-contained with good boundaries.

Checklist

  • Code is formatted by Rustfmt.
  • Documentation has been updated if necessary.

@iamrecursion iamrecursion added the enhancement New feature or request label Oct 18, 2024
@iamrecursion iamrecursion self-assigned this Oct 18, 2024
@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch from e669323 to cda996d Compare October 18, 2024 22:06
@iamrecursion iamrecursion marked this pull request as ready for review October 18, 2024 22:24
@iamrecursion iamrecursion requested a review from a team as a code owner October 18, 2024 22:24
@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch from cda996d to 03556a2 Compare October 18, 2024 22:25
wzmuda added a commit that referenced this pull request Oct 21, 2024
Most of the LLVM IR instructions come in the form of just an opcode
followed by operands, but some introduce an extra `to` keyword, e.g.
`zext` is called as follows:

```llvm
%X = zext i32 257 to i64
```

As discussed in the compiler skeleton PR[1], this naming duality make
the instructions-to-polyfills mapping more complex without adding any
benefits. Remove the `to` keyword from polyfill names. Affected
instructions: trunc, zext, sext, ptrtoint, inttoptr, bitcast.

--

[1] #74 (comment)

Signed-off-by: Wojciech Zmuda <zmuda.w@gmail.com>
wzmuda added a commit that referenced this pull request Oct 21, 2024
Most of the LLVM IR instructions come in the form of just an opcode
followed by operands, but some introduce an extra `to` keyword, e.g.
`zext` is called as follows:

```llvm
%X = zext i32 257 to i64
```

As discussed in the compiler skeleton PR[1], this naming duality make
the instructions-to-polyfills mapping more complex without adding any
benefits. Remove the `to` keyword from polyfill names. Affected
instructions: trunc, zext, sext, ptrtoint, inttoptr, bitcast.

--

[1] #74 (comment)

Signed-off-by: Wojciech Zmuda <zmuda.w@gmail.com>
@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch from e1112ab to 4fb9092 Compare October 21, 2024 21:17
Copy link
Contributor

@wzmuda wzmuda left a comment

Choose a reason for hiding this comment

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

Phew, I went through everything! There's a few open comments so I'm not acking just yet, but overall it looks amazing. I'm especially grateful for these detailed comments, they were enormously helpful.

@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch 2 times, most recently from 59c88ab to 785a1a2 Compare October 22, 2024 22:04
Copy link
Collaborator

@ktemkin ktemkin left a comment

Choose a reason for hiding this comment

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

Beyond being +4179, this looks excellent.

You asked for nitpicks, so I've provided them~. Feel free to disregard the nitpicking in the name of expediency and/or because the nitpicks are Wild (TM).

While it is incomplete, an initial skeleton for the pass management
infrastructure ensures that we do not paint ourselves into any corners
that might be hard to design our way out of later. It provides the
infrastructure for creating and managing passes, as well as shuffling
pass data between passes.

Please note that this we make use of self-referential structs via
Ouroboros to better encapsulate the LLVM context and the modules that
exist in it.

Added `libffi` and `libxml2` as build and runtime dependencies to the
project as these are required by inkwell now that it is actually in use.
This fixes an issue preventing compilation in tests.
This pass runs an analysis of LLVM modules to resolve all top-level
entities. The results are written out as pass data, and are intended for
use as part of a consistency check during the compilation to FLO.

As part of implementing this pass, this commit also implements:

- A proxy for the portions of the LLVM type system that we support,
  enabling us to do pre- and during-compilation consistency checking
  where necessary.
- A parser for LLVM's data-layout specifications, allowing us to ensure
  that the provided modules are not making any assumptions that would be
  unsafe for our target machine.
@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch from 785a1a2 to b8ac5e5 Compare October 23, 2024 14:28
This commit performs a number of small miscellaneous refactorings and
fixes in response to looking at the code with a fresh set of eyes. It
also accounts for feedback given during code review.
@iamrecursion iamrecursion force-pushed the wip/ara/initial-compilation branch from b8ac5e5 to 72aecf4 Compare October 23, 2024 17:07
@iamrecursion iamrecursion merged commit df36ce7 into main Oct 23, 2024
5 checks passed
@iamrecursion iamrecursion deleted the wip/ara/initial-compilation branch October 23, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants