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

A simple try for HKT #40368

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ad7b7e9
beta version.
ShuiRuTian Aug 31, 2020
b97c40a
analytcs something.
ShuiRuTian Sep 1, 2020
bc66c97
first step!
ShuiRuTian Sep 1, 2020
5df3394
continue analytics.
ShuiRuTian Sep 2, 2020
76d4940
third step!
ShuiRuTian Sep 2, 2020
6732416
come to mapper.
ShuiRuTian Sep 3, 2020
efacaeb
Merge remote-tracking branch 'origin/hkt' into hkt
ShuiRuTian Sep 3, 2020
4450ac6
just update some comment.
ShuiRuTian Sep 3, 2020
c67a88a
add comment.
ShuiRuTian Sep 4, 2020
63abe6c
Merge branch 'hkt' of https://github.com/ShuiRuTian/TypeScript into hkt
ShuiRuTian Sep 7, 2020
2bb3a15
work for simple conditon.
ShuiRuTian Sep 7, 2020
57b5acb
finally, I know the reason.
ShuiRuTian Sep 8, 2020
43041c2
works for nested typeconstructor.
ShuiRuTian Sep 9, 2020
1109ab6
fix quickinfo.
ShuiRuTian Sep 9, 2020
4356e74
fix and more clear code.
ShuiRuTian Sep 14, 2020
e6aab71
resolve most baseline.
ShuiRuTian Sep 14, 2020
829e12a
fix test case.
ShuiRuTian Sep 15, 2020
5462278
revert useless change for debug.
ShuiRuTian Sep 15, 2020
0766a75
just for pass test case.
ShuiRuTian Sep 15, 2020
6ef451a
for passing.....
ShuiRuTian Sep 15, 2020
778e9e3
...
ShuiRuTian Sep 15, 2020
9279c21
fix lint
ShuiRuTian Sep 15, 2020
8a247b3
extends could work.
ShuiRuTian Sep 16, 2020
29e1a56
fix test.
ShuiRuTian Sep 16, 2020
a00bd0a
Merge remote-tracking branch 'upstream/master' into hkt
ShuiRuTian Sep 16, 2020
4b9eed5
test case design.
ShuiRuTian Sep 17, 2020
63d7b58
type alias.
ShuiRuTian Sep 19, 2020
c71df53
simple fix.
ShuiRuTian Sep 19, 2020
9d1850c
first step for check error.
ShuiRuTian Sep 22, 2020
8e9ada1
fix test and another future fix issue.
ShuiRuTian Sep 23, 2020
d49f19c
Merge remote-tracking branch 'upstream/master' into hkt
ShuiRuTian Sep 23, 2020
ce27b0e
fix
ShuiRuTian Sep 23, 2020
21bbe6b
fix case.
ShuiRuTian Sep 23, 2020
8842bad
fix.
ShuiRuTian Sep 23, 2020
5cf045b
start to change binder.
ShuiRuTian Mar 10, 2021
41b1771
change binder beta version.
ShuiRuTian Mar 11, 2021
ab0080f
add type lambda.
ShuiRuTian Mar 18, 2021
d974a9e
update type lamda
ShuiRuTian Mar 19, 2021
0b4d9e0
add comment
ShuiRuTian Mar 19, 2021
e363b34
no build error.
ShuiRuTian Mar 24, 2021
47a2af3
add thoughts.
ShuiRuTian May 26, 2021
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
97 changes: 26 additions & 71 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9439,7 +9439,7 @@ namespace ts {
tmp.flags |= TypeFlags.TypeConstructorDeclaration;
// This line is important, which combines Node and Type.
// for now Node.paras is not used but its length. So constrait is not used for now.
(<TypeConstructorDeclaration>tmp).tParams = declration.tParamDeclarations.length;
(<TypeConstructorPolymophsimDeclaration>tmp).tParams = declration.tParamDeclarations.length;
}
links.declaredType = tmp;
}
Expand Down Expand Up @@ -12113,68 +12113,9 @@ namespace ts {
const isJsImplicitAny = !noImplicitAny && isJs;
// type reference without typeArguments. Like Set, rather than Set<XXX>
if (isTypeReferenceNode(node) && node.isTypeArguments && numTypeArguments === 0) {
(<any>type).isConcentrateTypeConstructor = true;
// These are not well considered, just for passing test cases.
// Maybe all those code should be removed and written in other places.

// get the type-constructor(the origional meaning)
const parentNode = <NodeWithTypeArguments | CallExpression>node.parent; // the parser make sure it must be TypeReference with typeArguments(or its parent.patent.....)
const typeParameterIndex = parentNode.typeArguments!.findIndex(t => t === node);
if (typeParameterIndex >= 0) {
if (isTypeReferenceNode(parentNode)) {
debugger;
const meaning = SymbolFlags.Type;
const parentSymbol = resolveTypeReferenceName(getTypeReferenceName(parentNode), meaning);
const parentType = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(parentSymbol));
if (parentType.typeParameters && !isTypeParameterTypeConstructorDeclaration(parentType.typeParameters[typeParameterIndex])) {
const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType);
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeStr, minTypeArgumentCount, typeParameters.length);
if (!isJs) {
// TODO: Adopt same permissive behavior in TS as in JS to reduce follow-on editing experience failures (requires editing fillMissingTypeArguments)
return errorType;
}
};
}
else if (isCallExpression(parentNode)) {
debugger;
const parentType = <ObjectType>getTypeOfExpression(parentNode.expression);
if (!(parentType.flags & TypeFlags.Object)) {
return errorType;
}
if (!parentType.callSignatures?.some(sig => sig.typeParameters && sig.typeParameters[typeParameterIndex] && isTypeParameterTypeConstructorDeclaration(sig.typeParameters[typeParameterIndex]))) {
const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType);
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeStr, minTypeArgumentCount, typeParameters.length);
if (!isJs) {
// TODO: Adopt same permissive behavior in TS as in JS to reduce follow-on editing experience failures (requires editing fillMissingTypeArguments)
return errorType;
}
}
}
else if (isExpressionWithTypeArguments(parentNode)) {
debugger;
if (!isIdentifier(parentNode.expression)) {
debugger;
return errorType;
}
const parentSymbol = getSymbolOfNameOrPropertyAccessExpression(parentNode.expression);
if (!parentSymbol) {
return errorType;
}
const parentType = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(parentSymbol));
if (parentType.typeParameters && !isTypeParameterTypeConstructorDeclaration(parentType.typeParameters[typeParameterIndex])) {
const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType);
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeStr, minTypeArgumentCount, typeParameters.length);
if (!isJs) {
// TODO: Adopt same permissive behavior in TS as in JS to reduce follow-on editing experience failures (requires editing fillMissingTypeArguments)
return errorType;
}
};
}
else {
debugger;
return errorType;
}
}
// another error.
}
else {
if (!isJsImplicitAny && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
Expand Down Expand Up @@ -12230,6 +12171,14 @@ namespace ts {
if (typeParameters) {
const numTypeArguments = length(node.typeArguments);
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
if (numTypeArguments === 0) {
const isTypeConstructorForTypeConstructorPoly = true; // should we check constraint here? or just pass the type if its parent is a TypeConstructor and accept this typeparameter as TypeConstructorPolymorphic
if (isTypeConstructorForTypeConstructorPoly) {
(<any>type).isConcentrateTypeConstructor = true;
(<any>type).origionalTypeAliasSymbol = symbol;
return type;
}
}
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
error(node,
minTypeArgumentCount === typeParameters.length ?
Expand Down Expand Up @@ -12295,13 +12244,11 @@ namespace ts {
if(node.typeArguments?.length !== res.tParams){
//check whether type arguments match type parameters.
}
// res.resolvedTypeConstructorParam = node.typeArguments?.map(getTypeFromTypeNode);
// return res;
const tmp = createTypeParameter(symbol);
tmp.flags |= TypeFlags.TypeConstructorInstance;
(<TypeConstructorInstance>tmp).resolvedTypeConstructorParam = node.typeArguments?.map(getTypeFromTypeNode);
(<TypeConstructorInstance>tmp).origionalTypeConstructorDeclaration = res;
return tmp;
const typeConstructorInstance = createTypeParameter(symbol);
typeConstructorInstance.flags |= TypeFlags.TypeConstructorInstance;
(<TypeConstructorPolymophsimInstance>typeConstructorInstance).resolvedTypeConstructorParam = node.typeArguments?.map(getTypeFromTypeNode);
(<TypeConstructorPolymophsimInstance>typeConstructorInstance).origionalTypeConstructorDeclaration = res;
return typeConstructorInstance;
}
if (checkNoTypeArguments(node, symbol)) {
return getRegularTypeOfLiteralType(res);
Expand Down Expand Up @@ -13882,11 +13829,11 @@ namespace ts {
return !!(type.flags & TypeFlags.TypeParameter && (<TypeParameter>type).isThisType);
}

function isTypeParameterTypeConstructorDeclaration(type: Type): type is TypeConstructorDeclaration {
function isTypeParameterTypeConstructorDeclaration(type: Type): type is TypeConstructorPolymophsimDeclaration {
return !!(type.flags & TypeFlags.TypeParameter && type.flags & TypeFlags.TypeConstructorDeclaration);
}

function isTypeParameterTypeConstructorInstance(type: Type): type is TypeConstructorInstance {
function isTypeParameterTypeConstructorInstance(type: Type): type is TypeConstructorPolymophsimInstance {
return !!(type.flags & TypeFlags.TypeParameter && type.flags & TypeFlags.TypeConstructorInstance);
}

Expand Down Expand Up @@ -15261,7 +15208,15 @@ namespace ts {
return origionalTypeConstructorParameter;
}
const newTypeArguments = instantiateTypes(resolvedTypeConstructorParam, mapper);
return createNormalizedTypeReference((<TypeReference>concentrateGenericType).target, newTypeArguments);
// concentrate type constructor is TypeAlias
if (!!concentrateGenericType.aliasSymbol) {
const tmpSymbol: Symbol = (<any>concentrateGenericType).origionalTypeAliasSymbol;
return getTypeAliasInstantiation(tmpSymbol, newTypeArguments);
}
// concentrate type constructor is Object of Interface/Class
else {
return createNormalizedTypeReference((<TypeReference>concentrateGenericType).target, newTypeArguments);
}
}
else if (flags & TypeFlags.TypeConstructorDeclaration) {
// this is a demo implement, and not well considered.
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5340,17 +5340,17 @@ namespace ts {
}

// Type parameters (TypeFlags.TypeParameter | TypeFlags.TypeConstructorDeclaration)
export interface TypeConstructorDeclaration extends TypeParameter{
export interface TypeConstructorPolymophsimDeclaration extends TypeParameter{
ShuiRuTian marked this conversation as resolved.
Show resolved Hide resolved
/* @internal */
tParams?: number; // Not allowed constraint for now, this might be a very complex feature.
}

// Type parameters (TypeFlags.TypeParameter | TypeFlags.TypeConstructorInstance)
export interface TypeConstructorInstance extends TypeParameter{
export interface TypeConstructorPolymophsimInstance extends TypeParameter{
/* @internal */
resolvedTypeConstructorParam?: Type[];
/* @internal */
origionalTypeConstructorDeclaration?: TypeConstructorDeclaration;
origionalTypeConstructorDeclaration?: TypeConstructorPolymophsimDeclaration;
}

// Indexed access types (TypeFlags.IndexedAccess)
Expand Down