Expand description
Matching a target’s lowering rules against a term.
Design: spec/10-backend.md section 10.2. The rules themselves are in rules/, one file per
target, and the automaton they compile into is generated by rucc-rules when this crate is
built. What is here is the walk over that automaton, which is the same walk for every target
and is written once.
§What a subject is
A rule matches a term, and the compiler does not have terms: it has a function full of
instructions, and what a pattern is about is one of them and whatever it was computed from.
So the walk is written against Subject, which is the three questions the automaton asks
of whatever it is matching, and the selector answers them out of the IR without building a
term to be thrown away. A test can answer them out of anything at all, which is what the
tests at the bottom of this file do.
§What a match gives back
The rule that fired and what its pattern bound, in the order the pattern binds it. The
bindings are positions rather than names because that is what the walk has, and the rule
carries the names for anything that has to say what it did. Building the replacement out of
Piece is the selector’s job rather than this file’s, because what a machine term becomes
is a machine instruction, and this module is about matching.
§Order
At every node the concrete tests are tried before the branch that takes anything, so a rule
naming an operand is tried before a rule taking whatever is there. That is the maximal munch
spec/10-backend.md asks for, and it falls out of the shape of the trie rather than being
sorted for. Among rules that are equally specific the first one written wins.
A guard is part of deciding whether a rule fires, so a rule whose guard is false is a rule that did not match, and the walk carries on looking rather than giving up. What that costs is the search from where the guard failed, which is the price of a guard being allowed to be about the values rather than only about the shape.
Modules§
- x86_64
- The x86-64 lowering table.
Structs§
- Match
- What a successful match found.
- Node
- One node of the trie over the patterns.
- Rule
- One lowering rule, as much of it as matching needs.
- Table
- A target’s lowering rules, as an automaton over their patterns.
Enums§
Traits§
- Subject
- The bits of a term the automaton asks about.
Type Aliases§
- Guard
- A condition on the constants a pattern matched.