diff options
Diffstat (limited to 'rfc.md')
-rw-r--r-- | rfc.md | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -36,7 +36,46 @@ be `0.1.0`. | |||
36 | # Motivation | 36 | # Motivation |
37 | [motivation]: #motivation | 37 | [motivation]: #motivation |
38 | 38 | ||
39 | Why are we doing this? What use cases does it support? What is the expected outcome? | 39 | "Reusable software component" part is addressed first "IDE ready part" |
40 | second. | ||
41 | |||
42 | |||
43 | In theory, parsing can be a pure function, which takes a `&str` as an | ||
44 | input, and produces a `ParseTree` as an output. | ||
45 | |||
46 | This is great for reusability: for example, you can compile this | ||
47 | function to WASM and use it for fast client-side validation of syntax | ||
48 | on the rust playground, or you can develop tools like `rustfmt` on | ||
49 | stable Rust outside of rustc repository, or you can embed the parser | ||
50 | into your favorite IDE or code editor. | ||
51 | |||
52 | This is also great for correctness: with such simple interface, it's | ||
53 | possible to write property-based tests to thoroughly compare two | ||
54 | different implementations of the parser. It's also straightforward to | ||
55 | create a comprehensive test suite, because all the inputs and outputs | ||
56 | are trivially serializable to human-readable text. | ||
57 | |||
58 | Another benefit is performance: with this signature, you can cache a | ||
59 | parse tree for each file, with trivial strategy for cache invalidation | ||
60 | (invalidate an entry when the underling file changes). On top of such | ||
61 | a cache it is possible to build a smart code indexer which maintains | ||
62 | the set of symbols in the project, watches files for changes and | ||
63 | automatically reindexes only changed files. | ||
64 | |||
65 | Unfortunately, the current libsyntax is far from this ideal. For | ||
66 | example, even the lexer makes use of the `FileMap` which is | ||
67 | essentially a global state of the compiler which represents all know | ||
68 | files. As a data point, it turned out to be easier to move `rustfmt` | ||
69 | inside of main `rustc` repository than to move libsyntax outside! | ||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
40 | 79 | ||
41 | # Guide-level explanation | 80 | # Guide-level explanation |
42 | [guide-level-explanation]: #guide-level-explanation | 81 | [guide-level-explanation]: #guide-level-explanation |