Skip to content

Commit 83833fc

Browse files
committed
Reading global variable is in general not SideEffectFree
* Global variables can have hooks with rb_define_hooked_variable() and can do arbitrary things. * $! (and $ERROR_INFO and $@) can access the backtrace of the exception, so they are not safe for the BACKTRACES_OMIT_UNUSED optimization.
1 parent 276dbde commit 83833fc

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,11 +2840,7 @@ public RubyNode visitRescueNode(RescueParseNode node) {
28402840
boolean canOmitBacktrace = false;
28412841

28422842
if (context.getOptions().BACKTRACES_OMIT_UNUSED && rescueBody != null &&
2843-
rescueBody.getBodyNode() instanceof SideEffectFree /* allow `expression rescue $!` pattern */ &&
2844-
(!(rescueBody.getBodyNode() instanceof GlobalVarParseNode) ||
2845-
(!((GlobalVarParseNode) rescueBody.getBodyNode()).getName().equals("$!") &&
2846-
!((GlobalVarParseNode) rescueBody.getBodyNode()).getName().equals("$ERROR_INFO"))) &&
2847-
rescueBody.getOptRescueNode() == null) {
2843+
rescueBody.getBodyNode() instanceof SideEffectFree && rescueBody.getOptRescueNode() == null) {
28482844
canOmitBacktrace = true;
28492845
}
28502846

src/main/java/org/truffleruby/parser/ast/GlobalVarParseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* access to a global variable.
4242
*/
43-
public class GlobalVarParseNode extends ParseNode implements INameNode, SideEffectFree {
43+
public class GlobalVarParseNode extends ParseNode implements INameNode {
4444
private String name;
4545

4646
public GlobalVarParseNode(SourceIndexLength position, String name) {

0 commit comments

Comments
 (0)