summaryrefslogtreecommitdiff
path: root/notes/compilation_unit_isolation.txt
blob: aabed7428383a55bf876c2ce0441398f8b7a588d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

Compilation unit isolation
==========================

Can we ("stage1"-)compile a file without looking at other files?

What can definitiely NOT be done:
- struct member offset
- struct member types (= and expression target type and type scopes for assignment)
- function argument types (= and expression target type and type scopes)
(i.e. we can not generate a usual object file)
(even if we skip target types and type scopes, we still need to know struct member types and offsets)
(on the other hand, bundling partial definitions in imports could be useful, e.g. "import func work(int, ref Something)" )

What CAN be done:
- generate list of
1) imported symbols and members / arguments / typescope members
2) exports
3) functions, with some kind of IR (with spotty type info)
4) type definitions (with spotty type info)
5) data / variable definitions

Simply generating a file with all definitions could potentially
make incremental compilation faster:
- If interface is unchanged, don't update file or touch mtime.
- When compiling a file, only the interfaces of the other files
  needs to be read.
- There could be an index/cache file for all interfaces
  combined.

Alternative approach to fast incremental compilation
- Copy (or hash) a all definitions that the compilation unit
  depends on
- When the dependencies are updated, compare against the
  copies/hashes. If they are identical, then no recompilation
  is needed.
- For minor changes (like a changed enum constant, or
  re-ordered struct), perhaps we simply update some info
  in the compiled file?


Defintions "binary header" file
-------------------------------
We can have one for exports (read when compiling other source files)
and one for imports (compared with other headers when checking whether
a recompilation of this source file is needed)


byte[8]    "LRL-BH\x0A\0"
le_uint32  num type symbols
le_uint32  num function/data symbols

for imports header:
- list of imported files (for re-reading those headers, if their timestamp is never, OR removing symbols if deleted)

tree       type symbols (pointers)
tree       function/data symbols (pointers)

bucket[]   bucket data


Each bucket contains:
- number of symbols in bucket
- symbols

Each symbol contains:
- name
- symbol definition
-- type (primitive/func/ref/struct/class struct/enum/array/optional/etc...)
-- data for this type