Skip to content

[PEx] Disable support for receive statement inside loop #843

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Src/PCompiler/CompilerCore/Backend/PEx/PExCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private CompiledFile GenerateSource(CompilationContext context, Scope globalScop

//context.WriteLine(source.Stream);

IEnumerable<IPDecl> decls = TransformASTPass.GetTransformedDecls(globalScope);
IEnumerable<IPDecl> decls = TransformASTPass.GetTransformedDecls(context, globalScope);
//IEnumerable<IPDecl> decls = globalScope.AllDecls;

var hasSafetyTest = false;
Expand Down
17 changes: 10 additions & 7 deletions Src/PCompiler/CompilerCore/Backend/PEx/TransformASTPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ namespace Plang.Compiler.Backend.PEx;

internal class TransformASTPass
{
private static CompilationContext context;
private static int continuationNumber;
private static int whileNumber;
private static int callNum;

public static List<IPDecl> GetTransformedDecls(Scope globalScope)
public static List<IPDecl> GetTransformedDecls(CompilationContext globalContext, Scope globalScope)
{
context = globalContext;
continuationNumber = 0;
callNum = 0;
var decls = new List<IPDecl>();
Expand Down Expand Up @@ -124,7 +126,7 @@ private static State TransformState(State state, IDictionary<Function, Function>
{
if (handler.Key.IsNullEvent)
throw new NotImplementedException(
$"Null events are not supported, found in state {transformedState.Name} of machine {transformedState.OwningMachine.Name}");
$"{context.LocationResolver.GetLocation(handler.Key.SourceLocation)}: Null events are not supported in this mode.");
transformedState[handler.Key] = TransformAction(handler.Value, functionMap);
}

Expand Down Expand Up @@ -249,7 +251,7 @@ private static List<IPStmt> ReplaceReturn(IReadOnlyList<IPStmt> body, IPExpr loc
{
if (CanReturn(entry.Value.Body))
{
throw new NotImplementedException($"Function with a return statement inside a receive-case isn't supported. Found in {func.Name}.");
throw new NotImplementedException($"{context.LocationResolver.GetLocation(entry.Value.SourceLocation)}: Function with a return statement inside a receive-case isn't supported in this mode.");
}

entry.Value.Body = new CompoundStmt(entry.Value.Body.SourceLocation,
Expand All @@ -262,7 +264,7 @@ private static List<IPStmt> ReplaceReturn(IReadOnlyList<IPStmt> body, IPExpr loc
case WhileStmt whileStmt:
if (CanReturn(whileStmt.Body))
{
throw new NotImplementedException($"Function with a return statement inside a loop isn't supported. Found in {func.Name}.");
throw new NotImplementedException($"{context.LocationResolver.GetLocation(whileStmt.SourceLocation)}: Function with a return statement inside a loop isn't supported in this mode.");
}

var bodyList = new List<IPStmt>();
Expand Down Expand Up @@ -546,7 +548,7 @@ private static Function TransformFunction(Function function, Machine machine)
{
if (!function.CanReceive) return function;
if (machine == null)
throw new NotImplementedException($"Async functions {function.Name} are not supported");
throw new NotImplementedException($"{context.LocationResolver.GetLocation(function.SourceLocation)}: Async functions are not supported in this mode.");
var transformedFunction = new Function(function.Name, function.SourceLocation);
transformedFunction.Owner = function.Owner;
transformedFunction.ParentFunction = function.ParentFunction;
Expand Down Expand Up @@ -687,7 +689,7 @@ private static IPStmt HandleReceives(IPStmt statement, Function function, Machin
{
if (c.Key.IsNullEvent)
throw new NotImplementedException(
$"Null events are not supported, found in a receive statement of machine {machine.Name}");
$"{context.LocationResolver.GetLocation(c.Key.SourceLocation)}: Null events in a receive statement are not supported in this mode.");
if (c.Value.CanReceive)
{
canReceiveInCase = true;
Expand Down Expand Up @@ -772,7 +774,8 @@ private static IPStmt HandleReceives(IPStmt statement, Function function, Machin
case WhileStmt loop:
if (CanReceive(loop.Body))
{
// throw new NotImplementedException($"Receive in a while statement is not yet supported, found in {machine.Name}");
throw new NotImplementedException(
$"{context.LocationResolver.GetLocation(loop.SourceLocation)}: Receive in a loop body is not supported in this mode. Suggestion: convert the loop into a recursion.");
// turn the while statement into a recursive function
var whileName = $"while_{whileNumber}";
whileNumber++;
Expand Down
15 changes: 14 additions & 1 deletion Src/PCompiler/CompilerCore/Compiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -64,7 +66,18 @@ public int Compile(ICompilerConfiguration job)
job.Output.WriteInfo($"Code generation for {entry}...");

// Run the selected backend on the project and write the files.
var compiledFiles = job.Backend.GenerateCode(job, scope);
IEnumerable<CompiledFile> compiledFiles;
try
{
compiledFiles = job.Backend.GenerateCode(job, scope);
}
catch (NotImplementedException e)
{
job.Output.WriteError("[NotImplementedError:]\n" + e.Message);
Environment.ExitCode = 1;
return Environment.ExitCode;
}

foreach (var file in compiledFiles)
{
job.Output.WriteInfo($"Generated {file.FileName}.");
Expand Down
10 changes: 10 additions & 0 deletions Src/PRuntimes/PExRuntime/src/test/java/pex/TestPEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ private static void setRunArgs() {
}

private static void createExcludeList() {
/**
* TODO: Receive statement inside a loop
*/
excluded.add("../../../Tst/RegressionTests/Feature2Stmts/DynamicError/pingPongReceive4");
excluded.add("../../../Tst/RegressionTests/Feature2Stmts/DynamicError/pingPongReceive5");
excluded.add("../../../Tst/RegressionTests/Feature2Stmts/Correct/receive19");
excluded.add("../../../Tst/RegressionTests/Feature2Stmts/Correct/pingPongReceive4");
excluded.add("../../../Tst/RegressionTests/Feature2Stmts/Correct/pingPongReceive5");
excluded.add("../../../Tst/RegressionTests/Integration/Correct/pingPongReceive3");

/**
* TODO: Null events
*/
Expand Down
Loading