Skip to content

Commit fc9a9e6

Browse files
committed
[GR-38632] [GR-31236] [GR-17176] Fix SL parser and add gate checks for generating parsers and for TODOs.
PullRequest: graal/11728
2 parents 340293c + 3087786 commit fc9a9e6

File tree

30 files changed

+99
-517
lines changed

30 files changed

+99
-517
lines changed

truffle/external_repos/simplelanguage/generate_parser.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@
4040
# SOFTWARE.
4141
#
4242

43-
curl -O https://www.antlr.org/download/antlr-4.7.1-complete.jar
44-
java -cp antlr-4.7.1-complete.jar org.antlr.v4.Tool -package com.oracle.truffle.sl.parser -no-listener language/src/main/java/com/oracle/truffle/sl/parser/SimpleLanguage.g4
43+
curl -O https://www.antlr.org/download/antlr-4.9.2-complete.jar
44+
java -cp antlr-4.9.2-complete.jar org.antlr.v4.Tool -package com.oracle.truffle.sl.parser -no-listener language/src/main/java/com/oracle/truffle/sl/parser/SimpleLanguage.g4

truffle/mx.truffle/mx_truffle.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def _truffle_gate_runner(args, tasks):
256256
with Task('Truffle DSL max state bit tests', tasks) as t:
257257
if t:
258258
_truffle_gate_state_bitwidth_tests()
259+
with Task('Validate parsers', tasks) as t:
260+
if t: validate_parsers()
259261

260262
# The Truffle DSL specialization state bit width computation is complicated and
261263
# rarely used as the default maximum bit width of 32 is rarely exceeded. Therefore
@@ -680,6 +682,30 @@ def create_parser(grammar_project, grammar_package, grammar_name, copyright_temp
680682
with open(filename, 'w') as content_file:
681683
content_file.write(content)
682684

685+
def validate_parsers(args=None, out=None):
686+
validate_parser("com.oracle.truffle.sl", "com/oracle/truffle/sl/parser/SimpleLanguage.g4", create_sl_parser)
687+
validate_parser("com.oracle.truffle.dsl.processor", "com/oracle/truffle/dsl/processor/expression/Expression.g4", create_dsl_parser)
688+
689+
def validate_parser(grammar_project, grammar_path, create_command, args=None, out=None):
690+
def read_file(path):
691+
with open(path, "r") as f:
692+
return f.readlines()
693+
parser_path = grammar_path.replace(".g4", "Parser.java")
694+
lexer_path = grammar_path.replace(".g4", "Lexer.java")
695+
parser = mx.project(grammar_project).source_dirs()[0] + "/" + parser_path
696+
lexer = mx.project(grammar_project).source_dirs()[0] + "/" + lexer_path
697+
parser_before = read_file(parser)
698+
lexer_before = read_file(lexer)
699+
create_command([], out)
700+
parser_after = read_file(parser)
701+
lexer_after = read_file(lexer)
702+
if (parser_before != parser_after or lexer_before != lexer_after):
703+
with open(parser, "w") as f:
704+
f.writelines(parser_before)
705+
with open(lexer, "w") as f:
706+
f.writelines(lexer_before)
707+
mx.abort("Parser generated from " + grammar_path + " does not match content of " + parser_path + " or " + lexer_path + "." +
708+
" Make sure the grammar files are up to date with the generated code. You can regenerate the generated code using mx.")
683709

684710
class LibffiBuilderProject(mx.AbstractNativeProject, mx_native.NativeDependency): # pylint: disable=too-many-ancestors
685711
"""Project for building libffi from source.

truffle/mx.truffle/suite.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
"mx:JUNIT",
337337
"sdk:POLYGLOT_TCK"
338338
],
339-
"checkstyle" : "com.oracle.truffle.sl",
339+
"checkstyle" : "com.oracle.truffle.api",
340340
"javaCompliance" : "11+",
341341
"workingSets" : "SimpleLanguage,Test",
342342
"jacoco" : "exclude",
@@ -872,7 +872,7 @@
872872
"jdk.unsupported", # GR-36880
873873
],
874874
"javaCompliance" : "11+",
875-
"checkstyleVersion" : "8.36.1",
875+
"checkstyle" : "com.oracle.truffle.api",
876876
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
877877
"workingSets" : "Truffle,SimpleLanguage",
878878
},
@@ -883,7 +883,7 @@
883883
"dependencies" : [
884884
"sdk:GRAAL_SDK",
885885
],
886-
"checkstyle" : "com.oracle.truffle.sl",
886+
"checkstyle" : "com.oracle.truffle.api",
887887
"javaCompliance" : "11+",
888888
"workingSets" : "Truffle,SimpleLanguage",
889889
},
@@ -899,7 +899,7 @@
899899
"requires" : [
900900
"java.logging",
901901
],
902-
"checkstyle" : "com.oracle.truffle.sl",
902+
"checkstyle" : "com.oracle.truffle.api",
903903
"javaCompliance" : "11+",
904904
"workingSets" : "Truffle,SimpleLanguage,Test",
905905
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR", "mx:JMH_1_21"],
@@ -927,9 +927,9 @@
927927
"com.oracle.truffle.st"
928928
],
929929
"javaCompliance" : "11+",
930-
"checkstyleVersion" : "8.36.1",
930+
"checkstyle" : "com.oracle.truffle.api",
931931
"annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR"],
932-
"workingSets" : "Truffle,SimpleLanguage",
932+
"workingSets" : "Truffle",
933933
"testProject" : True,
934934
"jacoco" : "exclude",
935935
},

truffle/src/com.oracle.truffle.api.debug/src/com/oracle/truffle/api/debug/Debugger.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,18 @@ public static Debugger find(TruffleLanguage.Env env) {
349349
static final class AccessorDebug extends Accessor {
350350

351351
/*
352-
* TODO get rid of this access and replace it with an API in {@link TruffleInstrument.Env}.
353-
* I don't think {@link CallTarget} is the right return type here as we want to make it
354-
* embeddable into the current AST.
352+
* TODO GR-38632 get rid of this access and replace it with an API in {@link
353+
* TruffleInstrument.Env}. I don't think {@link CallTarget} is the right return type here as
354+
* we want to make it embeddable into the current AST.
355355
*/
356356
protected CallTarget parse(Source code, Node context, String... argumentNames) {
357357
RootNode rootNode = context.getRootNode();
358358
return languageSupport().parse(engineSupport().getEnvForInstrument(rootNode.getLanguageInfo()), code, context, argumentNames);
359359
}
360360

361361
/*
362-
* TODO I initially moved this to TruffleInstrument.Env but decided against as a new API for
363-
* inline parsing might replace it.
362+
* TODO GR-38632 I initially moved this to TruffleInstrument.Env but decided against as a
363+
* new API for inline parsing might replace it.
364364
*/
365365
protected Object evalInContext(Source source, Node node, MaterializedFrame frame) {
366366
return languageSupport().evalInContext(source, node, frame);

truffle/src/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ abstract static class ImplicitCastTypedExecuteNode extends Node {
135135

136136
public abstract Object execute(int value);
137137

138-
// TODO: this should not be an error
138+
// TODO:GR-38632 this should not be an error
139139
@ExpectError("Method signature (boolean) does not match to the expected signature: %")
140140
@Specialization
141141
public boolean op1(boolean value) {
@@ -192,7 +192,7 @@ public void testImplicitCast1() {
192192

193193
@TypeSystemReference(ImplicitCast0Types.class)
194194
@NodeChildren({@NodeChild(value = "operand0", type = ImplicitCast2Node.class), @NodeChild(value = "operand1", type = ImplicitCast2Node.class, executeWith = "operand0")})
195-
// TODO temporary workaround
195+
// TODO GR-38632 temporary workaround
196196
abstract static class ImplicitCast2Node extends ValueNode {
197197

198198
@Specialization

truffle/src/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SharedCachedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
@SuppressWarnings("unused")
6060
public class SharedCachedTest {
6161

62-
// TODO how to share primitive caches? maybe through a specialization class?
62+
// TODO GR-38632 how to share primitive caches? maybe through a specialization class?
6363
abstract static class UnboundCachedPrimitiveNode extends Node {
6464

6565
abstract Object execute(Object arg);

truffle/src/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void afterExecution(TestRootNode<? extends ValueNode> node, int index, Ob
123123
});
124124
}
125125

126-
/* TODO assert falltrough do1 before do2 */
126+
/* TODO GR-38632 assert falltrough do1 before do2 */
127127
@NodeChildren({@NodeChild("a")})
128128
static class FallthroughTest1 extends ValueNode {
129129

truffle/src/com.oracle.truffle.api.library.test/src/com/oracle/truffle/api/library/test/ReflectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void testReflectionOnObject() throws Exception {
141141

142142
Message primitive = Message.resolve(ReflectionTestLibrary.class, "primitive");
143143

144-
// TODO more tests necessary
144+
// TODO GR-38632 more tests necessary
145145

146146
Assert.assertEquals(11, (int) reflection.send(object, primitive, 11));
147147

truffle/src/com.oracle.truffle.api.library.test/src/com/oracle/truffle/api/library/test/examples/ReflectiveExportExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Object send(Message message, Object[] args) throws Exception {
8282
if (message == MESSAGE) {
8383
return "reflectiveExport";
8484
} else {
85-
// TODO how to invoke the super implementation?
85+
// TODO GR-38632 how to invoke the super implementation?
8686
throw new AbstractMethodError();
8787
}
8888
}
@@ -99,7 +99,7 @@ public void runExample() throws Exception {
9999
try {
100100
assertEquals("message1", library.message1(value));
101101
} catch (AbstractMethodError e) {
102-
// TODO currently throws abstract method error but should return default value
102+
// TODO GR-38632 currently throws abstract method error but should return default value
103103
// "message1".
104104
}
105105
}

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/host/TestMemberAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public void testOverloadedConstructor2() throws InteropException {
422422
testObj = (TruffleObject) INTEROP.instantiate(testClass, (short) 42);
423423
assertEquals(int.class.getName(), INTEROP.readMember(testObj, "ctor"));
424424
testObj = (TruffleObject) INTEROP.instantiate(testClass, 4.2f);
425-
// TODO prioritize conversion from double to float over double to int
425+
// TODO GR-38632 prioritize conversion from double to float over double to int
426426
// assertEquals(float.class.getName(), INTEROP.readMember(testObj, "ctor"));
427427
}
428428

0 commit comments

Comments
 (0)