Skip to content

Commit 113d65c

Browse files
committed
Adopt specs to pass with different options and optimisations enabled
1 parent afced5d commit 113d65c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

spec/truffle/parsing/parsing_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# truffleruby_primitives: true
2+
13
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -63,6 +65,25 @@
6365
raise "The file #{filename} wasn't updated with actual AST"
6466
end
6567
else
68+
# the multi-context mode introduces some changes in the AST:
69+
# - static lexical scopes aren't set
70+
# - ReadConstantWithLexicalScopeNode is used instead of ReadConstantWithLexicalScopeNode
71+
# - ReadClassVariableNode.lexicalScopeNode is GetDynamicLexicalScopeNode instead of (ObjectLiteralNode object = :: Object)
72+
# - WriteConstantNode.moduleNode uses DynamicLexicalScopeNode instead of (LexicalScopeNode lexicalScope = :: Object)
73+
# - WriteClassVariableNode.lexicalScopeNode uses GetDynamicLexicalScopeNode instead of (LexicalScopeNode lexicalScope = :: Object)
74+
if !Primitive.vm_single_context? &&
75+
expected_ast.include?("staticLexicalScope") ||
76+
expected_ast.include?("ReadConstantWithLexicalScopeNode") ||
77+
expected_ast.include?("ReadClassVariableNode") ||
78+
expected_ast.include?("WriteConstantNode") ||
79+
expected_ast.include?("WriteClassVariableNode")
80+
skip "Static lexical scopes are never set in multi context mode"
81+
end
82+
83+
if TruffleRuby.jit?
84+
skip "Don't run parsing specs when JIT is enabled because it affects AST"
85+
end
86+
6687
# actual test check
6788
actual_ast.should == expected_ast.strip
6889
end

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,13 @@ protected long argvLength() {
658658
}
659659
}
660660

661+
@Primitive(name = "vm_single_context?")
662+
public abstract static class VMSingleContext extends PrimitiveArrayArgumentsNode {
663+
664+
@Specialization
665+
protected boolean singleContext() {
666+
return isSingleContext();
667+
}
668+
}
669+
661670
}

src/main/java/org/truffleruby/debug/TruffleASTPrinter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434

3535
public abstract class TruffleASTPrinter {
3636

37-
private static final Set<String> attributesToIgnore = Set.of("sourceCharIndex", "sourceLength");
37+
// Skip the following node attributes:
38+
// - "sourceCharIndex", "sourceLength" - are incorrect and will have correct values in YARP
39+
// - "RubyRootNode.bodyCopy" - is set if clone-uninitialized is forced
40+
private static final Set<String> attributesToIgnore = Set.of("sourceCharIndex", "sourceLength", "bodyCopy");
3841

3942
public static String dump(RubyRootNode rootNode, String focusedNodeClassName, int index) {
4043
final Node node;

0 commit comments

Comments
 (0)