Commit 724abef
authored
fix(assembly): regression in link-time symbol resolution involving quoted path components (#2627)
* test: add regression test for linking items with quoted path components
This test fails due to some subtle issues around how symbols and paths
are handled during parsing, semantic analysis, and linking/assembly.
* fix(assembly): unquote quoted path components when converting to str
This ensures that converting a path component to an identifier/str, then
pushing that identifier/str as a path component produces an identical
path.
While we want to preserve quotes in the underlying buffer of
Path/PathBuf, we don't want to surface quotes in strings produced by the
Path/PathBuf APIs. This is consistent with how Ident internally
represents symbols (i.e. unquoted).
Instead, we rely on the builder/constructor methods of `PathBuf` to
restore quotes as-needed.
Note that it is possible to construct a path involving quoted components
that don't actually need to be quoted. In a future commit,
canonicalization will be added so that you can always obtain a canonical
form from a possible non-canonical path.
* fix(assembly): ensure PathComponent::requires_quoting considers whether
a string is a valid identifier, not just whether it contains `::`
* fix(assembly): distinguish path join semantics for paths vs components
Previously, `Path::join` required the item to be joined to implement
`AsRef<Path>`, and implementations for this exist for both `str` and
`Path`/`PathBuf` - thus, it always treated the item to be joined as a
full path.
The problem is that we are frequently obtaining a path component as a
string, and then constructing new paths with `Path::join`. When these
strings are produced, they are produced unquoted - consequently, if
those paths happened to contain `::` delimiters, `Path::join` would
produce a path
Fundamentally, the issue is that the semantics of `Path::join` differ
depending on whether you are joining a `Path`-like item, or a
`PathComponent`-like item. We are always joining strings to a path as a
single component, never as a multi-component path; while we always join
paths to a path as multi-component paths.
This commit reworks `Path::join` to distinguish between the two use
cases. It provides a way to be explicit about what behavior you want
from `join`, while still providing the ergonomics from before. There is
still a subtle edge case where mistakes could be made, if someone is
attempting to join a multi-component path in string form (it will now be
treated as a single quoted component) - but we have no such uses in our
code base, and this is now documented clearly to warn those who might do
such a thing.
* fix(assembly): simplify path handling in grammar
* Properly handle quoted path components
* Remove unnecessary grammar rules
* fix(build): broken Makefile targets
* test(assembly): add test for intra-kernel library linking
* fix(assembly): implement path canonicalization and fix issues uncovered
This commit introduces two main features:
* Automatic canonicalization of paths when constructed via PathBuf
* Explicit canonicalization of Path via `Path::canonicalize`
* Tests were added for joining and canonicalization
It also addresses the following issues:
* We no longer treat $kernel/$exec specially during component parsing
and in certain Path methods like `is_absolute`, instead, these paths
are canonicalized to absolute and then treated like any other path.
* Some of the TryFrom/From conversions were not using the semantically
correct method when constructing a PathBuf
* Ident::requires_quoting was unused as a method, but has value as a
static function, and has been converted to one. It was also updated to
properly consider whether an identifier containing $ requires escaping
based on whether it is recognized as a reserved symbol, e.g. $kernel
* Deserialization of paths was requiring that the input be a borrowed
str, due to reusing the deserializer for Path, this is unnecessarily
limiting, and caused deserialization errors when the input string did
not have a lifetime sufficient to allow the input to be borrowed.
Instead, we now deserialize via PathBuf, and PathBufs deserialization
code was improved to allow deserializing from both borrowed and owned
strings, and to provide better error feedback1 parent 2e66bd2 commit 724abef
File tree
13 files changed
+708
-227
lines changed- crates
- assembly-syntax/src
- ast
- path
- procedure
- parser
- sema
- passes
- assembly/src
13 files changed
+708
-227
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
141 | 146 | | |
142 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
| |||
132 | 143 | | |
133 | 144 | | |
134 | 145 | | |
135 | | - | |
136 | | - | |
| 146 | + | |
| 147 | + | |
137 | 148 | | |
138 | 149 | | |
139 | 150 | | |
| |||
147 | 158 | | |
148 | 159 | | |
149 | 160 | | |
150 | | - | |
151 | | - | |
| 161 | + | |
| 162 | + | |
152 | 163 | | |
153 | 164 | | |
154 | 165 | | |
| |||
215 | 226 | | |
216 | 227 | | |
217 | 228 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
| |||
342 | 347 | | |
343 | 348 | | |
344 | 349 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
| 388 | + | |
395 | 389 | | |
396 | 390 | | |
397 | 391 | | |
| |||
557 | 551 | | |
558 | 552 | | |
559 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
560 | 558 | | |
561 | 559 | | |
562 | 560 | | |
| |||
566 | 564 | | |
567 | 565 | | |
568 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
569 | 571 | | |
570 | 572 | | |
571 | 573 | | |
572 | 574 | | |
573 | 575 | | |
574 | 576 | | |
575 | 577 | | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
576 | 583 | | |
577 | 584 | | |
578 | 585 | | |
| |||
584 | 591 | | |
585 | 592 | | |
586 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
587 | 599 | | |
588 | 600 | | |
589 | 601 | | |
| |||
0 commit comments