public override void ValidateConstraintForType(TypeVariableReference type, ITypeUnificationResult unificationResult) { if (!type.Lifetime.DoesOutlastLifetimeGraph(_lifetimeGraph)) { unificationResult.AddFailedTypeConstraint(this); } }
public override void ValidateConstraintForType(TypeVariableReference type, ITypeUnificationResult unificationResult) { if (!type.RenderNIType().TypeHasDisplayTrait()) { unificationResult.AddFailedTypeConstraint(this); } }
public override void ValidateConstraintForType(TypeVariableReference type, ITypeUnificationResult unificationResult) { NIType implementedIteratorInterface; // TODO: using NITypes here to destructure the iterator interface and reconstruct a TypeReference for the item type // is an incomplete solution; it will not work for item types that have bounded lifetimes. Also, currently there's // no way to create TypeReferences for non-reference types that have bounded lifetimes, as an iterator implementation // whose items are references will necessarily have. // // What is needed is a way of defining a generic parameterized TypeVariableReference, and then a reference to a specialization of that type. // Then, as long as the parameterized type can include an interface implementation, we should be able to get the specialized // interface implementation from the specialization. if (type.RenderNIType().TryGetImplementedIteratorInterface(out implementedIteratorInterface)) { NIType itemType; implementedIteratorInterface.TryDestructureIteratorType(out itemType); TypeVariableReference itemTypeReference = type.TypeVariableSet.CreateTypeVariableReferenceFromNIType( itemType, new Dictionary <NIType, TypeVariableReference>()); type.TypeVariableSet.Unify(_itemTypeVariable, itemTypeReference, unificationResult); } else { unificationResult.AddFailedTypeConstraint(this); } }
public override void UnifyWithConnectedWireTypeAsNodeInput(VariableReference wireFacadeVariable, TerminalTypeUnificationResults unificationResults) { TypeVariableSet typeVariableSet = Terminal.GetTypeVariableSet(); ITypeUnificationResult inputUnificationResult = unificationResults.GetTypeUnificationResult(Terminal, TrueVariable.TypeVariableReference, wireFacadeVariable.TypeVariableReference); typeVariableSet.Unify(TrueVariable.TypeVariableReference, wireFacadeVariable.TypeVariableReference, inputUnificationResult); TrueVariable.MergeInto(wireFacadeVariable); string constructorName; TypeVariableReference innerType, optionType; if (typeVariableSet.TryDecomposeConstructorType(TrueVariable.TypeVariableReference, out constructorName, out innerType) && constructorName == "Option") { optionType = TrueVariable.TypeVariableReference; } else { optionType = typeVariableSet.CreateReferenceToConstructorType("Option", TrueVariable.TypeVariableReference); } TypeVariableReference outputTypeReference = _outputTerminalFacade.TrueVariable.TypeVariableReference; ITypeUnificationResult outputUnificationResult = unificationResults.GetTypeUnificationResult(_outputTerminalFacade.Terminal, outputTypeReference, optionType); typeVariableSet.Unify(outputTypeReference, optionType, outputUnificationResult); }
public override void ValidateConstraintForType(TypeVariableReference type, ITypeUnificationResult unificationResult) { // TODO: probably not great to render an NIType at this stage if (!type.RenderNIType().WireTypeMayFork()) { unificationResult.AddFailedTypeConstraint(this); } }
public override void UnifyWithConnectedWireTypeAsNodeInput(VariableReference wireFacadeVariable, TerminalTypeUnificationResults unificationResults) { ITypeUnificationResult unificationResult = unificationResults.GetTypeUnificationResult( Terminal, FacadeVariable.TypeVariableReference, wireFacadeVariable.TypeVariableReference); FacadeVariable.UnifyTypeVariableInto(wireFacadeVariable, unificationResult); FacadeVariable.MergeInto(wireFacadeVariable); }
public override void UnifyWithConnectedWireTypeAsNodeInput(VariableReference wireFacadeVariable, ITypeUnificationResultFactory unificationResultFactory) { FacadeVariable.MergeInto(wireFacadeVariable); bool setExpectedMutable; ITypeUnificationResult unificationResult = Terminal.UnifyTerminalTypeWith( TrueVariable.TypeVariableReference, ComputeTypeToUnifyWith(wireFacadeVariable, out setExpectedMutable), unificationResultFactory); if (setExpectedMutable) { unificationResult.SetExpectedMutable(); } }
public static ITypeUnificationResult UnifyTerminalTypeWith( this Terminal terminal, TypeVariableReference terminalType, TypeVariableReference unifyWithType, ITypeUnificationResultFactory unificationResultFactory) { ITypeUnificationResult unificationResult = unificationResultFactory.GetTypeUnificationResult( terminal, terminalType, unifyWithType); terminalType.TypeVariableSet.Unify(terminalType, unifyWithType, unificationResult); return(unificationResult); }
public override void UnifyWithConnectedWireTypeAsNodeInput(VariableReference wireFacadeVariable, TerminalTypeUnificationResults unificationResults) { FacadeVariable.MergeInto(wireFacadeVariable); bool setExpectedMutable; TypeVariableReference typeToUnifyWith = ComputeTypeToUnifyWith(wireFacadeVariable, out setExpectedMutable); ITypeUnificationResult unificationResult = unificationResults.GetTypeUnificationResult( Terminal, TrueVariable.TypeVariableReference, typeToUnifyWith); if (setExpectedMutable) { unificationResult.SetExpectedMutable(); } TypeVariableSet.Unify(TrueVariable.TypeVariableReference, typeToUnifyWith, unificationResult); }
protected override void VisitWire(Wire wire) { // Merge the wire's input terminal with its connected source foreach (var wireTerminal in wire.InputTerminals) { var connectedNodeTerminal = wireTerminal.ConnectedTerminal; if (connectedNodeTerminal != null) { VariableReference wireVariable = wireTerminal.GetFacadeVariable(), nodeVariable = connectedNodeTerminal.GetFacadeVariable(); ITypeUnificationResult unificationResult = _typeUnificationResults.GetTypeUnificationResult( wireTerminal, wireVariable.TypeVariableReference, nodeVariable.TypeVariableReference); wireVariable.UnifyTypeVariableInto(nodeVariable, unificationResult); wireVariable.MergeInto(nodeVariable); } } }
internal void UnifyTypeVariableInto(VariableReference intoVariable, ITypeUnificationResult unificationResult) { _variableSet.TypeVariableSet.Unify(TypeVariableReference, intoVariable.TypeVariableReference, unificationResult); }
public abstract void ValidateConstraintForType(TypeVariableReference type, ITypeUnificationResult unificationResult);
private void UnifyTypeVariableWithNonTypeVariable(TypeVariableReference typeVariable, TypeVariableReference nonTypeVariable, ITypeUnificationResult unificationResult) { var t = (TypeVariable)GetTypeForTypeVariableReference(typeVariable); foreach (Constraint constraint in t.Constraints) { constraint.ValidateConstraintForType(nonTypeVariable, unificationResult); } MergeTypeVariableIntoTypeVariable(typeVariable, nonTypeVariable); }
public void Unify(TypeVariableReference toUnify, TypeVariableReference toUnifyWith, ITypeUnificationResult unificationResult) { TypeBase toUnifyTypeBase = GetTypeForTypeVariableReference(toUnify), toUnifyWithTypeBase = GetTypeForTypeVariableReference(toUnifyWith); LiteralType toUnifyLiteral = toUnifyTypeBase as LiteralType, toUnifyWithLiteral = toUnifyWithTypeBase as LiteralType; if (toUnifyLiteral != null && toUnifyWithLiteral != null) { if (toUnifyLiteral.Type == toUnifyWithLiteral.Type) { MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } unificationResult.SetTypeMismatch(); return; } ConstructorType toUnifyConstructor = toUnifyTypeBase as ConstructorType, toUnifyWithConstructor = toUnifyWithTypeBase as ConstructorType; if (toUnifyConstructor != null && toUnifyWithConstructor != null) { if (toUnifyConstructor.ConstructorName == toUnifyWithConstructor.ConstructorName) { Unify(toUnifyConstructor.Argument, toUnifyWithConstructor.Argument, unificationResult); MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } unificationResult.SetTypeMismatch(); return; } ReferenceType toUnifyReference = toUnifyTypeBase as ReferenceType, toUnifyWithReference = toUnifyWithTypeBase as ReferenceType; if (toUnifyReference != null && toUnifyWithReference != null) { toUnifyReference.UnifyMutability(toUnifyWithReference); Unify(toUnifyReference.UnderlyingType, toUnifyWithReference.UnderlyingType, unificationResult); Unify(toUnifyReference.LifetimeType, toUnifyWithReference.LifetimeType, unificationResult); return; } LifetimeTypeContainer toUnifyLifetime = toUnifyTypeBase as LifetimeTypeContainer, toUnifyWithLifetime = toUnifyWithTypeBase as LifetimeTypeContainer; if (toUnifyLifetime != null && toUnifyWithLifetime != null) { // toUnify is the possible supertype container here toUnifyLifetime.AdoptLifetimeIfPossible(toUnifyWithLifetime.LifetimeValue); return; } TypeVariable toUnifyTypeVariable = toUnifyTypeBase as TypeVariable, toUnifyWithTypeVariable = toUnifyWithTypeBase as TypeVariable; if (toUnifyTypeVariable != null && toUnifyWithTypeVariable != null) { toUnifyWithTypeVariable.AdoptConstraintsFromVariable(toUnifyTypeVariable); MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } if (toUnifyTypeVariable != null) { UnifyTypeVariableWithNonTypeVariable(toUnify, toUnifyWith, unificationResult); return; } if (toUnifyWithTypeVariable != null) { UnifyTypeVariableWithNonTypeVariable(toUnifyWith, toUnify, unificationResult); return; } unificationResult.SetTypeMismatch(); return; }