-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Populate runtimes with all built-in declarations #4658
Changes from 49 commits
5d4a536
ee1f458
1467945
e0321a5
80f4a69
cac5f6d
3f43125
ae4824d
122bf3d
3a6f48c
ddd92b9
0da417a
423662b
a81d0ab
4ae4a3b
f58fe08
0d9ac87
129b08f
dcd038c
96c3bae
29f26b9
7303e87
cd9167b
5b86ff3
51cb7eb
0facbbf
980d12f
cc2a370
1e013e6
39c71e5
72d5ea6
26a7214
67fb7c1
7b6258b
06dc8c7
dc012ae
c3c2ee2
86bc5e8
d518542
8a41a9f
2429f0c
639b9e6
d9d3713
dbc369f
ca730f8
dc0b8eb
4812b89
582fe2c
ab8c23b
761cbf8
b783675
f4adb04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ public class CsharpCompiler : SinglePassCompiler { | |
|
||
public override IReadOnlySet<Feature> UnsupportedFeatures => new HashSet<Feature> { | ||
Feature.SubsetTypeTests, | ||
Feature.TuplesWiderThan20 | ||
Feature.TuplesWiderThan20, | ||
Feature.ArraysWithMoreThan16Dims, | ||
Feature.ArrowsWithMoreThan16Arguments | ||
}; | ||
|
||
public CsharpCompiler(DafnyOptions options, ErrorReporter reporter) : base(options, reporter) { | ||
|
@@ -71,17 +73,26 @@ protected override void EmitHeader(Program program, ConcreteSyntaxTree wr) { | |
wr.WriteLine("// Optionally, you may want to include compiler switches like"); | ||
wr.WriteLine("// /debug /nowarn:162,164,168,183,219,436,1717,1718"); | ||
wr.WriteLine(); | ||
if (program.Options.SystemModuleTranslationMode == CommonOptionBag.SystemModuleMode.Populate) { | ||
wr.WriteLine("#if ISDAFNYRUNTIMELIB"); | ||
} | ||
wr.WriteLine("using System;"); | ||
wr.WriteLine("using System.Numerics;"); | ||
wr.WriteLine("using System.Collections;"); | ||
if (program.Options.SystemModuleTranslationMode == CommonOptionBag.SystemModuleMode.Populate) { | ||
wr.WriteLine("#endif"); | ||
} | ||
Synthesize = ProgramHasMethodsWithAttr(program, "synthesize"); | ||
if (Synthesize) { | ||
CsharpSynthesizer.EmitImports(wr); | ||
} | ||
EmitDafnySourceAttribute(program, wr); | ||
|
||
if (program.Options.SystemModuleTranslationMode != CommonOptionBag.SystemModuleMode.Populate) { | ||
EmitDafnySourceAttribute(program, wr); | ||
} | ||
|
||
if (Options.IncludeRuntime) { | ||
ReadRuntimeSystem(program, "DafnyRuntime.cs", wr); | ||
EmitRuntimeSource("DafnyRuntimeCsharp", wr, false); | ||
} | ||
|
||
} | ||
|
@@ -119,8 +130,25 @@ void EmitDafnySourceAttribute(Program program, ConcreteSyntaxTree wr) { | |
} | ||
|
||
protected override void EmitBuiltInDecls(SystemModuleManager systemModuleManager, ConcreteSyntaxTree wr) { | ||
if (systemModuleManager.MaxNonGhostTupleSizeUsed > 20) { | ||
UnsupportedFeatureError(systemModuleManager.MaxNonGhostTupleSizeToken, Feature.TuplesWiderThan20); | ||
switch (Options.SystemModuleTranslationMode) { | ||
case CommonOptionBag.SystemModuleMode.Omit: { | ||
CheckCommonSytemModuleLimits(systemModuleManager); | ||
break; | ||
} | ||
case CommonOptionBag.SystemModuleMode.Populate: { | ||
CheckSystemModulePopulatedToCommonLimits(systemModuleManager); | ||
break; | ||
} | ||
} | ||
|
||
// The declarations below would normally be omitted if we aren't compiling the system module, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like these declarations could be not-internal and only as part of the system module There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that, but realized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't get what you mean. You can use extensions methods defined in a library for sure. |
||
// but they are all marked as "internal", so they have to be included in each separately-compiled assembly. | ||
// Instead we just make sure to guard them with "#if ISDAFNYRUNTIMELIB" when compiling the system module, | ||
// so they don't become duplicates when --include-runtime is used. | ||
// See comment at the top of DafnyRuntime.cs. | ||
|
||
if (Options.SystemModuleTranslationMode == CommonOptionBag.SystemModuleMode.Populate) { | ||
wr.WriteLine("#if ISDAFNYRUNTIMELIB"); | ||
} | ||
|
||
var dafnyNamespace = CreateModule("Dafny", false, false, null, wr); | ||
|
@@ -129,6 +157,10 @@ protected override void EmitBuiltInDecls(SystemModuleManager systemModuleManager | |
CsharpSynthesizer.EmitMultiMatcher(dafnyNamespace); | ||
} | ||
EmitFuncExtensions(systemModuleManager, wr); | ||
|
||
if (Options.SystemModuleTranslationMode == CommonOptionBag.SystemModuleMode.Populate) { | ||
wr.WriteLine("#endif"); | ||
} | ||
} | ||
|
||
// Generates casts for functions of those arities present in the program, like: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this TODO