-
Notifications
You must be signed in to change notification settings - Fork 323
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
Implement conversions (#180312665) #3227
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
05c67cf
Implement conversions
ekmett 9f6d9f8
update RELEASES.md
ekmett a652ee2
disable test error about from conversions being tail calls. (pivotal …
ekmett 370d770
add changelog entry
ekmett 8c1c293
fix OverloadsResolutionTest
ekmett 655b8f6
fix MethodDefinitionsTest
ekmett d9fe8e7
fix DataflowAnalysisTest
ekmett cff13fc
the field name for a from conversion must be 'that'. Fix remaining te…
ekmett bf4e4ff
fix ModuleThisToHereTest
ekmett 63d069b
feat: suppress compilation errors from Builtins
4e6 3b174c8
Revert "feat: suppress compilation errors from Builtins"
kustosz a100754
fix tests
kustosz 50f879e
Merge branch 'develop' into compiler/wip/eak/conversions
ekmett 90dc03b
fix: formatting
4e6 57730dc
Merge branch 'develop' into compiler/wip/eak/conversions
4e6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
218 changes: 218 additions & 0 deletions
218
...untime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeConversionNode.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,218 @@ | ||
package org.enso.interpreter.node.callable; | ||
|
||
import com.oracle.truffle.api.TruffleLanguage; | ||
import com.oracle.truffle.api.dsl.*; | ||
import com.oracle.truffle.api.frame.MaterializedFrame; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
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.profiles.BranchProfile; | ||
import com.oracle.truffle.api.profiles.ConditionProfile; | ||
import org.enso.interpreter.Language; | ||
import org.enso.interpreter.node.BaseNode; | ||
import org.enso.interpreter.node.callable.dispatch.IndirectInvokeFunctionNode; | ||
import org.enso.interpreter.node.callable.resolver.AnyResolverNode; | ||
import org.enso.interpreter.node.callable.resolver.DataflowErrorResolverNode; | ||
import org.enso.interpreter.node.callable.resolver.HostMethodCallNode; | ||
import org.enso.interpreter.node.callable.thunk.ThunkExecutorNode; | ||
import org.enso.interpreter.runtime.Context; | ||
import org.enso.interpreter.runtime.callable.UnresolvedConversion; | ||
import org.enso.interpreter.runtime.callable.UnresolvedSymbol; | ||
import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo; | ||
import org.enso.interpreter.runtime.callable.function.Function; | ||
import org.enso.interpreter.runtime.data.text.Text; | ||
import org.enso.interpreter.runtime.error.DataflowError; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
import org.enso.interpreter.runtime.error.PanicSentinel; | ||
import org.enso.interpreter.runtime.library.dispatch.MethodDispatchLibrary; | ||
import org.enso.interpreter.runtime.state.Stateful; | ||
|
||
@GenerateUncached | ||
@ReportPolymorphism | ||
@ImportStatic({HostMethodCallNode.PolyglotCallType.class, HostMethodCallNode.class}) | ||
public abstract class IndirectInvokeConversionNode extends Node { | ||
|
||
/** @return a new indirect method invocation node */ | ||
public static IndirectInvokeConversionNode build() { | ||
return IndirectInvokeConversionNodeGen.create(); | ||
} | ||
|
||
public abstract Stateful execute( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
Object that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail); | ||
|
||
@Specialization(guards = "dispatch.canConvertFrom(that)") | ||
Stateful doConvertFrom( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
Object that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail, | ||
@CachedLibrary(limit = "10") MethodDispatchLibrary dispatch, | ||
@CachedContext(Language.class) TruffleLanguage.ContextReference<Context> ctx, | ||
@Cached ConditionProfile atomProfile, | ||
@Cached ConditionProfile atomConstructorProfile, | ||
@Cached IndirectInvokeFunctionNode indirectInvokeFunctionNode) { | ||
try { | ||
Function function = | ||
dispatch.getConversionFunction( | ||
that, | ||
InvokeConversionNode.extractConstructor( | ||
this, _this, ctx, atomConstructorProfile, atomProfile), | ||
conversion); | ||
return indirectInvokeFunctionNode.execute( | ||
function, | ||
frame, | ||
state, | ||
arguments, | ||
schema, | ||
defaultsExecutionMode, | ||
argumentsExecutionMode, | ||
isTail); | ||
} catch (MethodDispatchLibrary.NoSuchConversionException e) { | ||
throw new PanicException( | ||
ctx.get().getBuiltins().error().makeNoSuchConversionError(_this, that, conversion), this); | ||
} | ||
} | ||
|
||
@Specialization | ||
Stateful doDataflowError( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
DataflowError that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail, | ||
@CachedLibrary(limit = "10") MethodDispatchLibrary dispatch, | ||
@CachedContext(Language.class) TruffleLanguage.ContextReference<Context> ctx, | ||
@Cached BranchProfile profile, | ||
@Cached ConditionProfile atomProfile, | ||
@Cached ConditionProfile atomConstructorProfile, | ||
@Cached IndirectInvokeFunctionNode indirectInvokeFunctionNode) { | ||
try { | ||
Function function = | ||
dispatch.getConversionFunction( | ||
that, | ||
InvokeConversionNode.extractConstructor( | ||
this, _this, ctx, atomConstructorProfile, atomProfile), | ||
conversion); | ||
return indirectInvokeFunctionNode.execute( | ||
function, | ||
frame, | ||
state, | ||
arguments, | ||
schema, | ||
defaultsExecutionMode, | ||
argumentsExecutionMode, | ||
isTail); | ||
} catch (MethodDispatchLibrary.NoSuchConversionException e) { | ||
profile.enter(); | ||
return new Stateful(state, that); | ||
} | ||
} | ||
|
||
@Specialization | ||
Stateful doPanicSentinel( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
PanicSentinel that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail) { | ||
throw that; | ||
} | ||
|
||
@Specialization(guards = "interop.isString(that)") | ||
Stateful doConvertText( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
Object that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail, | ||
@CachedLibrary(limit = "10") MethodDispatchLibrary methods, | ||
@CachedLibrary(limit = "1") MethodDispatchLibrary textDispatch, | ||
@CachedLibrary(limit = "10") InteropLibrary interop, | ||
@Cached ConditionProfile atomProfile, | ||
@Cached ConditionProfile atomConstructorProfile, | ||
@CachedContext(Language.class) TruffleLanguage.ContextReference<Context> ctx, | ||
@Cached IndirectInvokeFunctionNode indirectInvokeFunctionNode) { | ||
try { | ||
String str = interop.asString(that); | ||
Text txt = Text.create(str); | ||
Function function = | ||
textDispatch.getConversionFunction( | ||
txt, | ||
InvokeConversionNode.extractConstructor( | ||
this, _this, ctx, atomConstructorProfile, atomProfile), | ||
conversion); | ||
arguments[0] = txt; | ||
return indirectInvokeFunctionNode.execute( | ||
function, | ||
frame, | ||
state, | ||
arguments, | ||
schema, | ||
defaultsExecutionMode, | ||
argumentsExecutionMode, | ||
isTail); | ||
} catch (UnsupportedMessageException e) { | ||
throw new IllegalStateException("Impossible, that is guaranteed to be a string."); | ||
} catch (MethodDispatchLibrary.NoSuchConversionException e) { | ||
throw new PanicException( | ||
ctx.get().getBuiltins().error().makeNoSuchConversionError(_this, that, conversion), this); | ||
} | ||
} | ||
|
||
@Specialization( | ||
guards = { | ||
"!methods.canConvertFrom(that)", | ||
"!interop.isString(that)", | ||
"!methods.hasSpecialConversion(that)" | ||
}) | ||
Stateful doFallback( | ||
MaterializedFrame frame, | ||
Object state, | ||
UnresolvedConversion conversion, | ||
Object _this, | ||
Object that, | ||
Object[] arguments, | ||
CallArgumentInfo[] schema, | ||
InvokeCallableNode.DefaultsExecutionMode defaultsExecutionMode, | ||
InvokeCallableNode.ArgumentsExecutionMode argumentsExecutionMode, | ||
BaseNode.TailStatus isTail, | ||
@CachedLibrary(limit = "10") MethodDispatchLibrary methods, | ||
@CachedLibrary(limit = "10") InteropLibrary interop, | ||
@CachedContext(Language.class) Context ctx) { | ||
throw new PanicException( | ||
ctx.getBuiltins().error().makeNoSuchConversionError(_this, that, conversion), this); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If I understand correctly, we are aiming to have a single changelog and currently the one to use is at
app/gui/CHANGELOG.md
. cc: @mwu-tow please correct me if I'm wrongThere 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.
Happy to put this in the right place. I was just reacting to a red checkmark in the build process.
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.
Yes,
app/gui/CHANGELOG.md
is the location currently enforced by the CI. It'll be moved to the repository root,