From 4d26601ac45aa2c33c215855991692f4f41e4fe1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 25 Nov 2015 16:00:19 -0800 Subject: [PATCH] Add a couple of overviews of general design --- Compiler-Internals.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Compiler-Internals.md b/Compiler-Internals.md index a1bad21..3297789 100644 --- a/Compiler-Internals.md +++ b/Compiler-Internals.md @@ -1,5 +1,24 @@ This is an incomplete page that will need to be updated as time goes on. The intent is that there are gaps of knowledge that are understood well among the team (or even just specific team members) which would be better if understood across a broader audience. +# General Design + +## Laziness + +To support language services that respond interactively, the compiler is lazy: it does not calculate any information until it is required. +This allows it to respond quickly when the language service requests the type of a variable or its members. +Unfortunately, laziness also makes the compiler code more complicated. + +As an overview, after parsing is complete, the binder does nothing but identify symbols. +The checker then waits until a particular symbol is requested to calculate type information, etc. + +## Immutability + +Each phase of the compiler (parser, binder, etc -- see below for details) treats data structures from the previous phases as immutable. +In addition, data structures created within each phase are not usually modified after their creation. +This requires a look-aside table in some cases. +For example, because the binder only looks at one file at a time, the checker needs a merged-symbols table to track merged declarations. +It checks whether a symbol has an entry in the merged-symbols table each time before it uses a symbol. + # Parser ## Incremental parsing