Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 89f41c3

Browse files
authored
QEP 2: Enhanced Array Literals (#983)
* Fix test * Update keyword comment * Update doc comment * Add doc comments * Use expectedExpr * Create fresh type parameter for empty arrays * Use new type inference for concatenation * Clean up Unify * Add basic subtyping and constraint support to inference * Remove duplicate type * Add Iterates constraint * Flip iterable and item types, add Satisfy method * Remove unneeded functions * Don't error in Unify if types equal * Use correct subtyping relation in substitutions * Treat addition and concatenation identically (semigroup) * Add Equatable and Numeric constraints * Add tests for empty array error * Add tests for zero/negative sizes * Clean up TypeInference.fs * Factor out constraint checker * Add basic call expression inference * Add occurs check * Use invalid types for fallback case in buildCall * Add unification failed diagnostic * Ignore invalid types in unification * Don't add trivial substitutions * Fix invalid type unification again * Replace several exceptions with diagnostics * Unify in TypeMatchArgument * Reduce nesting in CheckConstraint * Simplify type merging and resolution * Avoid double diagnostics in commonType * Fix range in inference diagnostics * Update diagnostic message * Update apply-and-reassign test * Ignore missing types in unification * Use HM for arithmetic ops * Use HM for integral ops * Fix remaining copy-and-update array tests * Use HM for conditional expressions * Resolve tvars in VerifyAssignment error message * Use HM for symbol bindings and unwrap * Add Indexed constraint * Add back some operation call verification * Fix variance in call expr arg tuple * Fix variance in callable type unification * Resolve type in buildNamedItem * Resolve type in Constrain * Resolve LHS in copy and update expression * Update open-ended range tests * Add partial application inference * Resolve type in buildCall * Add error for ambiguous type variables * Fix common base type in arrays * Update VerifyIsInteger * Unified tuples should have the same length * Remove type param recursion checks * Create fresh tvars for all polymorphic identifiers, not just calls * Add callable constraints * Fix duplicate error message * Update access modifier test * Generate diagnostic for invalid equality * Finalize HM types before capability diagnostics * Fix type args on identifiers * Fix inferred info for call exprs * Update VerifyIsBoolean * Update "Local namespace short names" test * Fix order of tuple binding * Update "Apply-and-reassign" test * Update "argument matching" test * Unify array types as invariant * Update "Common base type" test * Fix common base type * Update type checking tests * Update variance tests * Update tests * Fix partial application * Add Adjointable and Controllable constraints * Update "operation characteristics" test * Remove commented out code * Update tests * Formatting * Fix match warning * Enable "Concrete Graph Double Reference Resolution" test * Replace Variance with TypeOrdering * Add TypeRelation type * Remove TypeBound * Apply constraints as soon as params are bound * Use property * Remove unnecessary pipes * Rename things * Simplify internal type inference API * Clean up imports * Remove Relation * Rename AppliesPartial to HasPartialApplication * Replace Set with HashSet * Rewrite CommonBaseType * Finish cleaning up Inference module * Fix IsFresh * Use one dictionary * Clean up InferenceContext members * Use consistent expected/actual order in UnifyByOrdering * Use ResolvedTypes in InferenceContext.Resolve * Clean up UnifyByOrdering * Clean up fresh variable naming * Update tests * Remove IsFresh * Remove some unnecessary code * Clean up ExpressionVerification, remove diagnose callbacks * Shorter name for inference context * Add takeDiagnostics function * More clean up * Use TypedExpression instead of type * range tuples * Clean up StatementVerification * Simplify verifyExpr/verifyExprWith * Correct range for ambiguous type diagnostics * Remove ConstraintNotSatisfied and AmbiguousTypeVariable * Add general type mismatch error codes * Update tests * Add range to ResolvedType * Remove confusing ambiguous type diagnostics * Remove ambiguous type error for unknown identifiers * Clean up * Fix empty array type * Fix diagnostic range in use/borrow statement * Generate InvalidArrayItemIndex diagnostic correctly * Update type checking tests * Update range info for local variable types * Compare type params and UDTs without ranges * Improved message for type mismatch diagnostic * Fix some diagnostic bugs * Use TypeContext with combine * Improve common base type diagnostic * Fix attaching type args to identifier * Fix array slicing * Revert "Fix #885 (#886)" This reverts commit 3ffd626. * Add integral constraint tests * Add iterable constraint tests * Update occurs check * Add numeric constraint tests * Add semigroup constraint tests * Fix range of combined types * Add wrapped constraint tests * Improve missing base type diagnostic * Remove unneeded type annotations * Improve diagnostic range in array literal * Formatting * Remove type parameter warnings * Formatting * Update tests * Add doc comments * Add TypeInference folder * Add signature files * Rename member * Update ResolvedType API and doc comments * Add Hindley-Milner type inference module * Update CompiledName for withAllRanges * Add README * Add result variable * Fix README typos * Add leading zeroes to error code * Simplify check in bind * Simplify check in bind * Distinguish between annotated and inferred type ranges * TP and UDT ranges are obsolete * Visit range before type kind * Formatting * Distinguish between annotated and inferred type ranges * TP and UDT ranges are obsolete * Visit range before type kind * Fix obsolete warnings * Return Generated range from Intersect * Return Generated range from Intersect * Add CompiledNames * Add CompiledNames * Remove withSpanningRange * Clarify subtyping in doc comments * Update uses of obsolete range property * Add TypeTransformationBase.OnTypeRange * Add TODO for removing OnRangeInformation * Ignore TP and UDT ranges in Bond serializer * Ignore TP and UDT ranges in Bond deserializer * Revert "Revert "Fix #885 (#886)"" This reverts commit a665fdd. * Revert unnecessary changes * Use HM inference in expression and statement verification * Update comments * Deprecate diagnostics * Update doc comments in ExpressionVerification.fs * Update LocalVerification.qs * Refactor commaSep parsers * Update unused type param warning * Add TODOs for removing diagnostics * Fix type param name in diagnostic * Use OperationCallOutsideOfOperation diagnostic * Use OperationCallOutsideOfOperation diagnostic * Deprecate MissingExprInArray diagnostic * Remove replaceTypeParams * Remove VerifyNumberedItemAccess * Rename VerifyArrayItem * Add doc comment to partialArgType * Update naming convention * Nicer exprWithoutTypeArgs * Clean up exprWithoutTypeArgs again * Rename verifyConcatenation * Update verifyUdtWith documentation * Add range field to QsDeclarationAttribute * Update SearchAndReplace.cs * Support sized array in attribute arguments * Make new record constructors non-extension methods * Update unused type param message * Handle SizedArray in code output and optimizations * constructArray doesn't need to be rec * Update StripPositionInfoFromType for TypeRange * Improve ambiguous type error message * Remove redundant showFunctor * Better type mismatch error messages * Restore alignment in error messages * Add some type parameter inference tests * Fix UDT constructors * Rename MissingBaseType to TypeIntersectionMismatch
1 parent ed60c81 commit 89f41c3

File tree

61 files changed

+3121
-2400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3121
-2400
lines changed

src/QsCompiler/BondSchemas/BondSchemaTranslator.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,7 @@ private static QsTypeParameter ToBondSchema(this SyntaxTree.QsTypeParameter qsTy
536536
{
537537
Origin = qsTypeParameter.Origin.ToBondSchema(),
538538
TypeName = qsTypeParameter.TypeName,
539-
Range = qsTypeParameter.Range.IsNull ?
540-
null :
541-
qsTypeParameter.Range.Item.ToBondSchema()
539+
Range = null
542540
};
543541

544542
private static QsValueUpdate ToBondSchema(this SyntaxTree.QsValueUpdate valueUpdate) =>
@@ -675,9 +673,7 @@ private static UserDefinedType ToBondSchema(this SyntaxTree.UserDefinedType user
675673
{
676674
Namespace = userDefinedType.Namespace,
677675
Name = userDefinedType.Name,
678-
Range = userDefinedType.Range.IsNull ?
679-
null :
680-
userDefinedType.Range.Item.ToBondSchema()
676+
Range = null
681677
};
682678

683679
private static CharacteristicsKindComposition<TBond> ToBondSchemaGeneric<TBond, TCompiler>(
@@ -859,6 +855,14 @@ private static QsExpressionKindComposition<TBondExpression, TBondSymbol, TBondTy
859855
kind = QsExpressionKind.ValueArray;
860856
bondExpressionArray = compilerValueArray.Item.Select(e => expressionTranslator(e)).ToList();
861857
}
858+
else if (qsExpressionKind is SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.SizedArray compilerSizedArray)
859+
{
860+
kind = QsExpressionKind.SizedArray;
861+
bondExpressionDouble = ToQsExpressionKindExpressionDoubleGeneric(
862+
compilerSizedArray.value,
863+
compilerSizedArray.size,
864+
expressionTranslator);
865+
}
862866
else if (qsExpressionKind is SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.ArrayItem compilerArrayItem)
863867
{
864868
kind = QsExpressionKind.ArrayItem;

src/QsCompiler/BondSchemas/CompilerDataStructures.bond

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ enum QsExpressionKind
105105
ControlledApplication,
106106
CallLikeExpression,
107107
MissingExpr,
108-
InvalidExpr
108+
InvalidExpr,
109+
SizedArray
109110
}
110111

111112
// Used to encapsulate data when QsExpressionKind is Identifier.
@@ -126,7 +127,8 @@ struct QsExpressionKindStringLiteral<TExpression>
126127
10: vector<TExpression> Expressions;
127128
}
128129

129-
// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication.
130+
// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT,
131+
// LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication, SizedArray.
130132
// N.B. Does not have an equivalent F# type.
131133
struct QsExpressionKindExpressionDouble<TExpression>
132134
{
@@ -203,7 +205,8 @@ struct QsExpressionKindComposition<TExpression, TSymbol, TType>
203205
// Not null when Kind is NEG, NOT, BNOT, UnwrapApplication, AdjointApplication, ControlledApplication.
204206
65: nullable<TExpression> Expression;
205207

206-
// Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication.
208+
// Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR,
209+
// BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication, SizedArray.
207210
70: nullable<QsExpressionKindExpressionDouble<TExpression>> ExpressionDouble;
208211

209212
// Not null when Kind is CONDITIONAL, CopyAndUpdate.

src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ private static SyntaxTree.QsDeclarationAttribute ToCompilerObject(this QsDeclara
250250
typeId: bondQsDeclarationAttribute.TypeId != null ?
251251
bondQsDeclarationAttribute.TypeId.ToCompilerObject().ToQsNullableGeneric() :
252252
QsNullable<SyntaxTree.UserDefinedType>.Null,
253+
typeIdRange: QsNullable<DataTypes.Range>.Null,
253254
argument: bondQsDeclarationAttribute.Argument.ToCompilerObject(),
254255
offset: bondQsDeclarationAttribute.Offset.ToCompilerObject(),
255256
comments: bondQsDeclarationAttribute.Comments.ToCompilerObject());
@@ -537,9 +538,7 @@ private static SyntaxTree.QsTypeParameter ToCompilerObject(this QsTypeParameter
537538
new SyntaxTree.QsTypeParameter(
538539
origin: bondQsTypeParameter.Origin.ToCompilerObject(),
539540
typeName: bondQsTypeParameter.TypeName,
540-
range: bondQsTypeParameter.Range != null ?
541-
bondQsTypeParameter.Range.ToCompilerObject().ToQsNullableGeneric() :
542-
QsNullable<DataTypes.Range>.Null);
541+
range: QsNullable<DataTypes.Range>.Null);
543542

544543
private static SyntaxTree.QsWhileStatement ToCompilerObject(this QsWhileStatement bondQsWhileStatement) =>
545544
new SyntaxTree.QsWhileStatement(
@@ -653,9 +652,7 @@ private static SyntaxTree.UserDefinedType ToCompilerObject(this UserDefinedType
653652
new SyntaxTree.UserDefinedType(
654653
@namespace: bondUserDefinedType.Namespace,
655654
name: bondUserDefinedType.Name,
656-
range: bondUserDefinedType.Range != null ?
657-
bondUserDefinedType.Range.ToCompilerObject().ToQsNullableGeneric() :
658-
QsNullable<DataTypes.Range>.Null);
655+
range: QsNullable<DataTypes.Range>.Null);
659656

660657
private static Tuple<SyntaxTree.SymbolTuple, SyntaxTree.ResolvedType> ToCompilerObject(this QsLoopItem bondQsLoopItem) =>
661658
new Tuple<SyntaxTree.SymbolTuple, SyntaxTree.ResolvedType>(
@@ -868,6 +865,7 @@ string UnexpectedNullFieldMessage(string fieldName) =>
868865
}
869866
else if ((bondQsExpressionKindComposition.Kind == QsExpressionKind.RangeLiteral) ||
870867
(bondQsExpressionKindComposition.Kind == QsExpressionKind.ArrayItem) ||
868+
(bondQsExpressionKindComposition.Kind == QsExpressionKind.SizedArray) ||
871869
(bondQsExpressionKindComposition.Kind == QsExpressionKind.ADD) ||
872870
(bondQsExpressionKindComposition.Kind == QsExpressionKind.SUB) ||
873871
(bondQsExpressionKindComposition.Kind == QsExpressionKind.MUL) ||
@@ -901,6 +899,8 @@ string UnexpectedNullFieldMessage(string fieldName) =>
901899
NewRangeLiteral(item1: compilerExpression1, item2: compilerExpression2),
902900
QsExpressionKind.ArrayItem => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
903901
NewArrayItem(item1: compilerExpression1, item2: compilerExpression2),
902+
QsExpressionKind.SizedArray => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
903+
NewSizedArray(compilerExpression1, compilerExpression2),
904904
QsExpressionKind.ADD => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.
905905
NewADD(item1: compilerExpression1, item2: compilerExpression2),
906906
QsExpressionKind.SUB => SyntaxTokens.QsExpressionKind<TCompilerExpression, TCompilerSymbol, TCompilerType>.

0 commit comments

Comments
 (0)