-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
Meta.is_same_object
to test type equality
Removed `is_of_type` and moved some of the logic to `is_same_object`. Turns out the latter was actually broken when comparing polyglot values with the same underlying java class. Additionally, discovered why I can't simply use `==` - the dispatch for types is broken and it's a known "feature". This will be improved in the upcoming statics change so I'm not going to duplicate that work. Once in, we can most likely get rid of `should_equal_type` and `should_not_equal_type`. Addressed comments re date/time-related branches in pattern matching so that it doesn't try to do semi-subtyping checks but rather checks for equality. Moved all logic of `type_of` to the builtin node. Added tests for `type_of` of Date, Date_Time, Time_Of_Day and Time_Zone. Might still change `type_of` to ensure that java classes aren't leaking.
- Loading branch information
Showing
16 changed files
with
225 additions
and
154 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
37 changes: 0 additions & 37 deletions
37
...ime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsOfTypeMetaNode.java
This file was deleted.
Oops, something went wrong.
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
83 changes: 59 additions & 24 deletions
83
...e/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/TypeOfNode.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 |
---|---|---|
@@ -1,44 +1,79 @@ | ||
package org.enso.interpreter.node.expression.builtin.meta; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
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.Node; | ||
import com.oracle.truffle.api.profiles.BranchProfile; | ||
import org.enso.interpreter.Constants; | ||
import org.enso.interpreter.dsl.AcceptsError; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.Context; | ||
import org.enso.interpreter.runtime.builtin.Builtins; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; | ||
import org.enso.interpreter.runtime.number.EnsoBigInteger; | ||
import org.enso.interpreter.runtime.type.TypesGen; | ||
|
||
@BuiltinMethod( | ||
type = "Meta", | ||
name = "type_of_builtin", | ||
description = "Returns the type of a value.") | ||
public class TypeOfNode extends Node { | ||
private @Child InteropLibrary library = | ||
InteropLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); | ||
private @Child TypesLibrary types = | ||
TypesLibrary.getFactory().createDispatched(Constants.CacheSizes.BUILTIN_INTEROP_DISPATCH); | ||
|
||
Object execute(Object value) { | ||
if (library.hasMetaObject(value)) { | ||
try { | ||
return library.getMetaObject(value); | ||
} catch (UnsupportedMessageException e) { | ||
CompilerDirectives.transferToInterpreter(); | ||
Builtins builtins = Context.get(this).getBuiltins(); | ||
throw new PanicException( | ||
builtins.error().makeTypeError(builtins.any(), value, "object"), this); | ||
} | ||
} else { | ||
if (types.hasType(value)) { | ||
return types.getType(value); | ||
} else { | ||
Context ctx = Context.get(this); | ||
return ctx.getBuiltins().any(); | ||
} | ||
public abstract class TypeOfNode extends Node { | ||
|
||
abstract Object execute(@AcceptsError Object value); | ||
|
||
static TypeOfNode build() { | ||
return TypeOfNodeGen.create(); | ||
} | ||
|
||
@Specialization | ||
Object doDouble(double value) { | ||
Context ctx = Context.get(this); | ||
return ctx.getBuiltins().number().getDecimal(); | ||
} | ||
|
||
@Specialization | ||
Object doLong(long value) { | ||
Context ctx = Context.get(this); | ||
return ctx.getBuiltins().number().getInteger(); | ||
} | ||
|
||
@Specialization | ||
Object doBigInteger(EnsoBigInteger value) { | ||
Context ctx = Context.get(this); | ||
return ctx.getBuiltins().number().getInteger(); | ||
} | ||
|
||
@Specialization(guards = "isError(value)") | ||
Object doError(Object value) { | ||
return Context.get(this).getBuiltins().dataflowError(); | ||
} | ||
|
||
boolean isError(Object value) { | ||
return TypesGen.isDataflowError(value); | ||
} | ||
|
||
@Specialization(guards = "interop.hasMetaObject(value)") | ||
Object doMetaObject(Object value, @CachedLibrary(limit = "3") InteropLibrary interop) { | ||
try { | ||
return interop.getMetaObject(value); | ||
} catch (UnsupportedMessageException e) { | ||
CompilerDirectives.transferToInterpreter(); | ||
Builtins builtins = Context.get(this).getBuiltins(); | ||
throw new PanicException(builtins.error().makeCompileError("invalid meta object"), this); | ||
} | ||
} | ||
|
||
@Specialization(guards = "types.hasType(value)") | ||
Object doType(Object value, @CachedLibrary(limit = "3") TypesLibrary types) { | ||
return types.getType(value); | ||
} | ||
|
||
@Fallback | ||
Object doAny(Object value) { | ||
return Context.get(this).getBuiltins().any(); | ||
} | ||
} |
Oops, something went wrong.