Skip to content
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 rust externs subsets eta names tests #5613

Merged
merged 92 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
b8b7788
feat-rust-synonymtype-charliterals Feat: Added support for erased syn…
MikaelMayer May 3, 2024
cf95ebd
feat-rust-maybeuninit-out-vars: Feat: MaybeUninit for out variable de…
MikaelMayer May 4, 2024
2a42759
feat-rust-for-loops: Feat: Rust for loops
MikaelMayer May 6, 2024
bdf1f31
feat-classes-arrays: Support for trait types and upcast coercion as a…
MikaelMayer May 6, 2024
e3e1e2d
feat-rust-boundedpool-loops: MapBoundedPool domain, map builder fixed…
MikaelMayer May 28, 2024
7e3346b
feat-rust-borrowing-calls: Ensure borrowing of first argument is done…
MikaelMayer Jun 3, 2024
1e60595
feat-rust-dafny-test: Support for dafny test
MikaelMayer Jun 19, 2024
0ffa0c2
feat-rust-reserved-names: construction of Rust structs now has field …
Jun 3, 2024
e107306
feat-rust-traits: Support for traits, constructors, classes, self type
MikaelMayer Jun 3, 2024
67a050f
feat-rust-native-fix: Fixed owned conversion for newtypes
fabiomadge Jun 7, 2024
3f2d171
feat-rust-datatypes-fixes: PartialEq not for functions, print for fun…
Jun 12, 2024
ff611ed
feat-rust-coercion-upcast-downcast: Coercion for upcast/downcast, env…
MikaelMayer Jun 11, 2024
61527d7
feat-rust-fixup-hash-sequences-miri: Loosen Hash for sequences, fixed…
MikaelMayer Jun 17, 2024
203b8da
feat-rust-object-variance: Covariance and invariance on datatypes and…
MikaelMayer Jun 19, 2024
a7fde0e
Back-ported fix from #5574
MikaelMayer Jun 25, 2024
bb2ca4d
Fixup: Function's Hash on datatypes
MikaelMayer Jun 25, 2024
2adb014
Fixup: Removed merge conflict in mod.rs
MikaelMayer Jun 25, 2024
351f38e
Fixup: Non-overriden Destructor name not overriding existing one
MikaelMayer Jun 25, 2024
73b3561
arrays and usize
MikaelMayer Jun 25, 2024
5082cb5
MAybeuninit fix: Function by method's return statement is correct.
MikaelMayer Jun 25, 2024
7a42ea3
fixup traits: Correct paths when method names contain special characters
MikaelMayer Jun 25, 2024
6ebdce7
fixup classes: Avoid soundness issue with raw pointers + unreachable …
MikaelMayer Jun 26, 2024
12d5f36
feat-rust-externs: Support for additional rust files on the command line
MikaelMayer Jun 27, 2024
fe888e0
feat-rust-subset-constraints: Support for compiled subset constraints…
MikaelMayer Jun 27, 2024
bd46d20
functions: eta-expansion of top level functions and correct type for …
fabiomadge Jun 29, 2024
aafca78
constants: function constants are eta-expanded with an additional call
Jun 30, 2024
acdda1f
reserved names: refactoring of name escaping to handle module-/type-l…
Jul 1, 2024
371b62e
elephant operator: desugaring modified so RHS avoids capturing variab…
Jul 2, 2024
e196ed0
fix-maps-issues: Fixed several issues regarding maps, datatype erasur…
MikaelMayer Jul 2, 2024
3c235a6
maps: special field .Items now implemented
Jul 2, 2024
ed1750d
type tests: implemented when the source type is object
Jul 2, 2024
8acecb6
fix-rust-conversions: support for Rust parsing ambiguity and missing …
MikaelMayer Jul 2, 2024
92c176d
datatypes: references to hash are fully qualified to avoid shadowing …
Jul 3, 2024
f82ce12
feat-type-synonyms-complete: Feat: Support for type synonyms and conv…
MikaelMayer Jul 3, 2024
a9ddfea
No creation of allocate() and upcast for default class.
MikaelMayer Jul 5, 2024
2831035
SImplified encoding of escaping + less brittle code.
MikaelMayer Jul 5, 2024
c28abcf
Refactoring: Paths now shared between types and expressions
MikaelMayer Jul 5, 2024
d6beb1e
feat-rust-simplify-paths: Simplify top-level paths and use clauses to…
MikaelMayer Jul 6, 2024
828303d
Fixup paths optimization
MikaelMayer Jul 9, 2024
537601e
feat-rust-nested-modules: Feat: Modules are now generated as nested i…
MikaelMayer Jul 9, 2024
e4b87dc
fixup library: Better ways to create objects externally
MikaelMayer Jul 9, 2024
c7fb0d5
Fixup coercion/classes.rs
MikaelMayer Jul 9, 2024
e7323d8
fixup import files: Fix: Externs insensible to lower/upper case
MikaelMayer Jul 10, 2024
443a3dc
Fixup: Raw pointers working again, removed soundness issue with equality
MikaelMayer Jul 10, 2024
bbde91a
Merge branch 'refs/heads/master' into feat-rust
MikaelMayer Jul 10, 2024
428072f
Fixed the merge commit
MikaelMayer Jul 10, 2024
832205a
Review: Documentation for GenType / simplification
MikaelMayer Jul 10, 2024
a306e24
Type parameters that are used don't give rise to phantom fields or ph…
MikaelMayer Jul 10, 2024
32de2e4
Fixup: is_instance_of now a method, IIFE retain type information
MikaelMayer Jul 10, 2024
ddea4d4
fixed dafny_runtime_conversions to support more cases
MikaelMayer Jul 10, 2024
8197e83
Fixed all CI issues except the elephant operator
MikaelMayer Jul 10, 2024
9d2a8ef
Merged master
MikaelMayer Jul 10, 2024
5002833
Merged master
MikaelMayer Jul 10, 2024
3d446bf
Fixed externs errors and path optimization tests
MikaelMayer Jul 10, 2024
b6e6531
Rewriting of the optimization only in the SinglePassCompiler
MikaelMayer Jul 10, 2024
dc6dc2e
Formatting
MikaelMayer Jul 10, 2024
c2afb5d
extern errors fix
MikaelMayer Jul 10, 2024
b6b8d65
Fixed CI
MikaelMayer Jul 11, 2024
a311e51
Fixed CI
MikaelMayer Jul 11, 2024
5b1f288
Fixed expect file
MikaelMayer Jul 11, 2024
a27df22
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Jul 11, 2024
6b08007
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Aug 2, 2024
d082e85
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Aug 7, 2024
0da1b6f
Resolved merge conflicts
MikaelMayer Aug 8, 2024
16d1333
fixup: guarded for each loops no longer generate ConcreteSyntaxTrees
Jul 25, 2024
6bca265
reserved names: hash now in reserved_vars
Aug 1, 2024
c6f44b0
fixup: bounded integer ranges now have explicit newtype conversions w…
Aug 4, 2024
fceb8a7
formatting
MikaelMayer Aug 9, 2024
03b6afe
More doc about pointers + test the runtime in CI
MikaelMayer Aug 15, 2024
5599798
Fixup: Continue labels, operator chaining, and slices
MikaelMayer Aug 15, 2024
083affa
Review comments
MikaelMayer Aug 16, 2024
b1f5e24
Merge branch 'refs/heads/master' into feat-rust-externs-subsets-eta-n…
MikaelMayer Aug 16, 2024
5713b72
Review comments
MikaelMayer Aug 19, 2024
848b00c
Fixed unreported null pointer exception on user's code
MikaelMayer Aug 20, 2024
d8e2b3c
Review comments
MikaelMayer Aug 20, 2024
5da9893
Review comments
MikaelMayer Aug 21, 2024
5d90e60
Merge branch 'feat-rust-externs-subsets-eta-names-tests' of https://g…
MikaelMayer Aug 21, 2024
9cbfe25
Review comments
MikaelMayer Aug 23, 2024
4a4cc38
Fixed the check for --raw-pointers
MikaelMayer Aug 23, 2024
34091f7
Removing undefined behavior
MikaelMayer Aug 23, 2024
a0265d8
Fixed rust tests
MikaelMayer Aug 23, 2024
eccadb1
Update Source/DafnyCore/Options/CommonOptionBag.cs
MikaelMayer Aug 26, 2024
d662e3f
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Aug 26, 2024
c6d477d
Fixed a test case
MikaelMayer Aug 26, 2024
d5a7743
Updated DCOMP
MikaelMayer Aug 26, 2024
618131a
Ability to run one test with the makefile
MikaelMayer Sep 3, 2024
a31cd03
Fixed a CI test
MikaelMayer Sep 3, 2024
fc2de36
Regenerated C# files
MikaelMayer Sep 3, 2024
4323517
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Sep 3, 2024
5405773
Added missing makefile
MikaelMayer Sep 3, 2024
354e19b
Removed outdated tests in the Rust runtime
MikaelMayer Sep 3, 2024
a20aafa
Merge branch 'master' into feat-rust-externs-subsets-eta-names-tests
MikaelMayer Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,25 @@ clean:
update-cs-module:
(cd "${DIR}"; cd Source/DafnyRuntime; make update-system-module)

update-rs-module:
(cd "${DIR}"; cd Source/DafnyRuntime; make update-system-module-rs)

update-go-module:
(cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeGo; make update-system-module)

update-runtime-dafny:
(cd "${DIR}"; cd Source/DafnyRuntime/DafnyRuntimeDafny; make update-go)

pr-nogeneration: format-dfy format update-runtime-dafny update-cs-module update-rs-module update-go-module

# `make pr` will bring you in a state suitable for submitting a PR
# - Builds the Dafny executable
# - Use the build to convert core .dfy files to .cs
# - Rebuilds the Dafny executable with this .cs files
# - Apply dafny format on all dfy files
# - Apply dotnet format on all cs files except the generated ones
# - Rebuild the Go and C# runtime modules as needed.
pr: exe dfy-to-cs-exe format-dfy format update-runtime-dafny update-cs-module update-go-module
pr: exe dfy-to-cs-exe pr-nogeneration

# Same as `make pr` but useful when resolving conflicts, to take the last compiled version of Dafny first
pr-conflict: dfy-to-cs-exe dfy-to-cs-exe pr-nogeneration

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Dafny program the_program compiled into C#
// To recompile, you will need the libraries
// System.Runtime.Numerics.dll System.Collections.Immutable.dll
// but the 'dotnet' tool in net6.0 should pick those up automatically.
// Optionally, you may want to include compiler switches like
// /debug /nowarn:162,164,168,183,219,436,1717,1718

using System;
using System.Numerics;
using System.Collections;
#pragma warning disable CS0164 // This label has not been referenced
#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable CS1717 // Assignment made to same variable

namespace FactorPathsOptimizationTest {

public partial class __default {
public static void ShouldBeEqual(RAST._IMod a, RAST._IMod b)
{
Dafny.ISequence<Dafny.Rune> _0_sA;
_0_sA = (a)._ToString(Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""));
Dafny.ISequence<Dafny.Rune> _1_sB;
_1_sB = (b)._ToString(Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""));
if (!(_0_sA).Equals(_1_sB)) {
Dafny.Helpers.Print((Dafny.Sequence<Dafny.Rune>.Concat(Dafny.Sequence<Dafny.Rune>.Concat(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("Got:\n"), _0_sA), Dafny.Sequence<Dafny.Rune>.UnicodeFromString("\n"))).ToVerbatimString(false));
Dafny.Helpers.Print((Dafny.Sequence<Dafny.Rune>.Concat(Dafny.Sequence<Dafny.Rune>.Concat(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("Expected:\n"), _1_sB), Dafny.Sequence<Dafny.Rune>.UnicodeFromString("\n"))).ToVerbatimString(false));
if (!((_0_sA).Equals(_1_sB))) {
throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-path-simplification.dfy(12,6): " + Dafny.Sequence<Dafny.Rune>.UnicodeFromString("expectation violation").ToVerbatimString(false));}
}
}
public static void TestApply()
{
RAST._ITypeParamDecl _0_T__Decl;
_0_T__Decl = RAST.TypeParamDecl.create(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("T"), Dafny.Sequence<RAST._IType>.FromElements(RAST.__default.DafnyType));
RAST._ITypeParamDecl _1_T__Decl__simp;
_1_T__Decl__simp = RAST.TypeParamDecl.create(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("T"), Dafny.Sequence<RAST._IType>.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("DafnyType"))));
RAST._IType _2_T;
_2_T = RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("T"));
RAST._IPath _3_std__any__Any;
_3_std__any__Any = (((RAST.__default.@global).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("std"))).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("any"))).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("Any"));
RAST._IType _4_Any;
_4_Any = RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("Any"));
FactorPathsOptimizationTest.__default.ShouldBeEqual(FactorPathsOptimization.__default.apply(RAST.Mod.create_Mod(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("onemodule"), Dafny.Sequence<RAST._IModDecl>.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence<Dafny.ISequence<Dafny.Rune>>.FromElements(), Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"), Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence<RAST._IField>.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("onemodule"), Dafny.Sequence<RAST._IModDecl>.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence<Dafny.ISequence<Dafny.Rune>>.FromElements(), Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"), Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence<RAST._IField>.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements())))));
FactorPathsOptimizationTest.__default.ShouldBeEqual(FactorPathsOptimization.__default.apply(RAST.Mod.create_Mod(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("onemodule"), Dafny.Sequence<RAST._IModDecl>.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence<RAST._IType>.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("onemodule"), Dafny.Sequence<RAST._IModDecl>.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence<RAST._ITypeParamDecl>.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence<Dafny.Rune>.UnicodeFromString("test"))).Apply(Dafny.Sequence<RAST._IType>.FromElements(_2_T)), Dafny.Sequence<Dafny.Rune>.UnicodeFromString(""), Dafny.Sequence<RAST._IImplMember>.FromElements())))));
}
}
} // end of namespace FactorPathsOptimizationTest
59 changes: 43 additions & 16 deletions Source/DafnyCore/Backends/Dafny/AST.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ module {:extern "DAST"} DAST {
// Make it a newtype once newtypes are compatible with standard library
// See issue https://github.com/dafny-lang/dafny/issues/5345
datatype Name = Name(dafny_name: string)
// None would need to be escaped.
MikaelMayer marked this conversation as resolved.
Show resolved Hide resolved
datatype VarName = VarName(dafny_name: string)

datatype Module = Module(name: Name, attributes: seq<Attribute>, body: Option<seq<ModuleItem>>)
datatype Module = Module(name: Name, attributes: seq<Attribute>, requiresExterns: bool, body: Option<seq<ModuleItem>>)

datatype ModuleItem =
| Module(Module)
Expand All @@ -45,6 +47,28 @@ module {:extern "DAST"} DAST {
| Newtype(Newtype)
| SynonymType(SynonymType)
| Datatype(Datatype)
{
function name(): Name {
match this {
case Module(m) => m.name
case Class(m) => m.name
case Trait(m) => m.name
case Newtype(m) => m.name
case SynonymType(m) => m.name
case Datatype(m) => m.name
}
}
function attributes(): seq<Attribute> {
match this {
case Module(m) => m.attributes
case Class(m) => m.attributes
case Trait(m) => m.attributes
case Newtype(m) => m.attributes
case SynonymType(m) => m.attributes
case Datatype(m) => m.attributes
}
}
}

datatype Type =
UserDefined(resolved: ResolvedType) |
Expand Down Expand Up @@ -127,7 +151,7 @@ module {:extern "DAST"} DAST {
typeArgs: seq<Type>,
kind: ResolvedTypeBase,
attributes: seq<Attribute>,
properMethods: seq<Ident>,
properMethods: seq<Name>,
extendedTypes: seq<Type>) {
function Replace(mapping: map<Type, Type>): ResolvedType {
ResolvedType(
Expand Down Expand Up @@ -175,7 +199,7 @@ module {:extern "DAST"} DAST {

datatype Field = Field(formal: Formal, defaultValue: Option<Expression>)

datatype Formal = Formal(name: Name, typ: Type, attributes: seq<Attribute>)
datatype Formal = Formal(name: VarName, typ: Type, attributes: seq<Attribute>)

datatype Method = Method(
isStatic: bool,
Expand All @@ -188,22 +212,22 @@ module {:extern "DAST"} DAST {
params: seq<Formal>,
body: seq<Statement>,
outTypes: seq<Type>,
outVars: Option<seq<Ident>>)
outVars: Option<seq<VarName>>)

datatype CallSignature = CallSignature(parameters: seq<Formal>)

datatype CallName =
CallName(name: Name, onType: Option<Type>, receiverArgs: Option<Formal>, signature: CallSignature) |
CallName(name: Name, onType: Option<Type>, receiverArg: Option<Formal>, receiverAsArgument: bool, signature: CallSignature) |
MapBuilderAdd | MapBuilderBuild | SetBuilderAdd | SetBuilderBuild

datatype Statement =
DeclareVar(name: Name, typ: Type, maybeValue: Option<Expression>) |
DeclareVar(name: VarName, typ: Type, maybeValue: Option<Expression>) |
Assign(lhs: AssignLhs, value: Expression) |
If(cond: Expression, thn: seq<Statement>, els: seq<Statement>) |
Labeled(lbl: string, body: seq<Statement>) |
While(cond: Expression, body: seq<Statement>) |
Foreach(boundName: Name, boundType: Type, over: Expression, body: seq<Statement>) |
Call(on: Expression, callName: CallName, typeArgs: seq<Type>, args: seq<Expression>, outs: Option<seq<Ident>>) |
Foreach(boundName: VarName, boundType: Type, over: Expression, body: seq<Statement>) |
Call(on: Expression, callName: CallName, typeArgs: seq<Type>, args: seq<Expression>, outs: Option<seq<VarName>>) |
Return(expr: Expression) |
EarlyReturn() |
Break(toLabel: Option<string>) |
Expand All @@ -216,8 +240,8 @@ module {:extern "DAST"} DAST {
}

datatype AssignLhs =
Ident(ident: Ident) |
Select(expr: Expression, field: Name) |
Ident(ident: VarName) |
Select(expr: Expression, field: VarName) |
Index(expr: Expression, indices: seq<Expression>)

datatype CollKind = Seq | Array | Map
Expand All @@ -244,14 +268,15 @@ module {:extern "DAST"} DAST {

datatype Expression =
Literal(Literal) |
Ident(name: Name) |
Ident(name: VarName) |
Companion(seq<Ident>, typeArgs: seq<Type>) |
ExternCompanion(seq<Ident>) |
Tuple(seq<Expression>) |
New(path: seq<Ident>, typeArgs: seq<Type>, args: seq<Expression>) |
NewUninitArray(dims: seq<Expression>, typ: Type) |
ArrayIndexToInt(value: Expression) |
FinalizeNewArray(value: Expression, typ: Type) |
DatatypeValue(datatypeType: ResolvedType, typeArgs: seq<Type>, variant: Name, isCo: bool, contents: seq<(string, Expression)>) |
DatatypeValue(datatypeType: ResolvedType, typeArgs: seq<Type>, variant: Name, isCo: bool, contents: seq<(VarName, Expression)>) |
Convert(value: Expression, from: Type, typ: Type) |
SeqConstruct(length: Expression, elem: Expression) |
SeqValue(elements: seq<Expression>, typ: Type) |
Expand All @@ -270,23 +295,25 @@ module {:extern "DAST"} DAST {
ArrayLen(expr: Expression, exprType: Type, dim: nat, native: bool) |
MapKeys(expr: Expression) |
MapValues(expr: Expression) |
Select(expr: Expression, field: Name, isConstant: bool, onDatatype: bool, fieldType: Type) |
SelectFn(expr: Expression, field: Name, onDatatype: bool, isStatic: bool, arity: nat) |
MapItems(expr: Expression) |
Select(expr: Expression, field: VarName, isConstant: bool, onDatatype: bool, fieldType: Type) |
SelectFn(expr: Expression, field: VarName, onDatatype: bool, isStatic: bool, isConstant: bool, arguments: seq<Type>) |
Index(expr: Expression, collKind: CollKind, indices: seq<Expression>) |
IndexRange(expr: Expression, isArray: bool, low: Option<Expression>, high: Option<Expression>) |
TupleSelect(expr: Expression, index: nat, fieldType: Type) |
Call(on: Expression, callName: CallName, typeArgs: seq<Type>, args: seq<Expression>) |
Lambda(params: seq<Formal>, retType: Type, body: seq<Statement>) |
BetaRedex(values: seq<(Formal, Expression)>, retType: Type, expr: Expression) |
IIFE(ident: Ident, typ: Type, value: Expression, iifeBody: Expression) |
IIFE(ident: VarName, typ: Type, value: Expression, iifeBody: Expression) |
Apply(expr: Expression, args: seq<Expression>) |
TypeTest(on: Expression, dType: seq<Ident>, variant: Name) |
Is(expr: Expression, fromType: Type, toType: Type) |
InitializationValue(typ: Type) |
BoolBoundedPool() |
SetBoundedPool(of: Expression) |
MapBoundedPool(of: Expression) |
SeqBoundedPool(of: Expression, includeDuplicates: bool) |
IntRange(lo: Expression, hi: Expression, up: bool) |
IntRange(elemType: Type, lo: Expression, hi: Expression, up: bool) |
UnboundedIntRange(start: Expression, up: bool) |
Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression)

Expand Down
12 changes: 8 additions & 4 deletions Source/DafnyCore/Backends/Dafny/ASTBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void AddUnsupported(string why) {
interface ModuleContainer : Container {
void AddModule(Module item);

public ModuleBuilder Module(string name, Sequence<Attribute> attributes) {
return new ModuleBuilder(this, name, attributes);
public ModuleBuilder Module(string name, Sequence<Attribute> attributes, bool requiresExterns) {
return new ModuleBuilder(this, name, attributes, requiresExterns);
}

static public Module UnsupportedToModule(string why) {
return new Module(Sequence<Rune>.UnicodeFromString(why), Sequence<Attribute>.FromElements((Attribute)Attribute.create_Attribute(
Sequence<Rune>.UnicodeFromString(why), Sequence<Sequence<Rune>>.Empty)),
Sequence<Rune>.UnicodeFromString(why), Sequence<Sequence<Rune>>.Empty)), false,
Std.Wrappers.Option<Sequence<ModuleItem>>.create_None());
}
}
Expand All @@ -51,11 +51,13 @@ class ModuleBuilder : ClassContainer, TraitContainer, NewtypeContainer, Datatype
readonly string name;
readonly Sequence<Attribute> attributes;
readonly List<ModuleItem> body = new();
private readonly bool requiresExterns;

public ModuleBuilder(ModuleContainer parent, string name, Sequence<Attribute> attributes) {
public ModuleBuilder(ModuleContainer parent, string name, Sequence<Attribute> attributes, bool requiresExterns) {
this.parent = parent;
this.name = name;
this.attributes = attributes;
this.requiresExterns = requiresExterns;
}

public void AddModule(Module item) {
Expand All @@ -82,6 +84,7 @@ public object Finish() {
parent.AddModule((Module)Module.create(
Sequence<Rune>.UnicodeFromString(this.name),
attributes,
requiresExterns,
Std.Wrappers.Option<Sequence<ModuleItem>>.create_Some((Sequence<ModuleItem>)Sequence<ModuleItem>.FromArray(body.ToArray()))
));

Expand Down Expand Up @@ -1834,6 +1837,7 @@ public DAST.Expression Build() {
}

return (DAST.Expression)DAST.Expression.create_IntRange(
DAST.Type.create_Primitive(DAST.Primitive.create_Int()),
startExpr, endExpr, true);
}

Expand Down
Loading
Loading