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

Translation fixes for {:extern} when used for exports and for --test-assumptions=externs #5939

Merged
merged 17 commits into from
Nov 30, 2024

Conversation

keyboardDrummer
Copy link
Member

@keyboardDrummer keyboardDrummer commented Nov 28, 2024

Description

  • Fix incorrect translated code when using {:extern} to export members
  • Fix incorrect translated code when using --test-assumptions=externs

How has this been tested?

  • Add a CLI test

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@keyboardDrummer keyboardDrummer added the run-integration-tests Forces running the CI for integration tests even if the deep tests fail label Nov 28, 2024
@keyboardDrummer keyboardDrummer changed the title Fix export bugs Fix exporting {:extern} and --test-assumptions bugs Nov 28, 2024
@keyboardDrummer keyboardDrummer changed the title Fix exporting {:extern} and --test-assumptions bugs Translation fixes for {:extern} when used for exports and for --test-assumptions=externs Nov 28, 2024
Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, just some style/doc suggestions (and remove all the commented out code please :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of project files for tests :)

Type = newFunc.ResultType
};
var resultVar = origFunc.Result ?? new Formal(tok, "#result", origFunc.ResultType, false, false, null);
var localName = origFunc.Result?.Name ?? "__BLA__result";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLA?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an acronym for "believable left-hand-side alias", but I'll remove it since it's not well known

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's known to at least one more person now, so thank you for that :)

@@ -884,7 +884,7 @@ protected override string TypeName_UDT(string fullCompileName, List<TypeParamete
// We write an extern class as a base class that the actual extern class
// needs to extend, so the extern methods and functions need to be abstract
// in the base class
protected override bool IncludeExternMembers { get => true; }
protected override bool IncludeImportedMembers => true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using "ExternImported" rather than just "Imported" throughout, only because if we also start saying just "Exported" for the other direction, it will be easily confused with export sets.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment what's actually being tested here since it's not obvious. I think it's the fact that it previously didn't work because some extern-exported Dafny bodies were dropped.

I think you're also not actually testing the --test-assumptions fixes AFAICT? At a minimum you'd want to have a Dafny call to Builder that doesn't satisfy Pre.

@@ -1529,15 +1529,28 @@ public void Compile(Program program, ConcreteSyntaxTree wrx) {
EmitFooter(program, wrx);
}

protected (bool classIsExtern, bool included) GetIsExternAndIncluded(ClassLikeDecl cl) {

public bool IsImported(IAttributeBearingDeclaration me) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer IsExternallyImported since you made the other change, but could be changed in a future PR

Comment on lines -133 to -146
Statement callStmt;
if (origFunc.Result?.Name is null) {
var local = new LocalVariable(decl.RangeToken, localName, newFunc.ResultType, false);
local.type = newFunc.ResultType;
var locs = new List<LocalVariable> { local };
var varDeclStmt = new VarDeclStmt(decl.RangeToken, locs, new AssignStatement(decl.RangeToken, lhss, rhss) {
ResolvedStatements = new List<Statement>() { assignStmt }
});
localExpr.Var = local;
callStmt = varDeclStmt;
} else {
localExpr.Var = origFunc.Result;
callStmt = assignStmt;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely following why this logic became unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite writing the previous code, I don't understand well either, but this was conditional on origFunc.Result == null and above I do var resultVar = origFunc.Result ?? new Formal(tok, "#result", newFunc.ResultType, false, false, null); which handles the same thing.


var tok = f.ByMethodTok;
var resultVar = f.Result ?? new Formal(tok, "#result", f.ResultType, false, false, null);
// var resultVar = f.Result ?? new Formal(tok, "#result", f.ResultType, false, false, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// var resultVar = f.Result ?? new Formal(tok, "#result", f.ResultType, false, false, null);

Comment on lines +25 to +26
[Option("run-fails", HelpText = "Whether the running program should return a non-zero exit code")]
public bool RunShouldFail { get; set; } = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feature to add, but would strongly prefer --expect-exit-code instead, since we already have that option on for-each-resolver

Copy link
Member Author

@keyboardDrummer keyboardDrummer Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't pass in an exit code because I don't know what it will be. Dafny does not define what the exit code will be for programs that do not pass runtime contract checks. It could be different per target. All I know is that it won't be a success exit code.

I'm not inclined to let Define specify what the exit code will be for contract failures, because exit codes are not a scalable way of providing diagnostic information.

since we already have that option on for-each-resolver

That's the exit code that Dafny returns, which is also not specified AFAIK but at least it does not depend on target language runtimes. IMO this inconsistency is not confusing so we can keep it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair! I can live with this then.

@keyboardDrummer keyboardDrummer merged commit 34d068d into dafny-lang:master Nov 30, 2024
22 checks passed
@keyboardDrummer keyboardDrummer deleted the fixExportBugs branch December 1, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-integration-tests Forces running the CI for integration tests even if the deep tests fail
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants