(contents: str)
| 73 | |
| 74 | |
| 75 | def build_deopts(contents: str) -> dict[str, list[str]]: |
| 76 | raw_body = re.search( |
| 77 | r"fn deopt\(self\) -> Option<Self>(.*)", contents, re.DOTALL |
| 78 | ).group(1) |
| 79 | body = "\n".join( |
| 80 | itertools.takewhile( |
| 81 | lambda l: not l.startswith("_ =>"), # Take until reaching fallback |
| 82 | filter( |
| 83 | lambda l: ( |
| 84 | not l.startswith( |
| 85 | ("//", "Some(match") |
| 86 | ) # Skip comments or start of match |
| 87 | ), |
| 88 | map(str.strip, raw_body.splitlines()), |
| 89 | ), |
| 90 | ) |
| 91 | ).removeprefix("{") |
| 92 | |
| 93 | depth = 0 |
| 94 | arms = [] |
| 95 | buf = [] |
| 96 | for char in body: |
| 97 | if char == "{": |
| 98 | depth += 1 |
| 99 | elif char == "}": |
| 100 | depth -= 1 |
| 101 | |
| 102 | if depth == 0 and (char in ("}", ",")): |
| 103 | arm = "".join(buf).strip() |
| 104 | arms.append(arm) |
| 105 | buf = [] |
| 106 | else: |
| 107 | buf.append(char) |
| 108 | |
| 109 | # last arm |
| 110 | arms.append("".join(buf)) |
| 111 | arms = [arm for arm in arms if arm] |
| 112 | |
| 113 | deopts = {} |
| 114 | for arm in arms: |
| 115 | *specialized, deopt = map(to_pascal_case, re.findall(r"Self::(\w*)\b", arm)) |
| 116 | deopts[deopt] = specialized |
| 117 | |
| 118 | return deopts |
| 119 | |
| 120 | |
| 121 | contents = BYTECODE_FILE.read_text(encoding="utf-8") |
no test coverage detected