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

Adjusting tests to new parser #6143

Merged
merged 26 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
225f46a
(f _ _ b) b is application of a function
JaroslavTulach Mar 30, 2023
8f9e3c5
No IR.Expression.Binding for (f a = a)
JaroslavTulach Mar 30, 2023
864ad0f
Handle missing body in method declaration
JaroslavTulach Mar 30, 2023
d64680d
_ = ... binding yields different IR with the new parser using f = ...
JaroslavTulach Mar 30, 2023
a04b754
The annotations don't seem to be easily fixable on the IR side
JaroslavTulach Mar 30, 2023
6b264b6
Unexpected type signature
JaroslavTulach Mar 30, 2023
1043365
f a : Double makes no sense
JaroslavTulach Mar 30, 2023
53e353a
Avoid analysis of syntax error statements
JaroslavTulach Mar 30, 2023
f18b1cd
Bugfixing DataflowAnalysisTest
JaroslavTulach Mar 30, 2023
d663e1c
Merge branch 'develop' into wip/jtulach/CompilerTestsUpdate_5894
JaroslavTulach Mar 30, 2023
ecf3b9b
Skip further checks if the expression is marked as an error
JaroslavTulach Mar 30, 2023
b99e9df
@Tail_Call without arguments yields an IR.Error.Resolution
JaroslavTulach Mar 31, 2023
5fa45df
Merge branch 'develop' into wip/jtulach/CompilerTestsUpdate_5894
JaroslavTulach Mar 31, 2023
d880d7e
Link #6152 issue from the test
JaroslavTulach Mar 31, 2023
7616696
TypeAscription has to be ahead of function even in translateInline mode
JaroslavTulach Mar 31, 2023
92e74e7
a : _ is a Type.Ascription
JaroslavTulach Apr 1, 2023
71b5fc3
Dedicated issue #6165 for SugaredTypeFunctionsTest
JaroslavTulach Apr 1, 2023
0dbe636
SuspendedArgumentsTest works fully with the new parser
JaroslavTulach Apr 1, 2023
55c4002
Adjusting SugaredTypeFunctionsTest to us understanding _ : A now
JaroslavTulach Apr 1, 2023
487620f
Missing body yields an error
JaroslavTulach Apr 1, 2023
ea08bf0
Adjusting bounds in DataflowAnalysisTest
JaroslavTulach Apr 1, 2023
c108f39
Adjusting TypeSignaturesTest to the new parser
JaroslavTulach Apr 1, 2023
ceaecc8
No need to check for errors in "work properly for blocks" test
JaroslavTulach Apr 1, 2023
c402c21
Merge branch 'develop' into wip/jtulach/CompilerTestsUpdate_5894
mergify[bot] Apr 1, 2023
356d41f
Merge branch 'develop' into wip/jtulach/CompilerTestsUpdate_5894
mergify[bot] Apr 1, 2023
4eb1e5b
Merge branch 'develop' into wip/jtulach/CompilerTestsUpdate_5894
mergify[bot] Apr 1, 2023
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
76 changes: 45 additions & 31 deletions engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,21 @@ Option<IR.Expression> translateInline(Tree ast) {
for (Line statement : b.getStatements()) {
Tree exprTree = statement.getExpression();
IR.Expression expr = switch (exprTree) {
case null -> null;
case Tree.Export x -> null;
case Tree.Import x -> null;
case Tree.Invalid x -> null;
case null -> null;
case Tree.TypeSignature sig -> {
IR.Expression methodReference;
try {
methodReference = translateMethodReference(sig.getVariable(), true);
} catch (SyntaxException ex) {
methodReference = translateExpression(sig.getVariable());
}
var signature = translateType(sig.getType(), false);
var ascription = new IR$Type$Ascription(methodReference, signature, getIdentifiedLocation(sig), meta(), diag());
yield ascription;
}
default -> translateExpression(exprTree);
};
if (expr != null) {
Expand All @@ -125,37 +136,37 @@ Option<IR.Expression> translateInline(Tree ast) {
}
}
}
if (expressions.size() == 0) {
yield Option.empty();
} else if (expressions.size() == 1) {
yield Option.apply(expressions.apply(0));
} else {
Option<IdentifiedLocation> combinedLocation;
if (locations.isEmpty()) {
combinedLocation = Option.empty();
} else {
combinedLocation = Option.apply(
new IdentifiedLocation(
new Location(
locations.get(1).start(),
locations.get(locations.size() - 1).end()
),
Option.empty()
)
);
yield switch (expressions.size()) {
case 0 -> Option.empty();
case 1 -> Option.apply(expressions.head());
default -> {
Option<IdentifiedLocation> combinedLocation;
if (locations.isEmpty()) {
combinedLocation = Option.empty();
} else {
combinedLocation = Option.apply(
new IdentifiedLocation(
new Location(
locations.get(1).start(),
locations.get(locations.size() - 1).end()
),
Option.empty()
)
);
}
var returnValue = expressions.head();
@SuppressWarnings("unchecked")
var statements = ((List<IR.Expression>) expressions.tail()).reverse();
yield Option.apply(new IR$Expression$Block(
statements,
returnValue,
combinedLocation,
false,
meta(),
diag()
));
}

yield Option.apply(
new IR$Expression$Block(
expressions,
expressions.last(),
combinedLocation,
false,
meta(),
diag()
)
);
}
};
}
default -> {
throw new IllegalStateException();
Expand Down Expand Up @@ -523,6 +534,9 @@ private IR.Expression translateFunction(Tree fun, IR.Name name, java.util.List<A
getIdentifiedLocation(fun), meta(), diag()
);
} else {
if (body == null) {
return translateSyntaxError(fun, IR$Error$Syntax$UnexpectedDeclarationInType$.MODULE$);
}
return new IR$Function$Binding(name, args, body,
getIdentifiedLocation(fun), true, meta(), diag()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ case object OperatorToFunction extends IRPass {
inlineContext: InlineContext
): IR.Expression =
ir.transformExpressions {
case asc: IR.Type.Ascription => asc
case asc: IR.Type.Ascription =>
asc.copy(typed = runExpression(asc.typed, inlineContext))
case IR.Application.Operator.Binary(l, op, r, loc, passData, diag) =>
IR.Application.Prefix(
op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.enso.compiler.pass.resolve
import org.enso.compiler.context.{InlineContext, ModuleContext}
import org.enso.compiler.core.IR
import org.enso.compiler.core.ir.MetadataStorage.ToPair
import org.enso.compiler.exception.CompilerError
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.AliasAnalysis
import org.enso.compiler.pass.resolve.ModuleAnnotations.Annotations
Expand Down Expand Up @@ -79,8 +78,9 @@ case object ExpressionAnnotations extends IRPass {
if (isKnownAnnotation(ann.name)) {
arguments match {
case List() =>
throw new CompilerError(
"Impossible, application with no arguments."
IR.Error.Resolution(
ann,
IR.Error.Resolution.UnexpectedAnnotation
)
case List(arg) =>
doExpression(arg.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.enso.compiler;

import org.enso.compiler.core.IR$Error$Syntax;
import org.enso.compiler.core.IR$Error$Syntax$UnexpectedDeclarationInType$;
import org.enso.compiler.core.IR$Function$Binding;
import org.enso.compiler.core.IR$Module$Scope$Definition$Data;
import org.enso.compiler.core.IR$Module$Scope$Definition$SugaredType;
import org.enso.compiler.core.IR$Name$Annotation;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class AnnotationsCompilerTest extends CompilerTest {

Expand Down Expand Up @@ -88,10 +91,12 @@ public void testInvalidComplexType() throws Exception {
""");

var typeDefinition = (IR$Module$Scope$Definition$SugaredType) ir.bindings().apply(0);
var method = (IR$Function$Binding) typeDefinition.body().apply(0);
var methodOrError = typeDefinition.body().apply(0);

assertEquals(method.name().name(), "bar");
// FIXME method body is null. Should be `IR.Error.Syntax.UnexpectedDeclarationInType`
assertEquals(method.body(), null);
if (methodOrError instanceof IR$Error$Syntax error) {
assertEquals(error.reason(), IR$Error$Syntax$UnexpectedDeclarationInType$.MODULE$);
} else {
fail("Expecting error instead of bar function: " + methodOrError);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,7 @@ class AliasAnalysisTest extends CompilerTest {
}
}

"Alias analysis on typeset literals" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"Alias analysis on typeset literals" should {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
implicit val ctx: ModuleContext = mkModuleContext

val method =
Expand All @@ -1238,12 +1237,16 @@ class AliasAnalysisTest extends CompilerTest {
val blockScope =
block.unsafeGetMetadata(AliasAnalysis, "").unsafeAs[Info.Scope.Child]

val literal = block.returnValue.asInstanceOf[IR.Application.Literal.Typeset]
val literalScope =
literal.unsafeGetMetadata(AliasAnalysis, "").unsafeAs[Info.Scope.Child]

"create a new scope for the literal" in {
blockScope.scope.childScopes should contain(literalScope.scope)
if (!block.returnValue.isInstanceOf[IR.Error.Syntax]) {
val literal =
block.returnValue.asInstanceOf[IR.Application.Literal.Typeset]
val literalScope =
literal
.unsafeGetMetadata(AliasAnalysis, "")
.unsafeAs[Info.Scope.Child]
blockScope.scope.childScopes should contain(literalScope.scope)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,7 @@ class DataflowAnalysisTest extends CompilerTest {
dependencies.getDirect(argXId) shouldEqual None
}

"work properly for blocks" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"work properly for blocks" in {
implicit val inlineContext: InlineContext = mkInlineContext

val ir =
Expand Down Expand Up @@ -1286,26 +1285,27 @@ class DataflowAnalysisTest extends CompilerTest {
dependencies.getDirect(vecId) shouldEqual Some(Set(xUseId, yId, litId))
}

"work properly for typeset literals" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"work properly for typeset literals" in {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
implicit val inlineContext: InlineContext = mkInlineContext

val ir =
"""
|{ x := a ; y := b }
|""".stripMargin.preprocessExpression.get.analyse

val depInfo = ir.getMetadata(DataflowAnalysis).get
if (!ir.isInstanceOf[IR.Error.Syntax]) {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
val depInfo = ir.getMetadata(DataflowAnalysis).get

val literal = ir.asInstanceOf[IR.Application.Literal.Typeset]
val literalExpression = literal.expression.get
val literal = ir.asInstanceOf[IR.Application.Literal.Typeset]
val literalExpression = literal.expression.get

val literalId = mkStaticDep(literal.getId)
val literalExpressionId = mkStaticDep(literalExpression.getId)
val literalId = mkStaticDep(literal.getId)
val literalExpressionId = mkStaticDep(literalExpression.getId)

depInfo.dependents.getDirect(literalExpressionId).get shouldEqual Set(
literalId
)
depInfo.dependents.getDirect(literalExpressionId).get shouldEqual Set(
literalId
)
}
}

"work properly for case expressions" in {
Expand Down Expand Up @@ -1463,18 +1463,25 @@ class DataflowAnalysisTest extends CompilerTest {
implicit val inlineContext: InlineContext = mkInlineContext

val meta = new Metadata
val lambdaId = meta.addItem(1, 59)
val aBindId = meta.addItem(10, 9)
val lambdaId = meta.addItem(1, 45, "aaaa")
val aBindId = meta.addItem(10, 9, "bbbb")

val code =
"""
|x ->
| a = x + 1
| b = State.read
| a+b . IO.println
| a+b
|""".stripMargin.linesIterator.mkString("\n")

val codeWithMeta = meta.appendToCode(code)
meta.assertInCode(
lambdaId,
"\n" + codeWithMeta,
code.substring(0, code.length() - 1)
)
meta.assertInCode(aBindId, codeWithMeta, "a = x + 1")

val ir = codeWithMeta.preprocessExpression.get.analyse
.asInstanceOf[IR.Function.Lambda]

Expand All @@ -1485,17 +1492,17 @@ class DataflowAnalysisTest extends CompilerTest {
.asInstanceOf[IR.Expression.Binding]
val aBindExpr = aBind.expression

"store a mapping between internal and external identifiers" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
metadata.dependents.get(asStatic(aBind)).get should contain(
"store a mapping between internal and external identifiers" in {
val b = asStatic(aBind)
val m = metadata.dependents.get(b)
m.get should contain(
asStatic(ir)
)

asStatic(ir).externalId shouldEqual Some(lambdaId)
}

"return the set of external identifiers for invalidation" ignore {
// FIXME: Different result in new parser!--needs triage (#5894).
"return the set of external identifiers for invalidation" in {
metadata.dependents.getExternal(asStatic(aBindExpr)).get shouldEqual Set(
lambdaId,
aBindId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ class ComplexTypeTest extends CompilerTest {
}
}

"Invalid complex types" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"Invalid complex types" should {
implicit val ctx: ModuleContext = mkModuleContext

val ir =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ class FunctionBindingTest extends CompilerTest {
cArg.defaultValue shouldBe defined
}

"work recursively" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"work recursively" in {
val ir =
"""
|f (a = (f a = a)) =
Expand All @@ -290,8 +289,12 @@ class FunctionBindingTest extends CompilerTest {
.asInstanceOf[IR.DefinitionArgument.Specified]
aArg.name.name shouldEqual "a"
aArg.defaultValue.get
.asInstanceOf[IR.Expression.Binding]
.name
.asInstanceOf[IR.Application.Operator.Binary]
.left
.value
.asInstanceOf[IR.Application.Prefix]
.function
.asInstanceOf[IR.Name.Literal]
.name shouldEqual "f"

val body = ir.expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,17 @@ class LambdaShorthandToLambdaTest extends CompilerTest {
lamArg1Name shouldEqual appArg1Name
}

"correctly translate the function in an application" ignore {
// FIXME: Not supported by new parser--needs triage (#5894).
"correctly translate the function in an application" in {
implicit val ctx: InlineContext = mkInlineContext

val ir =
"""(f _ _ b) b
|""".stripMargin.preprocessExpression.get.desugar

ir shouldBe an[IR.Function.Lambda]
val firstLam = ir.asInstanceOf[IR.Function.Lambda]
ir shouldBe an[IR.Application.Prefix]
val irFn = ir.asInstanceOf[IR.Application.Prefix].function
irFn shouldBe an[IR.Function.Lambda]
val firstLam = irFn.asInstanceOf[IR.Function.Lambda]
firstLam.arguments.length shouldEqual 1
val firstLamArgName = firstLam.arguments.head
.asInstanceOf[IR.DefinitionArgument.Specified]
Expand All @@ -555,7 +556,7 @@ class LambdaShorthandToLambdaTest extends CompilerTest {
.name
.name
val app = secondLam.body.asInstanceOf[IR.Application.Prefix]
app.arguments.length shouldEqual 4
app.arguments.length shouldEqual 3
val appArg1Name = app.arguments.head
.asInstanceOf[IR.CallArgument.Specified]
.value
Expand Down
Loading