Skip to content
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

Support runtime checks of intersection types #7769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@
- [Use `numpy` & co. from Enso!][7678]
- [Changed layout of local libraries directory, making it easier to reference
projects next to each other][7634]
- [Support runtime checks of intersection types][7769]
- [Merge `Small_Integer` and `Big_Integer` types][7636]

[3227]: https://github.com/enso-org/enso/pull/3227
Expand Down Expand Up @@ -1083,6 +1084,7 @@
[7613]: https://github.com/enso-org/enso/pull/7613
[7678]: https://github.com/enso-org/enso/pull/7678
[7634]: https://github.com/enso-org/enso/pull/7634
[7769]: https://github.com/enso-org/enso/pull/7769
[7636]: https://github.com/enso-org/enso/pull/7636

# Enso 2.0.0-alpha.18 (2021-10-12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,108 +650,4 @@ object Set {
object Intersection extends Info {
override val name: String = "&"
}

/** The typeset subtraction operator `\`.
*
* @param left the left operand
* @param right the right operand
* @param location the source location that the node corresponds to
* @param passData the pass metadata associated with this node
* @param diagnostics compiler diagnostics for this node
*/
sealed case class Subtraction(
left: Expression,
right: Expression,
override val location: Option[IdentifiedLocation],
override val passData: MetadataStorage = MetadataStorage(),
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
) extends Set
with IRKind.Primitive {
override protected var id: Identifier = randomId

/** Creates a copy of `this`.
*
* @param left the left operand
* @param right the right operand
* @param location the source location that the node corresponds to
* @param passData the pass metadata associated with this node
* @param diagnostics compiler diagnostics for this node
* @param id the identifier for the new node
* @return a copy of `this`, updated with the specified values
*/
def copy(
left: Expression = left,
right: Expression = right,
location: Option[IdentifiedLocation] = location,
passData: MetadataStorage = passData,
diagnostics: DiagnosticStorage = diagnostics,
id: Identifier = id
): Subtraction = {
val res = Subtraction(left, right, location, passData, diagnostics)
res.id = id
res
}

/** @inheritdoc */
override def duplicate(
keepLocations: Boolean = true,
keepMetadata: Boolean = true,
keepDiagnostics: Boolean = true,
keepIdentifiers: Boolean = false
): Subtraction =
copy(
left = left.duplicate(
keepLocations,
keepMetadata,
keepDiagnostics,
keepIdentifiers
),
right = right.duplicate(
keepLocations,
keepMetadata,
keepDiagnostics,
keepIdentifiers
),
location = if (keepLocations) location else None,
passData = if (keepMetadata) passData.duplicate else MetadataStorage(),
diagnostics =
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
id = if (keepIdentifiers) id else randomId
)

/** @inheritdoc */
override def setLocation(
location: Option[IdentifiedLocation]
): Subtraction = copy(location = location)

/** @inheritdoc */
override def mapExpressions(
fn: Expression => Expression
): Subtraction = {
copy(left = fn(left), right = fn(right))
}

/** @inheritdoc */
override def toString: String =
s"""
|`type`.Set.Subtraction(
|left = $left,
|right = $right,
|location = $location,
|passData = ${this.showPassData},
|diagnostics = $diagnostics,
|id = $id
|""".toSingleLine

/** @inheritdoc */
override def children: List[IR] = List(left, right)

/** @inheritdoc */
override def showCode(indent: Int): String =
s"(${left.showCode(indent)} \\ ${right.showCode(indent)})"
}

object Subtraction extends Info {
override val name: String = "\\"
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.enso.interpreter.runtime.data.EnsoDate;
import org.enso.interpreter.runtime.data.EnsoDateTime;
import org.enso.interpreter.runtime.data.EnsoDuration;
import org.enso.interpreter.runtime.data.EnsoMultiValue;
import org.enso.interpreter.runtime.data.EnsoTimeOfDay;
import org.enso.interpreter.runtime.data.EnsoTimeZone;
import org.enso.interpreter.runtime.data.Type;
Expand Down Expand Up @@ -208,9 +209,7 @@ Object doFunctionalDispatchUncachedSymbol(
Type selfTpe = typesLibrary.getType(self);
Function function = resolveFunction(symbol, selfTpe, methodResolverNode);
if (function == null) {
var cause = onBoundary ? UnknownIdentifierException.create(symbol.getName()) : null;
var payload = EnsoContext.get(this).getBuiltins().error().makeNoSuchMethod(self, symbol);
throw new PanicException(payload, cause, this);
throw methodNotFound(symbol, self);
}
var resolvedFuncArgCount = function.getSchema().getArgumentsCount();
CallArgumentInfo[] invokeFuncSchema = invokeFunctionNode.getSchema();
Expand Down Expand Up @@ -271,6 +270,32 @@ Object doFunctionalDispatchUncachedSymbol(
return invokeFunctionNode.execute(function, frame, state, arguments);
}

private PanicException methodNotFound(UnresolvedSymbol symbol, Object self) throws PanicException {
var cause = onBoundary ? UnknownIdentifierException.create(symbol.getName()) : null;
var payload = EnsoContext.get(this).getBuiltins().error().makeNoSuchMethod(self, symbol);
throw new PanicException(payload, cause, this);
}

@Specialization
Object doMultiValue(
VirtualFrame frame,
State state,
UnresolvedSymbol symbol,
EnsoMultiValue self,
Object[] arguments,
@Shared("methodResolverNode") @Cached MethodResolverNode methodResolverNode
) {
var fnAndType = self.resolveSymbol(methodResolverNode, symbol);
if (fnAndType != null) {
var unwrapSelf = self.castTo(fnAndType.getRight());
assert unwrapSelf != null;
assert arguments[0] == self;
arguments[0] = unwrapSelf;
return execute(frame, state, symbol, unwrapSelf, arguments);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
}
throw methodNotFound(symbol, self);
}

@Specialization
Object doDataflowError(
VirtualFrame frame,
Expand Down Expand Up @@ -327,7 +352,7 @@ Function resolveWarningFunction(
e);
}

Type typeOfSymbol = symbol.resolveDeclaringType(types.getType(selfWithoutWarnings));
Type typeOfSymbol = symbol.resolveDeclaringType(this, types.getType(selfWithoutWarnings));
Builtins builtins = EnsoContext.get(this).getBuiltins();
if (typeOfSymbol == builtins.any()) {
return symbol
Expand Down
Loading