Expand description
Code related to match expressions. These are sufficiently complex to warrant their own module and submodules. :) This main module includes the high-level algorithm, the submodules contain the details.
This also includes code for pattern bindings in let statements and
function parameters.
ModulesΒ§
- match_
pair π - simplify πSimplifying Candidates
- test π
- util π
StructsΒ§
- ArmHas
Guard πArmHasGuardis a wrapper around a boolean flag. It indicates whether a match arm has a guard expression attached to it. - Ascription πIndicates that the type of
sourcemust be a subtype of the user-given typeuser_ty; this is basically a no-op but can influence region inference. - Binding π
- Built
Match πTree The result of generating MIR for a pattern-matching expression. Each input branch/arm/pattern gives rise to an outputMatchTreeBranch. If one of the patterns matches, we branch to the correspondingsuccess_block. If none of the patterns matches, we branch tootherwise_block. - Candidate πCandidates are a generalization of (a) top-level match arms, and (b) sub-branches of or-patterns, allowing the match-lowering process to handle them both in a mostly-uniform way. For example, the list of candidates passed to
Builder::match_candidateswill often contain a mixture of top-level candidates and or-pattern subcandidates. - FlatPat πA pattern in a form suitable for lowering the match tree, with all irrefutable patterns simplified away, and or-patterns sorted to the end.
- Match
Pair πTree Node in a tree of βmatch pairsβ, where each pair consists of a place to be tested, and a test to perform on that place. - Match
Tree πBranch A branch in the output of match lowering. - Match
Tree πSubBranch A sub-branch in the output of match lowering. Match lowering has generated MIR code that will branch tosuccess_blockwhen the matched value matches the corresponding pattern. If there is a guard, its failure must continue tootherwise_block, which will resume testing patterns. - Pattern
Extra πData Data extracted from a pattern that doesnβt affect which branch is taken. Collected during pattern simplification and not mutated later. - Test πA test to perform to determine which
Candidatematches a value. - Then
Else πArgs Arguments toBuilder::then_else_break_innerthat are usually forwarded to recursive invocations.
EnumsΒ§
- Declare
LetBindings πShould lowering aletexpression also declare its bindings? - Emit
Storage πLive Used byBuilder::bind_matched_candidate_for_arm_bodyto determine whether or not to callBuilder::storage_live_bindingto emitStatementKind::StorageLive. - HasMatch
Guard π - Schedule
Drops πUsed byBuilder::storage_live_bindingandBuilder::bind_matched_candidate_for_arm_bodyto decide whether to schedule drops. - Test
Branch πThe branch to be taken after a test. - Test
Case πPartial summary of athir::Pat, indicating what sort of test should be performed to match/reject the pattern, and what the desired test outcome is. This avoids having to perform a full match onthir::PatKindin some places, and helpsTestKind::SwitchandTestKind::SwitchIntknow what target values to use. - Test
Kind πSeeTestfor more.
FunctionsΒ§
- traverse_
candidate πA depth-first traversal of theCandidateand all of its recursive subcandidates.