C# Compiler Incremental Compilation

This topic is based on a Microsoft developer design document that describes specific stages of the implementation of the C# compiler.  This topic is included here as a potential guide to understanding portions of the C# source code.

The following is an outline of the stages of COMPILER::CompileAll().

Read Incremental Information

Declare

All types in the compilation are known; however note the following:

Check for change in type list. A change to the following will cause a full rebuild:

Resolve Inheritance

All types have:

It is now legal to look up types in any context.

Define

Changed files have all public members declared (except property accessors). 
Public (non-private, to be precise) interface is compared against metadata. 
If a type has changed, all dependant files are added to the changed list. 
If the changed threshold is reached (50% of files have been read from source), recover to a full rebuild.

At this point, the final decision is made for either an incremental or a full rebuild.

For an incremental rebuild, read member definitions for all unchanged files from metadata.

Prepare

Common Language Specification

Common language specification checking on all members performed.

Emit (EmitTokens and Compile)

Write Incremental Information

Writes incremental information file.

Marking a Source Input File as Changed

Things that cause a file to be marked as changed:

State a file can be in:

Backing Out to a Full Rebuild

To back out to a full rebuild, all remaining unchanged files are marked as changed.  This forces them to be brought up to the current stage.

Emitting Metadata and Incremental Update

Types

Interface Changed

Reemit

Parameters

Reemit

Methods

Emit

HasChanged

Reemit

Method Impls Structure

Fields

Emit

HasChanged

Reemit

Properties

Emit

HasChanged

Reemit

Events

Emit

HasChanged

Reemit

Assembly

Emit

HasChanged

Reemit

Module


Emit

HasChanged

Reemit

Private Implementation Details

Emit

Reemit


Copyright (c) 2002 Microsoft Corporation. All rights reserved.