Don't give most type attributes to the any typesIf the intersection of two object types is built, allattributes that aren't present in both types areinteresected with the "any" type. If there are namesattached to "any", that leads to stupid naming results.Now we only give the provenance attribute to "any".

This commit is contained in:
Mark Probst 2018-07-27 20:28:42 +02:00
Родитель c87a58adcf
Коммит a89e20798b
3 изменённых файлов: 28 добавлений и 2 удалений

Просмотреть файл

@ -922,6 +922,10 @@ class TransformationTypeAttributeKind extends TypeAttributeKind<Transformation>
super("transformation");
}
appliesToTypeKind(_kind: TypeKind): boolean {
return true;
}
get inIdentity(): boolean {
return true;
}

Просмотреть файл

@ -2,12 +2,16 @@ import stringHash = require("string-hash");
import { mapFilterMap, mapFilter, mapTranspose, mapMap } from "collection-utils";
import { panic, assert } from "./support/Support";
import { Type } from "./Type";
import { Type, TypeKind } from "./Type";
import { BaseGraphRewriteBuilder } from "./GraphRewriting";
export class TypeAttributeKind<T> {
constructor(readonly name: string) {}
appliesToTypeKind(kind: TypeKind): boolean {
return kind !== "any";
}
combine(_attrs: T[]): T {
return panic(`Cannot combine type attribute ${this.name}`);
}

Просмотреть файл

@ -35,7 +35,8 @@ import {
TypeIdentity,
TransformedStringTypeKind,
isPrimitiveStringTypeKind,
transformedStringTypeKinds
transformedStringTypeKinds,
TypeKind
} from "./Type";
import { TypeGraph, TypeRef, makeTypeRef, derefTypeRef, typeRefIndex, assertTypeRefGraph } from "./TypeGraph";
import { TypeAttributes, combineTypeAttributes, TypeAttributeKind, emptyTypeAttributes } from "./TypeAttributes";
@ -49,6 +50,10 @@ class ProvenanceTypeAttributeKind extends TypeAttributeKind<Set<number>> {
super("provenance");
}
appliesToTypeKind(_kind: TypeKind): boolean {
return true;
}
combine(arr: Set<number>[]): Set<number> {
return setUnionManyInto(new Set(), arr);
}
@ -144,6 +149,14 @@ export class TypeBuilder {
trefs.forEach(tref => this.assertTypeRefGraph(tref));
}
private filterTypeAttributes(t: Type, attributes: TypeAttributes): TypeAttributes {
const filtered = mapFilter(attributes, (_, k) => k.appliesToTypeKind(t.kind));
if (attributes.size !== filtered.size) {
this.setLostTypeAttributes();
}
return filtered;
}
private commitType(tref: TypeRef, t: Type): void {
this.assertTypeRefGraph(tref);
const index = typeRefIndex(tref);
@ -151,6 +164,7 @@ export class TypeBuilder {
// console.log(`committing ${t.kind}${name} to ${index}`);
assert(this.types[index] === undefined, "A type index was committed twice");
this.types[index] = t;
this.typeAttributes[index] = this.filterTypeAttributes(t, this.typeAttributes[index]);
}
protected addType<T extends Type>(
@ -199,6 +213,10 @@ export class TypeBuilder {
}),
"Can't add different identity type attributes to an existing type"
);
const maybeType = this.types[index];
if (maybeType !== undefined) {
attributes = this.filterTypeAttributes(maybeType, attributes);
}
const nonIdentityAttributes = mapFilter(attributes, (_, k) => !k.inIdentity);
this.typeAttributes[index] = combineTypeAttributes("union", existingAttributes, nonIdentityAttributes);
}