Skip to content

Commit ffa5ed7

Browse files
committed
More docs
1 parent 65e5f8a commit ffa5ed7

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

docs/UnderTheHood.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ big project into small one. So I decided to make incremental compiler for Unity3
2323

2424
Unity3D makes three projects from Assets directory if your project has only C# sources.
2525
(If there are .js or .boo sources, additional projects will be created.
26-
more detailed info: [Unity Manual: Special Folders and Script Compilation Order](http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html))
26+
more detailed info: [Unity Manual: Special Folders and Script Compilation Order](http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html))
2727

2828
- Assembly-CSharp-firstpass
2929
- Consists of scripts in Plugins directory.
@@ -46,7 +46,7 @@ because they depends on previous projects.
4646
### Roslyn
4747

4848
Incremental compiler is built with [Roslyn](https://github.com/dotnet/roslyn)
49-
which is new open-source project providings C# and Visual Basic compilers.
49+
which is new open-source project providings C# and Visual Basic compilers.
5050
With this project it's really easy to use features that compiler can
5151
provide like parsing, analysing and even compiling itself.
5252

@@ -71,10 +71,10 @@ Not only compiling itself, it can provide new C# 6 and upcoming features.
7171

7272
Roslyn C# compiler does two steps to compile from API view.
7373

74-
1. Parsing step:
74+
1. Parsing step:
7575
It loads sources and build syntax trees by parsing them.
76-
2. Emitting step:
77-
From compiler's view, most of work is done here such as semantic analysis,
76+
2. Emitting step:
77+
From compiler's view, most of work is done here such as semantic analysis,
7878
optimization and code generation.
7979

8080
Because library users cannot access internal phase in emitting step,
@@ -87,7 +87,7 @@ incremental compiler is written in a simple way like:
8787
var compilation = CSharpCompilation.Create(syntaxTrees, references);
8888
compilation.Emit(ms);
8989
```
90-
- For subsequent builds, it update changes to compilation object and compiles it.
90+
- For subsequent builds, it update changes to compilation object and compiles it.
9191
```csharp
9292
compliation = compliation.RemoveReferences(oldLoadedReferences)
9393
.AddReferences(load(newReference))
@@ -102,7 +102,7 @@ pre-parsed syntax trees and some informations that I wish.
102102
### Compile server
103103

104104
Ok. Keeping compilation object and reusing can make an incremental compiler.
105-
But where can we put this object on? Everytime Unity3D want to build DLL,
105+
But where can we put this object on? Everytime Unity3D want to build DLL,
106106
it spawns C# compiler.
107107
C# compiler is running awhile, terminates and leaves built DLL for Unity3D,
108108
which means it should throw away compilation object.
@@ -129,7 +129,7 @@ to make this tool quickly even Mono doesn't support it.
129129

130130
Compiler server allocates big memory to keep a compilation object.
131131
In my case, for project consisting of 2,000 sources, it takes 300MB.
132-
132+
133133
### How to replace a builtin compiler with a new one.
134134

135135
At first, replacing mono compiler in unity directory with new one was considered.
@@ -198,45 +198,45 @@ public static class EditorTest {
198198
[MenuItem("Assets/Call Test")]
199199
public static void Test() {
200200
NormalTest.Test(1);
201-
}
201+
}
202202
}
203203
```
204-
204+
205205
After build & run, change the signature of method `Test` called by EditorTest.
206206

207207
```csharp
208208
public static class NormalTest {
209-
public static void Test(int a, string b) { // "string b" added
209+
public static void Test(int a, string b) { // "string b" added
210210
Debug.Log("Log:" + a);
211211
}
212212
}
213213
```
214214

215215
With WhenNoChange, Assembly-CSharp-Editor will be built because of change of NormalTest.
216216
But with WhenNoSourceChange, Assembly-CSharp-Editor won't be built because there is no change in their sources and
217-
you might get MissingMethodException like this:
217+
you might get MissingMethodException like this:
218218

219219
```csharp
220220
MissingMethodException: Method not found: 'NormalTest.Test'.
221221
```
222222

223223
When this exception is thrown, just recompiling Assembly-CSharp-Editor can solve the problem.
224-
So this can be a good option for making build fast on the price of rare exception.
224+
So this can be a good option for making build fast on the price of rare exception.
225225

226226
### MDB instead of PDB
227227

228228
Roslyn emits PDB file as a debugging symbol. But Unity3D cannot understand PDB file
229229
because it's based on mono compiler. To make unity3D get proper debugging information,
230230
MDB file should be constructed.
231-
Fortunately they already provided a tool to convert pdb to mdb.
231+
Fortunately they already provided a tool to convert pdb to mdb.
232232
Jb Evain also released [new one](https://gist.github.com/jbevain/ba23149da8369e4a966f)
233233
to support output of visual studio 2015.
234234

235235
So simple process supporting unity3d is
236236
1. Emit pdb with Roslyn
237237
1. Convert pdb to mdb with pdb2mdb tool
238238

239-
But how about emitting mdb from Roslyn directly?
239+
But how about emitting mdb from Roslyn directly?
240240
It could save time for generating and converting pdb.
241241
Good thing is that a guy at Xamarain already tried [it](https://github.com/mono/roslyn/pull/4).
242242
But bad thing is that it is not being maintained now.
@@ -270,7 +270,7 @@ IEnumerator TestCoroutine(int a, Func<int, string> b) {
270270
}
271271
```
272272

273-
Set breakpoint at a commented line in coroutine and watch local variable `v` in debugging windows.
273+
Set breakpoint at a commented line in coroutine and watch local variable `v` in debugging windows.
274274
UnityVS can show variable `v` in watch window for DLL built from Mono3.
275275

276276
```csharp
@@ -390,5 +390,6 @@ with detailed comments.
390390

391391
## Conclusion
392392

393-
Done! During this journey implementing an incremental compiler,
393+
`Done!` During this journey implementing an incremental compiler,
394394
I found many interesting works that people has been working and got inspired.
395+
Also with simple compiler, I became to be able to do iteration faster.

0 commit comments

Comments
 (0)