-
Notifications
You must be signed in to change notification settings - Fork 317
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
Make suspended atom fields work for boxed atoms #8712
Changes from all commits
4aa19cc
c227a5b
9bc1af4
597599a
22f22ae
b543c7c
bb6116b
4b3e245
7146ee8
6d890de
7ff995e
580c3d8
03ed29e
85c396f
d433218
561d8be
8675747
f8d8a98
1d8bd1a
95cece3
afa9ad2
97ef02e
fbfc319
57fdd05
a28daff
b6a1c2a
0c5955a
fff48c5
2fe3a87
08df824
6bb2725
33e79e1
a5b169c
3addd39
2eee9fa
d62e6b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package org.enso.interpreter.node.controlflow.caseexpr; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | ||
import com.oracle.truffle.api.RootCallTarget; | ||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.nodes.ExplodeLoop; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import com.oracle.truffle.api.profiles.CountingConditionProfile; | ||
import org.enso.interpreter.runtime.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.callable.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.callable.atom.StructsLibrary; | ||
import org.enso.interpreter.runtime.data.atom.Atom; | ||
import org.enso.interpreter.runtime.data.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.data.atom.StructsLibrary; | ||
|
||
/** An implementation of the case expression specialised to working on constructors. */ | ||
@NodeInfo(shortName = "ConstructorMatch") | ||
|
@@ -36,15 +40,38 @@ public static ConstructorBranchNode build( | |
|
||
@Specialization | ||
void doAtom( | ||
VirtualFrame frame, | ||
Object state, | ||
Atom target, | ||
@CachedLibrary(limit = "10") StructsLibrary structs) { | ||
VirtualFrame frame, Object state, Atom target, @Cached FieldsAsArrayNode toArrayNode) { | ||
if (profile.profile(matcher == target.getConstructor())) { | ||
accept(frame, state, structs.getFields(target)); | ||
var arr = toArrayNode.executeFields(target); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
accept(frame, state, arr); | ||
} | ||
} | ||
|
||
@Fallback | ||
void doFallback(VirtualFrame frame, Object state, Object target) {} | ||
|
||
abstract static class FieldsAsArrayNode extends Node { | ||
abstract Object[] executeFields(Atom target); | ||
|
||
@Specialization( | ||
limit = "3", | ||
guards = {"atom.getConstructor() == cons"}) | ||
@ExplodeLoop | ||
Object[] fieldsFromAtomCached( | ||
Atom atom, | ||
@Cached("atom.getConstructor()") AtomConstructor cons, | ||
@CachedLibrary(limit = "3") StructsLibrary structs) { | ||
var arr = new Object[cons.getArity()]; | ||
for (var i = 0; i < arr.length; i++) { | ||
arr[i] = structs.getField(atom, i); | ||
} | ||
return arr; | ||
} | ||
|
||
@Specialization | ||
@TruffleBoundary | ||
Object[] fieldsFromAtomUncached(Atom atom) { | ||
return fieldsFromAtomCached(atom, atom.getConstructor(), StructsLibrary.getUncached()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import java.util.List; | ||
import org.enso.interpreter.runtime.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.callable.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.data.atom.Atom; | ||
import org.enso.interpreter.runtime.data.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.data.atom.AtomNewInstanceNode; | ||
|
||
public abstract class UniquelyConstructibleBuiltin extends Builtin { | ||
private @CompilerDirectives.CompilationFinal AtomConstructor uniqueConstructor; | ||
|
@@ -29,6 +30,6 @@ protected void postInitialize() { | |
} | ||
|
||
public final Atom newInstance(Object... params) { | ||
return uniqueConstructor.newInstance(params); | ||
return AtomNewInstanceNode.getUncached().newInstance(uniqueConstructor, params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to hide |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing the
accessorFor
method allows us to makeQualifiedAccessorNode
package private, @4e6.