-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-17457] Remove loop in special variable lookup
PullRequest: truffleruby/3949
- Loading branch information
Showing
13 changed files
with
142 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/org/truffleruby/parser/BlockDescriptorInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 2.0, or | ||
* GNU General Public License version 2, or | ||
* GNU Lesser General Public License version 2.1. | ||
*/ | ||
package org.truffleruby.parser; | ||
|
||
import com.oracle.truffle.api.Assumption; | ||
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; | ||
import com.oracle.truffle.api.frame.FrameDescriptor; | ||
import com.oracle.truffle.api.nodes.ExplodeLoop; | ||
import org.truffleruby.language.threadlocal.SpecialVariableStorage; | ||
|
||
/** This is the {@link FrameDescriptor#getInfo() descriptor info} for blocks. The descriptor info for methods is an | ||
* {@link SpecialVariableStorage#getAssumption(FrameDescriptor) Assumption}. */ | ||
public final class BlockDescriptorInfo { | ||
|
||
@ExplodeLoop | ||
public static FrameDescriptor getDeclarationFrameDescriptor(FrameDescriptor topDescriptor, int depth) { | ||
assert depth > 0; | ||
FrameDescriptor descriptor = topDescriptor; | ||
for (int i = 0; i < depth; i++) { | ||
descriptor = ((BlockDescriptorInfo) descriptor.getInfo()).getParentDescriptor(); | ||
} | ||
return descriptor; | ||
} | ||
|
||
@CompilationFinal private FrameDescriptor parentDescriptor; | ||
private final Assumption specialVariableAssumption; | ||
|
||
public BlockDescriptorInfo(Assumption specialVariableAssumption) { | ||
assert SpecialVariableStorage.isSpecialVariableAssumption(specialVariableAssumption); | ||
this.specialVariableAssumption = specialVariableAssumption; | ||
} | ||
|
||
public BlockDescriptorInfo(FrameDescriptor parentDescriptor) { | ||
this.parentDescriptor = parentDescriptor; | ||
this.specialVariableAssumption = getSpecialVariableAssumptionFromDescriptor(parentDescriptor); | ||
} | ||
|
||
private Assumption getSpecialVariableAssumptionFromDescriptor(FrameDescriptor descriptor) { | ||
if (descriptor.getInfo() instanceof BlockDescriptorInfo blockDescriptorInfo) { | ||
return blockDescriptorInfo.getSpecialVariableAssumption(); | ||
} else { | ||
return SpecialVariableStorage.getAssumption(descriptor); | ||
} | ||
} | ||
|
||
public FrameDescriptor getParentDescriptor() { | ||
assert parentDescriptor != null; | ||
return parentDescriptor; | ||
} | ||
|
||
void setParentDescriptor(FrameDescriptor parentDescriptor) { | ||
assert this.parentDescriptor == null; | ||
this.parentDescriptor = parentDescriptor; | ||
} | ||
|
||
public Assumption getSpecialVariableAssumption() { | ||
assert specialVariableAssumption != null; | ||
return specialVariableAssumption; | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
src/main/java/org/truffleruby/parser/ParentFrameDescriptor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.