[nem-en] patch for matching compiler

mgrzeskowiak at tlen.pl mgrzeskowiak at tlen.pl
Sun Oct 23 22:10:20 CEST 2005


Hi

Finally I managed to get new matching compiler to the state
where it is quite usable. I attached a patch to revision
5836 of the repository for review and if it is ok I would
be thankful if someone could apply it (I can't do it myself
at the moment since I don't have Inet on my home computer).

Patch adds three new options to the ncc.exe:
-new-matching: this flag turns on the new matching compiler
  (it is still off by default)
-dump-decision-trees: this is mainly for debugging trees
  created by DecisionTreeBuilder
-no-dag: disable detection of shared subtrees in decision
  tree

Not everything is implemented and I don't plan to add
new features add the moment as I am very late with
my schedule. I haven't implemented any additional
optimizations (e.g. GetVariantCode () isn't used) and 
I think that there is still some work needed to
properly support null values (the idea was to 
add special message when matching failure was
due to null value in matching object). Also I didn't
remove Cast nodes from generated TExpr tree (although
it seems that there are less castclass instructions
in generated code). I didn't perform thorough 
benchmarks but it seems that code generated by
either of the matching compilers has similar run-time 
characteristics. A bit more noticeable are changes
in the amount of generated IL (new compiler is
better here). 
I tested the patch on mono-1.1.9 from 2005/10/12.
In `make check` there is one failure (the same as
for 5836 without patching). Some tests didn't 
execute due to missing libraries. On MS .Net I
only checked assemblies with PEVerify. There were
no errors and a lot of warnings, but they are
the same as for original boot compiler.

Some more detailed description of changes:

ncc/CompilationOptions.n
  Three new options mentioned above.

ncc/external/InternalTypes.n
  Add static property TupleType.NamePrefix. It is used in
  DecisionTreeCompiler and DecisionTreeBuilder to check
  if IField is from some tuple.
  I don't know if there is a better way to perform this test.

ncc/generation/DecisionTreeCompiler.n
  DecisionTreeCompiler class that implements new matching
  compiler. There is a static method Run that can be used
  similarly to MatchingCompiler.Run (). It creates new
  instance of DecisionTreeCompiler which in turn creates
  DecisionTreeBuilder, uses it to create a decision tree,
  and compiles it.
  I tried to avoid generating any TExprs in DecisionTreeBuilder
  and dealing with any Pattern nodes in DecisionTreeCompiler
  (I'd like to have DTC responsible for fromer and DTB for latter)
  which complicated a bit some functions.
  The one function I am still not very satisfied with is
  build_path_expression () which generates TExprs to load
  objects on the VM stack. But it seems to work anyway :-P

ncc/typing/DecisionTreeBuilder.n
  Fix support for null values in Con and CheckMatching ()
  (this was also in the previously posted patch).
  CheckMatching () can be used now either as static or
  instance function (depending whether new or old matching
  compiler is used).
  Add Equals () and GetHashCode () functions to Path, Con,
  and Decision variants, so instances of Decision can be
  stored in a hash table. This is needed to detect shared
  nodes.
  TyVar of Pattern is also stored in Path -- it is used
  to generate TExprs in DecisionTreeCompiler.build_path_expression ()

ncc/generation/Typer3.n
  Run either DecisionTreeCompiler.Run () or MatchingCompiler.Run ()
  to compile a matching instance.

ncc/Makefile
  Add DecisionTreeCompiler.n to the list of Nemerle.Compiler.dll
  sources.

ncc/typing/TypedTree.n:
  Add disable_warnings field to Match_case. This is needed when
  -new-matching is used because in this case CheckMatching () is
  invoked later (not in Typer).

ncc/typing/Typer.n:
  Defer calling CheckMatching () and FixupMatchCase () when
  -new-matching was specified.

ncc/misc/PrettyPrint:
  Small fix because of new Match_case.

ncc/testsuite/Makefile, ncc/testsuite/test.n:
  Two small changes to fix problems on Mono 1.1.9:
  1) new code to pass additional arguments to .Net engine
  2) catch and ignore InvalidOperationException thrown from
     runtime.Kill ()
  These changes just fix the problems I don't know if
  ignoring InvalidOperationException is the right thing to do.

ncc/testsuite/positive/new-matching-as.n,
ncc/testsuite/positive/new-matching-null.n:
  Two additional test cases for new matching.
  (I am not sure if 'positive' directory is ok)

Marcin Grześkowiak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: =?iso-8859-2?Q?new-matching.patch?=
Type: application/octet-stream
Size: 53088 bytes
Desc: not available
Url : /mailman/pipermail/devel-en/attachments/20051023/0b9b4d50/iso-8859-2Qnew-matching-0001.obj


More information about the devel-en mailing list