or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Peeking at compiler-internal data
for fun and profit
About me: oli-obk
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Note:
what do we say about us?
Where is Oli?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →About me: nikomatsakis
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →About me: I am evil
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →I plan to mercilessly show you his private notes, at least when they're endearing.
About you
About you
Hopefully you are not here to play Rust the game…
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →About you
You're here because you
This Talk
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Oli's notes to himself
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →"oh boy, let me tell you about my PhD thesis which is just about that topic"
Why does it matter how you integrate with the compiler?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Effects of DRY
Note:
because you didn't duplicate logic with slightly different behaviour
so you can just grab all the info from the compiler
because you give feedback on APIs
How…
Integrate with rustc
What we are going to do
Write a rustc that runs a custom lint to detect comparisons like
x == x
.Then we can give a nice friendly error message!
Example error message
via GIPHY
All examples work with
You can follow these examples via the hackmd of this presentation.
Also you can learn tons about rustc in the rustc-dev-guide:
https://rustc-dev-guide.rust-lang.org
get rustc as a lib
Unstable stuff
At present, the API is forever unstable, use at your own risk
Your own compiler
You have now reproduced rustc. You rock!
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Too bad people could already run rustc.
Callbacks
Callbacks is a trait which you can use to customize your compilation.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Callbacks
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Note:
Config has lots of fun things to configure
We concentrate on lints, so
register_lints
Callbacks
Callbacks
Note: we'll get into what a late pass is in a second
Callbacks
Note: we haven'd defined MyLint yet
Custom lints
Note: interesting part: LateLintPass
A (very) brief tour of rustc's IRs
LintPass(es)
EarlyLintPass
EarlyLintPass
LateLintPass
Note: types are cool, so always use
LateLintPass
if you canNote: called on all expressions, cannot cancel recursion
An actual lint
Not the code you really want, but gives you the idea:
==
compares too strictlyCheck the clippy version for something more realistic.
Config
file_loader
register_lints
override_queries
make_codegen_backend
Note:
the interesting parts
file_loader
22 second introduction to queries
override_queries
Examples of queries to override
layout_of
optimized_mir
mir_built
Integrations
miri
__start
symbolrustc_mir::interpret
Note:
most argument manipulation is for cargo-miri integration
cranelift
Note:
you are not forced to use rustc's
codgen_ssa framework
The community helps
Note:
abstractions aren't required to be useful for the compiler, just consistent with the rest of the APIs
Library-ification
Note:
I skimmed over this a bit like it wasn't important
Summary